diff --git a/PaddleNLP/neural_machine_translation/transformer/infer.py b/PaddleNLP/neural_machine_translation/transformer/infer.py index 8a6804e6a496888e503449190ddc74846b1cff6e..9a3bfa2a78e475bd3ea996ae492bc7a08279d22a 100644 --- a/PaddleNLP/neural_machine_translation/transformer/infer.py +++ b/PaddleNLP/neural_machine_translation/transformer/infer.py @@ -4,6 +4,9 @@ import multiprocessing import numpy as np import os import sys +if sys.version[0] == '2': + reload(sys) + sys.setdefaultencoding("utf-8") sys.path.append("../../") sys.path.append("../../models/neural_machine_translation/transformer/") from functools import partial @@ -307,13 +310,13 @@ def fast_infer(args): for j in range(end - start): # for each candidate sub_start = seq_ids.lod()[1][start + j] sub_end = seq_ids.lod()[1][start + j + 1] - hyps[i].append(" ".join([ + hyps[i].append(b" ".join([ trg_idx2word[idx] for idx in post_process_seq( np.array(seq_ids)[sub_start:sub_end]) ])) scores[i].append(np.array(seq_scores)[sub_end - 1]) - print(hyps[i][-1]) + print(hyps[i][-1].decode("utf8")) if len(hyps[i]) >= InferTaskConfig.n_best: break except (StopIteration, fluid.core.EOFException): diff --git a/PaddleNLP/neural_machine_translation/transformer/train.py b/PaddleNLP/neural_machine_translation/transformer/train.py index 09c50e453fd5b5bb7b25a69e65deb83c5e91b62f..0d30178ae98a0fc3cba1a71e7fba596aeb53201f 100644 --- a/PaddleNLP/neural_machine_translation/transformer/train.py +++ b/PaddleNLP/neural_machine_translation/transformer/train.py @@ -11,6 +11,9 @@ if os.environ.get('FLAGS_eager_delete_tensor_gb', None) is None: import six import sys +if sys.version[0] == '2': + reload(sys) + sys.setdefaultencoding("utf-8") sys.path.append("../../") sys.path.append("../../models/neural_machine_translation/transformer/") import time diff --git a/PaddleNLP/unarchived/neural_machine_translation/transformer/infer.py b/PaddleNLP/unarchived/neural_machine_translation/transformer/infer.py index 9f168199b7a89697489c047d0e3b724b187421fc..62e7ce39531c683d3e2a30e51257e0be6e2aa258 100644 --- a/PaddleNLP/unarchived/neural_machine_translation/transformer/infer.py +++ b/PaddleNLP/unarchived/neural_machine_translation/transformer/infer.py @@ -3,6 +3,10 @@ import ast import multiprocessing import numpy as np import os +import sys +if sys.version[0] == '2': + reload(sys) + sys.setdefaultencoding("utf-8") from functools import partial import paddle @@ -303,13 +307,13 @@ def fast_infer(args): for j in range(end - start): # for each candidate sub_start = seq_ids.lod()[1][start + j] sub_end = seq_ids.lod()[1][start + j + 1] - hyps[i].append(" ".join([ + hyps[i].append(b" ".join([ trg_idx2word[idx] for idx in post_process_seq( np.array(seq_ids)[sub_start:sub_end]) ])) scores[i].append(np.array(seq_scores)[sub_end - 1]) - print(hyps[i][-1]) + print(hyps[i][-1].decode("utf8")) if len(hyps[i]) >= InferTaskConfig.n_best: break except (StopIteration, fluid.core.EOFException): diff --git a/PaddleNLP/unarchived/neural_machine_translation/transformer/train.py b/PaddleNLP/unarchived/neural_machine_translation/transformer/train.py index ade645997c8698c783372cf1cfd7c87a2c67effa..73213de6777455084f1c99d02c014deab1f0bfb4 100644 --- a/PaddleNLP/unarchived/neural_machine_translation/transformer/train.py +++ b/PaddleNLP/unarchived/neural_machine_translation/transformer/train.py @@ -6,6 +6,9 @@ import multiprocessing import os import six import sys +if sys.version[0] == '2': + reload(sys) + sys.setdefaultencoding("utf-8") import time import numpy as np