From 7340c88c4701148eec09e17ec9cbb572d4f7cfc0 Mon Sep 17 00:00:00 2001 From: Lizhengo <18811528909@163.com> Date: Wed, 21 Aug 2019 18:39:06 +0800 Subject: [PATCH] fix open file bug in test (#3159) * fix pred in simnet * add init checkpoint in train and fix file open bug in window10 * Update README.md * fix file open bug in test --- PaddleNLP/similarity_net/run_classifier.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/PaddleNLP/similarity_net/run_classifier.py b/PaddleNLP/similarity_net/run_classifier.py index 727aa555..4413c24c 100644 --- a/PaddleNLP/similarity_net/run_classifier.py +++ b/PaddleNLP/similarity_net/run_classifier.py @@ -17,6 +17,7 @@ sys.path.append("..") import paddle import paddle.fluid as fluid import numpy as np +import codecs import config import utils import reader @@ -326,7 +327,7 @@ def test(conf_dict, args): simnet_process = reader.SimNetProcessor(args, vocab) # load auc method metric = fluid.metrics.Auc(name="auc") - with open("predictions.txt", "w") as predictions_file: + with codecs.open("predictions.txt", "w", "utf-8") as predictions_file: # Get model path model_path = args.init_checkpoint # Get device @@ -430,7 +431,7 @@ def infer(args): map(lambda item: str((item[0] + 1) / 2), output[1])) else: preds_list += map(lambda item: str(np.argmax(item)), output[1]) - with open(args.infer_result_path, "w") as infer_file: + with codecs.open(args.infer_result_path, "w", "utf-8") as infer_file: for _data, _pred in zip(simnet_process.get_infer_data(), preds_list): infer_file.write(_data + "\t" + _pred + "\n") logging.info("infer result saved in %s" % -- GitLab