From c27a0a2e334c89672ae0ca9ad4e14c5fb0c472c8 Mon Sep 17 00:00:00 2001 From: Yibing Liu Date: Sat, 16 May 2020 01:11:57 +0800 Subject: [PATCH] Upgrade APIs for word2vec & label_semantic_roles (#2115) * Upgrade APIs for word2vec & label_semantic_roles * Some more fixes --- .../nlp_case/label_semantic_roles/README.md | 4 ++-- .../user_guides/nlp_case/label_semantic_roles/train.py | 10 +++++----- doc/fluid/user_guides/simple_case/word2vec/README.md | 6 +++--- doc/fluid/user_guides/simple_case/word2vec/train.py | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/doc/fluid/user_guides/nlp_case/label_semantic_roles/README.md b/doc/fluid/user_guides/nlp_case/label_semantic_roles/README.md index 3801b0df8..00c5f627f 100644 --- a/doc/fluid/user_guides/nlp_case/label_semantic_roles/README.md +++ b/doc/fluid/user_guides/nlp_case/label_semantic_roles/README.md @@ -388,8 +388,8 @@ The data introduction section mentions the payment of the CoNLL 2005 training se crf_decode = fluid.layers.crf_decoding( input=feature_out, param_attr=fluid.ParamAttr(name='crfw')) -train_data = paddle.batch( - paddle.reader.shuffle( +train_data = fluid.io.batch( + fluid.io.shuffle( paddle.dataset.conll05.test(), buf_size=8192), batch_size=BATCH_SIZE) diff --git a/doc/fluid/user_guides/nlp_case/label_semantic_roles/train.py b/doc/fluid/user_guides/nlp_case/label_semantic_roles/train.py index 70d05946e..5ce21ffe0 100644 --- a/doc/fluid/user_guides/nlp_case/label_semantic_roles/train.py +++ b/doc/fluid/user_guides/nlp_case/label_semantic_roles/train.py @@ -143,8 +143,8 @@ def train(use_cuda, save_dirname=None, is_local=True): # define network topology feature_out = db_lstm(**locals()) - target = fluid.layers.data( - name='target', shape=[1], dtype='int64', lod_level=1) + target = fluid.data( + name='target', shape=[None, 1], dtype='int64', lod_level=1) crf_cost = fluid.layers.linear_chain_crf( input=feature_out, label=target, @@ -165,11 +165,11 @@ def train(use_cuda, save_dirname=None, is_local=True): input=feature_out, param_attr=fluid.ParamAttr(name='crfw')) if args.enable_ce: - train_data = paddle.batch( + train_data = fluid.io.batch( paddle.dataset.conll05.test(), batch_size=BATCH_SIZE) else: - train_data = paddle.batch( - paddle.reader.shuffle( + train_data = fluid.io.batch( + fluid.io.shuffle( paddle.dataset.conll05.test(), buf_size=8192), batch_size=BATCH_SIZE) diff --git a/doc/fluid/user_guides/simple_case/word2vec/README.md b/doc/fluid/user_guides/simple_case/word2vec/README.md index 8d7acaea3..6393aec48 100644 --- a/doc/fluid/user_guides/simple_case/word2vec/README.md +++ b/doc/fluid/user_guides/simple_case/word2vec/README.md @@ -289,15 +289,15 @@ def optimizer_func(): - Now we can start training. This version is much simpler than before. We have ready-made training and test sets: `paddle.dataset.imikolov.train()` and `paddle.dataset.imikolov.test()`. Both will return a reader. In PaddlePaddle, the reader is a Python function that reads the next piece of data when called each time . It is a Python generator. -`paddle.batch` will read in a reader and output a batched reader. We can also output the training of each step and batch during the training process. +`fluid.io.batch` will read in a reader and output a batched reader. We can also output the training of each step and batch during the training process. ```python def train(if_use_cuda, params_dirname, is_sparse=True): place = fluid.CUDAPlace(0) if if_use_cuda else fluid.CPUPlace() - train_reader = paddle.batch( + train_reader = fluid.io.batch( paddle.dataset.imikolov.train(word_dict, N), BATCH_SIZE) - test_reader = paddle.batch( + test_reader = fluid.io.batch( paddle.dataset.imikolov.test(word_dict, N), BATCH_SIZE) first_word = fluid.data(name='firstw', shape=[None, 1], dtype='int64') diff --git a/doc/fluid/user_guides/simple_case/word2vec/train.py b/doc/fluid/user_guides/simple_case/word2vec/train.py index d3c9a985c..beed63eb7 100644 --- a/doc/fluid/user_guides/simple_case/word2vec/train.py +++ b/doc/fluid/user_guides/simple_case/word2vec/train.py @@ -98,9 +98,9 @@ def optimizer_func(): def train(if_use_cuda, params_dirname, is_sparse=True): place = fluid.CUDAPlace(0) if if_use_cuda else fluid.CPUPlace() - train_reader = paddle.batch( + train_reader = fluid.io.batch( paddle.dataset.imikolov.train(word_dict, N), BATCH_SIZE) - test_reader = paddle.batch( + test_reader = fluid.io.batch( paddle.dataset.imikolov.test(word_dict, N), BATCH_SIZE) first_word = fluid.data(name='firstw', shape=[None, 1], dtype='int64') -- GitLab