in utils/compute_score.py [0:0]
def compute_nmt_zh2en(file_path, model_path):
references = []
candidates = []
comet_data = []
print("金融中英翻译")
# model_path = download_model("Unbabel/XCOMET-XL")
model = load_from_checkpoint(model_path) # XCOMET-XL/checkpoints/model.ckpt
"""
data = [
{
"src": "10 到 15 分钟可以送到吗",
"mt": "Can I receive my food in 10 to 15 minutes?",
"ref": "Can it be delivered between 10 to 15 minutes?"
},...
]
"""
with open(file_path, 'r') as input_file:
print("Reading\t" + file_path)
sample_list = json.load(input_file)
for line in sample_list:
if line['sub_task'] == '金融中英翻译':
references.append(" ".join(tokenizer_en(line['output'])))
candidates.append(" ".join(tokenizer_en(line['predict'])))
src = line['instruction'].replace("你是一个金融行业专家,请将下面金融领域的中文内容翻译成准确、专业的英文。\n中文:", "").replace("英文:",
"").strip()
comet_data.append({
"src": src,
"mt": line['predict'],
"ref": line['output']
})
_, bleu4 = bleu_score(references, candidates)
model_output = model.predict(comet_data, batch_size=32, gpus=1)
print(model_output.system_score) # system-level score
print('\n')
return bleu4, model_output.system_score