We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
text_classification reader error
Get follow error log while running  `train.py`  of text_classification model:
```
[INFO 2017-11-16 17:19:51,458 train.py:44] please wait to build the word dictionary ...
[INFO 2017-11-16 17:20:07,138 train.py:101] length of word dictionary is : 5147.
I1116 17:20:07.168130 24638 Util.cpp:166] commandline:  --use_gpu=False --trainer_count=1
I1116 17:20:07.176143 24638 GradientMachine.cpp:94] Initing parameters..
I1116 17:20:07.186369 24638 GradientMachine.cpp:101] Init parameters done.
Traceback (most recent call last):
  File "train.py", line 178, in <module>
    main(args)
  File "train.py", line 169, in main
    model_save_dir=args.model_save_dir)
  File "train.py", line 150, in train
    num_passes=num_passes)
  File "/home/work/wanghaoshuang/paddle/python/install/lib/python2.7/site-packages/paddle/v2/trainer.py", line 162, in train
    for batch_id, data_batch in enumerate(reader()):
  File "/home/work/wanghaoshuang/paddle/python/install/lib/python2.7/site-packages/paddle/v2/minibatch.py", line 33, in batch_reader
    for instance in r:
  File "/home/work/wanghaoshuang/paddle/python/install/lib/python2.7/site-packages/paddle/v2/reader/decorator.py", line 67, in data_reader
    for e in reader():
TypeError: 'function' object is not iterable
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `text_classification/train.py`
Content:
```
1 import os
2 import sys
3 import gzip
4 
5 import paddle.v2 as paddle
6 
7 import reader
8 from utils import logger, parse_train_cmd, build_dict, load_dict
9 from network_conf import fc_net, convolution_net
10 
11 
12 def train(topology,
13           train_data_dir=None,
14           test_data_dir=None,
15           word_dict_path=None,
16           label_dict_path=None,
17           model_save_dir="models",
18           batch_size=32,
19           num_passes=10):
20     """
21     train dnn model
22 
23 
24     :params train_data_path: path of training data, if this parameter
25         is not specified, paddle.dataset.imdb will be used to run this example
26     :type train_data_path: str
27     :params test_data_path: path of testing data, if this parameter
28         is not specified, paddle.dataset.imdb will be used to run this example
29     :type test_data_path: str
30     :params word_dict_path: path of training data, if this parameter
31         is not specified, paddle.dataset.imdb will be used to run this example
32     :type word_dict_path: str
33     :params num_pass: train pass number
34     :type num_pass: int
35     """
36     if not os.path.exists(model_save_dir):
37         os.mkdir(model_save_dir)
38 
39     use_default_data = (train_data_dir is None)
40 
41     if use_default_data:
42         logger.info(("No training data are porivided, "
43                      "use paddle.dataset.imdb to train the model."))
44         logger.info("please wait to build the word dictionary ...")
45 
46         word_dict = paddle.dataset.imdb.word_dict()
47         train_reader = paddle.batch(
48             paddle.reader.shuffle(
49                 lambda: paddle.dataset.imdb.train(word_dict), buf_size=1000),
50             batch_size=100)
51         test_reader = paddle.batch(
52             lambda: paddle.dataset.imdb.test(word_dict), batch_size=100)
53 
54         class_num = 2
55     else:
56         if word_dict_path is None or not os.path.exists(word_dict_path):
57             logger.info(("word dictionary is not given, the dictionary "
58                          "is automatically built from the training data."))
59 
60             # build the word dictionary to map the original string-typed
61             # words into integer-typed index
62             build_dict(
63                 data_dir=train_data_dir,
64                 save_path=word_dict_path,
65                 use_col=1,
66                 cutoff_fre=5,
67                 insert_extra_words=["<UNK>"])
68 
69         if not os.path.exists(label_dict_path):
70             logger.info(("label dictionary is not given, the dictionary "
71                          "is automatically built from the training data."))
72             # build the label dictionary to map the original string-typed
73             # label into integer-typed index
74             build_dict(
75                 data_dir=train_data_dir, save_path=label_dict_path, use_col=0)
76 
77         word_dict = load_dict(word_dict_path)
78 
79         lbl_dict = load_dict(label_dict_path)
80         class_num = len(lbl_dict)
81         logger.info("class number is : %d." % (len(lbl_dict)))
82 
83         train_reader = paddle.batch(
84             paddle.reader.shuffle(
85                 reader.train_reader(train_data_dir, word_dict, lbl_dict),
86                 buf_size=1000),
87             batch_size=batch_size)
88 
89         if test_data_dir is not None:
90             # here, because training and testing data share a same format,
91             # we still use the reader.train_reader to read the testing data.
92             test_reader = paddle.batch(
93                 paddle.reader.shuffle(
94                     reader.train_reader(test_data_dir, word_dict, lbl_dict),
95                     buf_size=1000),
96                 batch_size=batch_size)
97         else:
98             test_reader = None
99 
100     dict_dim = len(word_dict)
101     logger.info("length of word dictionary is : %d." % (dict_dim))
102 
103     paddle.init(use_gpu=False, trainer_count=1)
104 
105     # network config
106     cost, prob, label = topology(dict_dim, class_num)
107 
108     # create parameters
109     parameters = paddle.parameters.create(cost)
110 
111     # create optimizer
112     adam_optimizer = paddle.optimizer.Adam(
113         learning_rate=1e-3,
114         regularization=paddle.optimizer.L2Regularization(rate=1e-3),
115         model_average=paddle.optimizer.ModelAverage(average_window=0.5))
116 
117     # create trainer
118     trainer = paddle.trainer.SGD(
119         cost=cost,
120         extra_layers=paddle.evaluator.auc(input=prob, label=label),
121         parameters=parameters,
122         update_equation=adam_optimizer)
123 
124     # begin training network
125     feeding = {"word": 0, "label": 1}
126 
127     def _event_handler(event):
128         """
129         Define end batch and end pass event handler
130         """
131         if isinstance(event, paddle.event.EndIteration):
132             if event.batch_id % 100 == 0:
133                 logger.info("Pass %d, Batch %d, Cost %f, %s\n" % (
134                     event.pass_id, event.batch_id, event.cost, event.metrics))
135 
136         if isinstance(event, paddle.event.EndPass):
137             if test_reader is not None:
138                 result = trainer.test(reader=test_reader, feeding=feeding)
139                 logger.info("Test at Pass %d, %s \n" % (event.pass_id,
140                                                         result.metrics))
141             with gzip.open(
142                     os.path.join(model_save_dir, "dnn_params_pass_%05d.tar.gz" %
143                                  event.pass_id), "w") as f:
144                 trainer.save_parameter_to_tar(f)
145 
146     trainer.train(
147         reader=train_reader,
148         event_handler=_event_handler,
149         feeding=feeding,
150         num_passes=num_passes)
151 
152     logger.info("Training has finished.")
153 
154 
155 def main(args):
156     if args.nn_type == "dnn":
157         topology = fc_net
158     elif args.nn_type == "cnn":
159         topology = convolution_net
160 
161     train(
162         topology=topology,
163         train_data_dir=args.train_data_dir,
164         test_data_dir=args.test_data_dir,
165         word_dict_path=args.word_dict,
166         label_dict_path=args.label_dict,
167         batch_size=args.batch_size,
168         num_passes=args.num_passes,
169         model_save_dir=args.model_save_dir)
170 
171 
172 if __name__ == "__main__":
173     args = parse_train_cmd()
174     if args.train_data_dir is not None:
175         assert args.word_dict and args.label_dict, (
176             "the parameter train_data_dir, word_dict_path, and label_dict_path "
177             "should be set at the same time.")
178     main(args)
179
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/text_classification/train.py b/text_classification/train.py
--- a/text_classification/train.py
+++ b/text_classification/train.py
@@ -46,10 +46,10 @@
         word_dict = paddle.dataset.imdb.word_dict()
         train_reader = paddle.batch(
             paddle.reader.shuffle(
-                lambda: paddle.dataset.imdb.train(word_dict), buf_size=1000),
+                lambda: paddle.dataset.imdb.train(word_dict)(), buf_size=1000),
             batch_size=100)
         test_reader = paddle.batch(
-            lambda: paddle.dataset.imdb.test(word_dict), batch_size=100)
+            lambda: paddle.dataset.imdb.test(word_dict)(), batch_size=100)
 
         class_num = 2
     else:

{"golden_diff": "diff --git a/text_classification/train.py b/text_classification/train.py\n--- a/text_classification/train.py\n+++ b/text_classification/train.py\n@@ -46,10 +46,10 @@\n         word_dict = paddle.dataset.imdb.word_dict()\n         train_reader = paddle.batch(\n             paddle.reader.shuffle(\n-                lambda: paddle.dataset.imdb.train(word_dict), buf_size=1000),\n+                lambda: paddle.dataset.imdb.train(word_dict)(), buf_size=1000),\n             batch_size=100)\n         test_reader = paddle.batch(\n-            lambda: paddle.dataset.imdb.test(word_dict), batch_size=100)\n+            lambda: paddle.dataset.imdb.test(word_dict)(), batch_size=100)\n \n         class_num = 2\n     else:\n", "issue": "text_classification reader error\nGet follow error log while running  `train.py`  of text_classification model:\r\n```\r\n[INFO 2017-11-16 17:19:51,458 train.py:44] please wait to build the word dictionary ...\r\n[INFO 2017-11-16 17:20:07,138 train.py:101] length of word dictionary is : 5147.\r\nI1116 17:20:07.168130 24638 Util.cpp:166] commandline:  --use_gpu=False --trainer_count=1\r\nI1116 17:20:07.176143 24638 GradientMachine.cpp:94] Initing parameters..\r\nI1116 17:20:07.186369 24638 GradientMachine.cpp:101] Init parameters done.\r\nTraceback (most recent call last):\r\n  File \"train.py\", line 178, in <module>\r\n    main(args)\r\n  File \"train.py\", line 169, in main\r\n    model_save_dir=args.model_save_dir)\r\n  File \"train.py\", line 150, in train\r\n    num_passes=num_passes)\r\n  File \"/home/work/wanghaoshuang/paddle/python/install/lib/python2.7/site-packages/paddle/v2/trainer.py\", line 162, in train\r\n    for batch_id, data_batch in enumerate(reader()):\r\n  File \"/home/work/wanghaoshuang/paddle/python/install/lib/python2.7/site-packages/paddle/v2/minibatch.py\", line 33, in batch_reader\r\n    for instance in r:\r\n  File \"/home/work/wanghaoshuang/paddle/python/install/lib/python2.7/site-packages/paddle/v2/reader/decorator.py\", line 67, in data_reader\r\n    for e in reader():\r\nTypeError: 'function' object is not iterable\r\n```\n", "before_files": [{"content": "import os\nimport sys\nimport gzip\n\nimport paddle.v2 as paddle\n\nimport reader\nfrom utils import logger, parse_train_cmd, build_dict, load_dict\nfrom network_conf import fc_net, convolution_net\n\n\ndef train(topology,\n          train_data_dir=None,\n          test_data_dir=None,\n          word_dict_path=None,\n          label_dict_path=None,\n          model_save_dir=\"models\",\n          batch_size=32,\n          num_passes=10):\n    \"\"\"\n    train dnn model\n\n\n    :params train_data_path: path of training data, if this parameter\n        is not specified, paddle.dataset.imdb will be used to run this example\n    :type train_data_path: str\n    :params test_data_path: path of testing data, if this parameter\n        is not specified, paddle.dataset.imdb will be used to run this example\n    :type test_data_path: str\n    :params word_dict_path: path of training data, if this parameter\n        is not specified, paddle.dataset.imdb will be used to run this example\n    :type word_dict_path: str\n    :params num_pass: train pass number\n    :type num_pass: int\n    \"\"\"\n    if not os.path.exists(model_save_dir):\n        os.mkdir(model_save_dir)\n\n    use_default_data = (train_data_dir is None)\n\n    if use_default_data:\n        logger.info((\"No training data are porivided, \"\n                     \"use paddle.dataset.imdb to train the model.\"))\n        logger.info(\"please wait to build the word dictionary ...\")\n\n        word_dict = paddle.dataset.imdb.word_dict()\n        train_reader = paddle.batch(\n            paddle.reader.shuffle(\n                lambda: paddle.dataset.imdb.train(word_dict), buf_size=1000),\n            batch_size=100)\n        test_reader = paddle.batch(\n            lambda: paddle.dataset.imdb.test(word_dict), batch_size=100)\n\n        class_num = 2\n    else:\n        if word_dict_path is None or not os.path.exists(word_dict_path):\n            logger.info((\"word dictionary is not given, the dictionary \"\n                         \"is automatically built from the training data.\"))\n\n            # build the word dictionary to map the original string-typed\n            # words into integer-typed index\n            build_dict(\n                data_dir=train_data_dir,\n                save_path=word_dict_path,\n                use_col=1,\n                cutoff_fre=5,\n                insert_extra_words=[\"<UNK>\"])\n\n        if not os.path.exists(label_dict_path):\n            logger.info((\"label dictionary is not given, the dictionary \"\n                         \"is automatically built from the training data.\"))\n            # build the label dictionary to map the original string-typed\n            # label into integer-typed index\n            build_dict(\n                data_dir=train_data_dir, save_path=label_dict_path, use_col=0)\n\n        word_dict = load_dict(word_dict_path)\n\n        lbl_dict = load_dict(label_dict_path)\n        class_num = len(lbl_dict)\n        logger.info(\"class number is : %d.\" % (len(lbl_dict)))\n\n        train_reader = paddle.batch(\n            paddle.reader.shuffle(\n                reader.train_reader(train_data_dir, word_dict, lbl_dict),\n                buf_size=1000),\n            batch_size=batch_size)\n\n        if test_data_dir is not None:\n            # here, because training and testing data share a same format,\n            # we still use the reader.train_reader to read the testing data.\n            test_reader = paddle.batch(\n                paddle.reader.shuffle(\n                    reader.train_reader(test_data_dir, word_dict, lbl_dict),\n                    buf_size=1000),\n                batch_size=batch_size)\n        else:\n            test_reader = None\n\n    dict_dim = len(word_dict)\n    logger.info(\"length of word dictionary is : %d.\" % (dict_dim))\n\n    paddle.init(use_gpu=False, trainer_count=1)\n\n    # network config\n    cost, prob, label = topology(dict_dim, class_num)\n\n    # create parameters\n    parameters = paddle.parameters.create(cost)\n\n    # create optimizer\n    adam_optimizer = paddle.optimizer.Adam(\n        learning_rate=1e-3,\n        regularization=paddle.optimizer.L2Regularization(rate=1e-3),\n        model_average=paddle.optimizer.ModelAverage(average_window=0.5))\n\n    # create trainer\n    trainer = paddle.trainer.SGD(\n        cost=cost,\n        extra_layers=paddle.evaluator.auc(input=prob, label=label),\n        parameters=parameters,\n        update_equation=adam_optimizer)\n\n    # begin training network\n    feeding = {\"word\": 0, \"label\": 1}\n\n    def _event_handler(event):\n        \"\"\"\n        Define end batch and end pass event handler\n        \"\"\"\n        if isinstance(event, paddle.event.EndIteration):\n            if event.batch_id % 100 == 0:\n                logger.info(\"Pass %d, Batch %d, Cost %f, %s\\n\" % (\n                    event.pass_id, event.batch_id, event.cost, event.metrics))\n\n        if isinstance(event, paddle.event.EndPass):\n            if test_reader is not None:\n                result = trainer.test(reader=test_reader, feeding=feeding)\n                logger.info(\"Test at Pass %d, %s \\n\" % (event.pass_id,\n                                                        result.metrics))\n            with gzip.open(\n                    os.path.join(model_save_dir, \"dnn_params_pass_%05d.tar.gz\" %\n                                 event.pass_id), \"w\") as f:\n                trainer.save_parameter_to_tar(f)\n\n    trainer.train(\n        reader=train_reader,\n        event_handler=_event_handler,\n        feeding=feeding,\n        num_passes=num_passes)\n\n    logger.info(\"Training has finished.\")\n\n\ndef main(args):\n    if args.nn_type == \"dnn\":\n        topology = fc_net\n    elif args.nn_type == \"cnn\":\n        topology = convolution_net\n\n    train(\n        topology=topology,\n        train_data_dir=args.train_data_dir,\n        test_data_dir=args.test_data_dir,\n        word_dict_path=args.word_dict,\n        label_dict_path=args.label_dict,\n        batch_size=args.batch_size,\n        num_passes=args.num_passes,\n        model_save_dir=args.model_save_dir)\n\n\nif __name__ == \"__main__\":\n    args = parse_train_cmd()\n    if args.train_data_dir is not None:\n        assert args.word_dict and args.label_dict, (\n            \"the parameter train_data_dir, word_dict_path, and label_dict_path \"\n            \"should be set at the same time.\")\n    main(args)\n", "path": "text_classification/train.py"}], "after_files": [{"content": "import os\nimport sys\nimport gzip\n\nimport paddle.v2 as paddle\n\nimport reader\nfrom utils import logger, parse_train_cmd, build_dict, load_dict\nfrom network_conf import fc_net, convolution_net\n\n\ndef train(topology,\n          train_data_dir=None,\n          test_data_dir=None,\n          word_dict_path=None,\n          label_dict_path=None,\n          model_save_dir=\"models\",\n          batch_size=32,\n          num_passes=10):\n    \"\"\"\n    train dnn model\n\n\n    :params train_data_path: path of training data, if this parameter\n        is not specified, paddle.dataset.imdb will be used to run this example\n    :type train_data_path: str\n    :params test_data_path: path of testing data, if this parameter\n        is not specified, paddle.dataset.imdb will be used to run this example\n    :type test_data_path: str\n    :params word_dict_path: path of training data, if this parameter\n        is not specified, paddle.dataset.imdb will be used to run this example\n    :type word_dict_path: str\n    :params num_pass: train pass number\n    :type num_pass: int\n    \"\"\"\n    if not os.path.exists(model_save_dir):\n        os.mkdir(model_save_dir)\n\n    use_default_data = (train_data_dir is None)\n\n    if use_default_data:\n        logger.info((\"No training data are porivided, \"\n                     \"use paddle.dataset.imdb to train the model.\"))\n        logger.info(\"please wait to build the word dictionary ...\")\n\n        word_dict = paddle.dataset.imdb.word_dict()\n        train_reader = paddle.batch(\n            paddle.reader.shuffle(\n                lambda: paddle.dataset.imdb.train(word_dict)(), buf_size=1000),\n            batch_size=100)\n        test_reader = paddle.batch(\n            lambda: paddle.dataset.imdb.test(word_dict)(), batch_size=100)\n\n        class_num = 2\n    else:\n        if word_dict_path is None or not os.path.exists(word_dict_path):\n            logger.info((\"word dictionary is not given, the dictionary \"\n                         \"is automatically built from the training data.\"))\n\n            # build the word dictionary to map the original string-typed\n            # words into integer-typed index\n            build_dict(\n                data_dir=train_data_dir,\n                save_path=word_dict_path,\n                use_col=1,\n                cutoff_fre=5,\n                insert_extra_words=[\"<UNK>\"])\n\n        if not os.path.exists(label_dict_path):\n            logger.info((\"label dictionary is not given, the dictionary \"\n                         \"is automatically built from the training data.\"))\n            # build the label dictionary to map the original string-typed\n            # label into integer-typed index\n            build_dict(\n                data_dir=train_data_dir, save_path=label_dict_path, use_col=0)\n\n        word_dict = load_dict(word_dict_path)\n\n        lbl_dict = load_dict(label_dict_path)\n        class_num = len(lbl_dict)\n        logger.info(\"class number is : %d.\" % (len(lbl_dict)))\n\n        train_reader = paddle.batch(\n            paddle.reader.shuffle(\n                reader.train_reader(train_data_dir, word_dict, lbl_dict),\n                buf_size=1000),\n            batch_size=batch_size)\n\n        if test_data_dir is not None:\n            # here, because training and testing data share a same format,\n            # we still use the reader.train_reader to read the testing data.\n            test_reader = paddle.batch(\n                paddle.reader.shuffle(\n                    reader.train_reader(test_data_dir, word_dict, lbl_dict),\n                    buf_size=1000),\n                batch_size=batch_size)\n        else:\n            test_reader = None\n\n    dict_dim = len(word_dict)\n    logger.info(\"length of word dictionary is : %d.\" % (dict_dim))\n\n    paddle.init(use_gpu=False, trainer_count=1)\n\n    # network config\n    cost, prob, label = topology(dict_dim, class_num)\n\n    # create parameters\n    parameters = paddle.parameters.create(cost)\n\n    # create optimizer\n    adam_optimizer = paddle.optimizer.Adam(\n        learning_rate=1e-3,\n        regularization=paddle.optimizer.L2Regularization(rate=1e-3),\n        model_average=paddle.optimizer.ModelAverage(average_window=0.5))\n\n    # create trainer\n    trainer = paddle.trainer.SGD(\n        cost=cost,\n        extra_layers=paddle.evaluator.auc(input=prob, label=label),\n        parameters=parameters,\n        update_equation=adam_optimizer)\n\n    # begin training network\n    feeding = {\"word\": 0, \"label\": 1}\n\n    def _event_handler(event):\n        \"\"\"\n        Define end batch and end pass event handler\n        \"\"\"\n        if isinstance(event, paddle.event.EndIteration):\n            if event.batch_id % 100 == 0:\n                logger.info(\"Pass %d, Batch %d, Cost %f, %s\\n\" % (\n                    event.pass_id, event.batch_id, event.cost, event.metrics))\n\n        if isinstance(event, paddle.event.EndPass):\n            if test_reader is not None:\n                result = trainer.test(reader=test_reader, feeding=feeding)\n                logger.info(\"Test at Pass %d, %s \\n\" % (event.pass_id,\n                                                        result.metrics))\n            with gzip.open(\n                    os.path.join(model_save_dir, \"dnn_params_pass_%05d.tar.gz\" %\n                                 event.pass_id), \"w\") as f:\n                trainer.save_parameter_to_tar(f)\n\n    trainer.train(\n        reader=train_reader,\n        event_handler=_event_handler,\n        feeding=feeding,\n        num_passes=num_passes)\n\n    logger.info(\"Training has finished.\")\n\n\ndef main(args):\n    if args.nn_type == \"dnn\":\n        topology = fc_net\n    elif args.nn_type == \"cnn\":\n        topology = convolution_net\n\n    train(\n        topology=topology,\n        train_data_dir=args.train_data_dir,\n        test_data_dir=args.test_data_dir,\n        word_dict_path=args.word_dict,\n        label_dict_path=args.label_dict,\n        batch_size=args.batch_size,\n        num_passes=args.num_passes,\n        model_save_dir=args.model_save_dir)\n\n\nif __name__ == \"__main__\":\n    args = parse_train_cmd()\n    if args.train_data_dir is not None:\n        assert args.word_dict and args.label_dict, (\n            \"the parameter train_data_dir, word_dict_path, and label_dict_path \"\n            \"should be set at the same time.\")\n    main(args)\n", "path": "text_classification/train.py"}]}