Repository: PaddlePaddle/models

Issue:
fluid/PaddleNLP/sequence_tagging_for_ner 预测问题
用ner模型在预测的时候发现，给预测数据随意标记的label会影响到最终的预测结果；当把数据减少一些(比如10w)后，这个问题就没有了，数据比较大的时候term的预测结果就会往这个随意标记的类别大量倾斜。。。

定义term的类别只有1和0， 预测是时候任意定义所有label=2，发现用较大预测数据集时候，大部分term的标签被预测为2，数据量较少时候，则是正常的

预测结果正常：
![image](https://user-images.githubusercontent.com/19464821/49934978-c2566d80-ff0a-11e8-8726-091f6b1a7549.png)

预测结果出现问题：
![image](https://user-images.githubusercontent.com/19464821/49934993-cf735c80-ff0a-11e8-8fb0-0a8bb720777c.png)



Discussion:
问题已收到，追查定位后会尽快反馈。

Resolving patch:
diff --git a/fluid/PaddleNLP/sequence_tagging_for_ner/infer.py b/fluid/PaddleNLP/sequence_tagging_for_ner/infer.py
--- a/fluid/PaddleNLP/sequence_tagging_for_ner/infer.py
+++ b/fluid/PaddleNLP/sequence_tagging_for_ner/infer.py
@@ -38,12 +38,10 @@ def infer(model_path, batch_size, test_data_file, vocab_file, target_file,
         for data in test_data():
             word = to_lodtensor([x[0] for x in data], place)
             mark = to_lodtensor([x[1] for x in data], place)
-            target = to_lodtensor([x[2] for x in data], place)
             crf_decode = exe.run(
                 inference_program,
                 feed={"word": word,
-                      "mark": mark,
-                      "target": target},
+                      "mark": mark},
                 fetch_list=fetch_targets,
                 return_numpy=False)
             lod_info = (crf_decode[0].lod())[0]
diff --git a/fluid/PaddleNLP/sequence_tagging_for_ner/train.py b/fluid/PaddleNLP/sequence_tagging_for_ner/train.py
--- a/fluid/PaddleNLP/sequence_tagging_for_ner/train.py
+++ b/fluid/PaddleNLP/sequence_tagging_for_ner/train.py
@@ -61,22 +61,21 @@ def main(train_data_file,
     avg_cost, feature_out, word, mark, target = ner_net(
         word_dict_len, label_dict_len, parallel)
 
-    sgd_optimizer = fluid.optimizer.SGD(learning_rate=1e-3)
-    sgd_optimizer.minimize(avg_cost)
-
     crf_decode = fluid.layers.crf_decoding(
         input=feature_out, param_attr=fluid.ParamAttr(name='crfw'))
 
     (precision, recall, f1_score, num_infer_chunks, num_label_chunks,
-     num_correct_chunks) = fluid.layers.chunk_eval(
-         input=crf_decode,
-         label=target,
-         chunk_scheme="IOB",
-         num_chunk_types=int(math.ceil((label_dict_len - 1) / 2.0)))
+    num_correct_chunks) = fluid.layers.chunk_eval(
+        input=crf_decode,
+        label=target,
+        chunk_scheme="IOB",
+        num_chunk_types=int(math.ceil((label_dict_len - 1) / 2.0)))
     chunk_evaluator = fluid.metrics.ChunkEvaluator()
 
     inference_program = fluid.default_main_program().clone(for_test=True)
     test_fetch_list = [num_infer_chunks, num_label_chunks, num_correct_chunks]
+    sgd_optimizer = fluid.optimizer.SGD(learning_rate=1e-3)
+    sgd_optimizer.minimize(avg_cost)
 
     if "CE_MODE_X" not in os.environ:
         train_reader = paddle.batch(
@@ -135,7 +134,7 @@ def main(train_data_file,
               " pass_f1_score:" + str(test_pass_f1_score))
 
         save_dirname = os.path.join(model_save_dir, "params_pass_%d" % pass_id)
-        fluid.io.save_inference_model(save_dirname, ['word', 'mark', 'target'],
+        fluid.io.save_inference_model(save_dirname, ['word', 'mark'],
                                       crf_decode, exe)
 
     if "CE_MODE_X" in os.environ:


Test patch: