diff --git a/04.word2vec/README.md b/04.word2vec/README.md index 352d3adf42de486d10afb389c5b4cda9f4e74977..2813d61c32948632dc937373cf4466f47984a9b4 100644 --- a/04.word2vec/README.md +++ b/04.word2vec/README.md @@ -234,25 +234,25 @@ Unlike the previous PaddlePaddle v2 version, in the new Fluid version, we don't ```python def inference_program(words, is_sparse): - embed_first = fluid.layers.embedding( + embed_first = fluid.embedding( input=words[0], size=[dict_size, EMBED_SIZE], dtype='float32', is_sparse=is_sparse, param_attr='shared_w') - embed_second = fluid.layers.embedding( + embed_second = fluid.embedding( input=words[1], size=[dict_size, EMBED_SIZE], dtype='float32', is_sparse=is_sparse, param_attr='shared_w') - embed_third = fluid.layers.embedding( + embed_third = fluid.embedding( input=words[2], size=[dict_size, EMBED_SIZE], dtype='float32', is_sparse=is_sparse, param_attr='shared_w') - embed_fourth = fluid.layers.embedding( + embed_fourth = fluid.embedding( input=words[3], size=[dict_size, EMBED_SIZE], dtype='float32', @@ -300,11 +300,11 @@ def train(if_use_cuda, params_dirname, is_sparse=True): test_reader = paddle.batch( paddle.dataset.imikolov.test(word_dict, N), BATCH_SIZE) - first_word = fluid.layers.data(name='firstw', shape=[1], dtype='int64') - second_word = fluid.layers.data(name='secondw', shape=[1], dtype='int64') - third_word = fluid.layers.data(name='thirdw', shape=[1], dtype='int64') - forth_word = fluid.layers.data(name='fourthw', shape=[1], dtype='int64') - next_word = fluid.layers.data(name='nextw', shape=[1], dtype='int64') + first_word = fluid.data(name='firstw', shape=[None, 1], dtype='int64') + second_word = fluid.data(name='secondw', shape=[None, 1], dtype='int64') + third_word = fluid.data(name='thirdw', shape=[None, 1], dtype='int64') + forth_word = fluid.data(name='fourthw', shape=[None, 1], dtype='int64') + next_word = fluid.data(name='nextw', shape=[None, 1], dtype='int64') word_list = [first_word, second_word, third_word, forth_word, next_word] feed_order = ['firstw', 'secondw', 'thirdw', 'fourthw', 'nextw'] diff --git a/04.word2vec/index.html b/04.word2vec/index.html index c97cb748e3757045bc38158f607c5ad06671aee3..9831c3a5dbe539775f143684e9c8de3fcb150947 100644 --- a/04.word2vec/index.html +++ b/04.word2vec/index.html @@ -276,25 +276,25 @@ Unlike the previous PaddlePaddle v2 version, in the new Fluid version, we don't ```python def inference_program(words, is_sparse): - embed_first = fluid.layers.embedding( + embed_first = fluid.embedding( input=words[0], size=[dict_size, EMBED_SIZE], dtype='float32', is_sparse=is_sparse, param_attr='shared_w') - embed_second = fluid.layers.embedding( + embed_second = fluid.embedding( input=words[1], size=[dict_size, EMBED_SIZE], dtype='float32', is_sparse=is_sparse, param_attr='shared_w') - embed_third = fluid.layers.embedding( + embed_third = fluid.embedding( input=words[2], size=[dict_size, EMBED_SIZE], dtype='float32', is_sparse=is_sparse, param_attr='shared_w') - embed_fourth = fluid.layers.embedding( + embed_fourth = fluid.embedding( input=words[3], size=[dict_size, EMBED_SIZE], dtype='float32', @@ -342,11 +342,11 @@ def train(if_use_cuda, params_dirname, is_sparse=True): test_reader = paddle.batch( paddle.dataset.imikolov.test(word_dict, N), BATCH_SIZE) - first_word = fluid.layers.data(name='firstw', shape=[1], dtype='int64') - second_word = fluid.layers.data(name='secondw', shape=[1], dtype='int64') - third_word = fluid.layers.data(name='thirdw', shape=[1], dtype='int64') - forth_word = fluid.layers.data(name='fourthw', shape=[1], dtype='int64') - next_word = fluid.layers.data(name='nextw', shape=[1], dtype='int64') + first_word = fluid.data(name='firstw', shape=[None, 1], dtype='int64') + second_word = fluid.data(name='secondw', shape=[None, 1], dtype='int64') + third_word = fluid.data(name='thirdw', shape=[None, 1], dtype='int64') + forth_word = fluid.data(name='fourthw', shape=[None, 1], dtype='int64') + next_word = fluid.data(name='nextw', shape=[None, 1], dtype='int64') word_list = [first_word, second_word, third_word, forth_word, next_word] feed_order = ['firstw', 'secondw', 'thirdw', 'fourthw', 'nextw'] diff --git a/04.word2vec/train.py b/04.word2vec/train.py index 2b3a97276d8fbd35b78ec480f2d1ea4496e0f62a..63fa8b377adf4c26fe25920cce40d035cc58026c 100644 --- a/04.word2vec/train.py +++ b/04.word2vec/train.py @@ -45,25 +45,25 @@ def parse_args(): def inference_program(words, is_sparse): - embed_first = fluid.layers.embedding( + embed_first = fluid.embedding( input=words[0], size=[dict_size, EMBED_SIZE], dtype='float32', is_sparse=is_sparse, param_attr='shared_w') - embed_second = fluid.layers.embedding( + embed_second = fluid.embedding( input=words[1], size=[dict_size, EMBED_SIZE], dtype='float32', is_sparse=is_sparse, param_attr='shared_w') - embed_third = fluid.layers.embedding( + embed_third = fluid.embedding( input=words[2], size=[dict_size, EMBED_SIZE], dtype='float32', is_sparse=is_sparse, param_attr='shared_w') - embed_fourth = fluid.layers.embedding( + embed_fourth = fluid.embedding( input=words[3], size=[dict_size, EMBED_SIZE], dtype='float32', @@ -82,7 +82,7 @@ def train_program(predict_word): # The declaration of 'next_word' must be after the invoking of inference_program, # or the data input order of train program would be [next_word, firstw, secondw, # thirdw, fourthw], which is not correct. - next_word = fluid.layers.data(name='nextw', shape=[1], dtype='int64') + next_word = fluid.data(name='nextw', shape=[None, 1], dtype='int64') cost = fluid.layers.cross_entropy(input=predict_word, label=next_word) avg_cost = fluid.layers.mean(cost) return avg_cost @@ -102,11 +102,11 @@ def train(if_use_cuda, params_dirname, is_sparse=True): test_reader = paddle.batch( paddle.dataset.imikolov.test(word_dict, N), BATCH_SIZE) - first_word = fluid.layers.data(name='firstw', shape=[1], dtype='int64') - second_word = fluid.layers.data(name='secondw', shape=[1], dtype='int64') - third_word = fluid.layers.data(name='thirdw', shape=[1], dtype='int64') - forth_word = fluid.layers.data(name='fourthw', shape=[1], dtype='int64') - next_word = fluid.layers.data(name='nextw', shape=[1], dtype='int64') + first_word = fluid.data(name='firstw', shape=[None, 1], dtype='int64') + second_word = fluid.data(name='secondw', shape=[None, 1], dtype='int64') + third_word = fluid.data(name='thirdw', shape=[None, 1], dtype='int64') + forth_word = fluid.data(name='fourthw', shape=[None, 1], dtype='int64') + next_word = fluid.data(name='nextw', shape=[None, 1], dtype='int64') word_list = [first_word, second_word, third_word, forth_word, next_word] feed_order = ['firstw', 'secondw', 'thirdw', 'fourthw', 'nextw']