diff --git a/PaddleNLP/similarity_net/run_classifier.py b/PaddleNLP/similarity_net/run_classifier.py index 727aa5554104bc25803b7e4b3b489ebdcf02259b..4413c24c6722b2703dd6f758a2febd8924857dae 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" %