From e242e6f143db2f0f9cd0e8c5803306341a6104dd Mon Sep 17 00:00:00 2001 From: Li Fuchen Date: Wed, 20 May 2020 14:39:47 +0800 Subject: [PATCH] fix an infer bug of understand_sentiment (#2164) * fix a infer bug of understand_sentiment. --- .../user_guides/nlp_case/understand_sentiment/README.cn.md | 3 ++- .../user_guides/nlp_case/understand_sentiment/README.md | 3 ++- .../user_guides/nlp_case/understand_sentiment/index.cn.html | 3 ++- .../user_guides/nlp_case/understand_sentiment/index.html | 3 ++- .../user_guides/nlp_case/understand_sentiment/train_conv.py | 5 +++-- .../nlp_case/understand_sentiment/train_dyn_rnn.py | 5 +++-- .../nlp_case/understand_sentiment/train_stacked_lstm.py | 5 +++-- 7 files changed, 17 insertions(+), 10 deletions(-) diff --git a/doc/fluid/user_guides/nlp_case/understand_sentiment/README.cn.md b/doc/fluid/user_guides/nlp_case/understand_sentiment/README.cn.md index ce9cd776d..199e18ed8 100644 --- a/doc/fluid/user_guides/nlp_case/understand_sentiment/README.cn.md +++ b/doc/fluid/user_guides/nlp_case/understand_sentiment/README.cn.md @@ -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) ``` diff --git a/doc/fluid/user_guides/nlp_case/understand_sentiment/README.md b/doc/fluid/user_guides/nlp_case/understand_sentiment/README.md index 5e18077ce..00ed9efb7 100644 --- a/doc/fluid/user_guides/nlp_case/understand_sentiment/README.md +++ b/doc/fluid/user_guides/nlp_case/understand_sentiment/README.md @@ -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) ``` diff --git a/doc/fluid/user_guides/nlp_case/understand_sentiment/index.cn.html b/doc/fluid/user_guides/nlp_case/understand_sentiment/index.cn.html index 4af229074..a1d945d35 100644 --- a/doc/fluid/user_guides/nlp_case/understand_sentiment/index.cn.html +++ b/doc/fluid/user_guides/nlp_case/understand_sentiment/index.cn.html @@ -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) ``` diff --git a/doc/fluid/user_guides/nlp_case/understand_sentiment/index.html b/doc/fluid/user_guides/nlp_case/understand_sentiment/index.html index 45604f13c..ecd861f30 100644 --- a/doc/fluid/user_guides/nlp_case/understand_sentiment/index.html +++ b/doc/fluid/user_guides/nlp_case/understand_sentiment/index.html @@ -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) ``` diff --git a/doc/fluid/user_guides/nlp_case/understand_sentiment/train_conv.py b/doc/fluid/user_guides/nlp_case/understand_sentiment/train_conv.py index 745474615..456b127b9 100644 --- a/doc/fluid/user_guides/nlp_case/understand_sentiment/train_conv.py +++ b/doc/fluid/user_guides/nlp_case/understand_sentiment/train_conv.py @@ -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" diff --git a/doc/fluid/user_guides/nlp_case/understand_sentiment/train_dyn_rnn.py b/doc/fluid/user_guides/nlp_case/understand_sentiment/train_dyn_rnn.py index 78f3d64b4..b782f6435 100644 --- a/doc/fluid/user_guides/nlp_case/understand_sentiment/train_dyn_rnn.py +++ b/doc/fluid/user_guides/nlp_case/understand_sentiment/train_dyn_rnn.py @@ -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" diff --git a/doc/fluid/user_guides/nlp_case/understand_sentiment/train_stacked_lstm.py b/doc/fluid/user_guides/nlp_case/understand_sentiment/train_stacked_lstm.py index 5878c7f73..6db40f42a 100644 --- a/doc/fluid/user_guides/nlp_case/understand_sentiment/train_stacked_lstm.py +++ b/doc/fluid/user_guides/nlp_case/understand_sentiment/train_stacked_lstm.py @@ -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" -- GitLab