未验证 提交 e242e6f1 编写于 作者: L Li Fuchen 提交者: GitHub

fix an infer bug of understand_sentiment (#2164)

* fix a infer bug of understand_sentiment.
上级 c245fed2
......@@ -394,7 +394,7 @@ inference_scope = fluid.core.Scope()
```python
reviews_str = [
'read the book forget the movie', 'this is a great movie', 'this is very bad'
b'read the book forget the movie', b'this is a great movie', b'this is very bad'
]
reviews = [c.split() for c in reviews_str]
......@@ -404,6 +404,7 @@ for c in reviews:
lod.append([word_dict.get(words, UNK) for words in c])
base_shape = [[len(c) for c in lod]]
lod = np.array(sum(lod, []), dtype=np.int64)
tensor_words = fluid.create_lod_tensor(lod, base_shape, place)
```
......
......@@ -383,7 +383,7 @@ Then we use `create_lod_tensor` to create the tensor of the detail level. For a
```python
reviews_str = [
'read the book forget the movie', 'this is a great movie', 'this is very bad'
b'read the book forget the movie', b'this is a great movie', b'this is very bad'
]
reviews = [c.split() for c in reviews_str]
......@@ -393,6 +393,7 @@ for c in reviews:
lod.append([word_dict.get(words, UNK) for words in c])
base_shape = [[len(c) for c in lod]]
lod = np.array(sum(lod, []), dtype=np.int64)
tensor_words = fluid.create_lod_tensor(lod, base_shape, place)
```
......
......@@ -436,7 +436,7 @@ inference_scope = fluid.core.Scope()
```python
reviews_str = [
'read the book forget the movie', 'this is a great movie', 'this is very bad'
b'read the book forget the movie', b'this is a great movie', b'this is very bad'
]
reviews = [c.split() for c in reviews_str]
......@@ -446,6 +446,7 @@ for c in reviews:
lod.append([word_dict.get(words, UNK) for words in c])
base_shape = [[len(c) for c in lod]]
lod = np.array(sum(lod, []), dtype=np.int64)
tensor_words = fluid.create_lod_tensor(lod, base_shape, place)
```
......
......@@ -425,7 +425,7 @@ Then we use `create_lod_tensor` to create the tensor of the detail level. For a
```python
reviews_str = [
'read the book forget the movie', 'this is a great movie', 'this is very bad'
b'read the book forget the movie', b'this is a great movie', b'this is very bad'
]
reviews = [c.split() for c in reviews_str]
......@@ -435,6 +435,7 @@ for c in reviews:
lod.append([word_dict.get(words, UNK) for words in c])
base_shape = [[len(c) for c in lod]]
lod = np.array(sum(lod, []), dtype=np.int64)
tensor_words = fluid.create_lod_tensor(lod, base_shape, place)
```
......
......@@ -205,8 +205,8 @@ def infer(use_cuda, params_dirname=None):
# length 3, 4 and 2, respectively.
# Note that lod info should be a list of lists.
reviews_str = [
'read the book forget the movie', 'this is a great movie',
'this is very bad'
b'read the book forget the movie', b'this is a great movie',
b'this is very bad'
]
reviews = [c.split() for c in reviews_str]
......@@ -216,6 +216,7 @@ def infer(use_cuda, params_dirname=None):
lod.append([np.int64(word_dict.get(words, UNK)) for words in c])
base_shape = [[len(c) for c in lod]]
lod = np.array(sum(lod, []), dtype=np.int64)
tensor_words = fluid.create_lod_tensor(lod, base_shape, place)
assert feed_target_names[0] == "words"
......
......@@ -194,8 +194,8 @@ def infer(use_cuda, params_dirname=None):
# length 3, 4 and 2, respectively.
# Note that lod info should be a list of lists.
reviews_str = [
'read the book forget the movie', 'this is a great movie',
'this is very bad'
b'read the book forget the movie', b'this is a great movie',
b'this is very bad'
]
reviews = [c.split() for c in reviews_str]
......@@ -205,6 +205,7 @@ def infer(use_cuda, params_dirname=None):
lod.append([np.int64(word_dict.get(words, UNK)) for words in c])
base_shape = [[len(c) for c in lod]]
lod = np.array(sum(lod, []), dtype=np.int64)
tensor_words = fluid.create_lod_tensor(lod, base_shape, place)
assert feed_target_names[0] == "words"
......
......@@ -216,8 +216,8 @@ def infer(use_cuda, params_dirname=None):
# length 3, 4 and 2, respectively.
# Note that lod info should be a list of lists.
reviews_str = [
'read the book forget the movie', 'this is a great movie',
'this is very bad'
b'read the book forget the movie', b'this is a great movie',
b'this is very bad'
]
reviews = [c.split() for c in reviews_str]
......@@ -227,6 +227,7 @@ def infer(use_cuda, params_dirname=None):
lod.append([np.int64(word_dict.get(words, UNK)) for words in c])
base_shape = [[len(c) for c in lod]]
lod = np.array(sum(lod, []), dtype=np.int64)
tensor_words = fluid.create_lod_tensor(lod, base_shape, place)
assert feed_target_names[0] == "words"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册