1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| mt_data = [ {"src":"Large language models are changing software development.","ref":"大型语言模型正在改变软件开发。"}, {"src":"We use retrieval to reduce hallucination.","ref":"我们使用检索来减少幻觉。"}, {"src":"The training loss decreases steadily.","ref":"训练损失稳定下降。"}, {"src":"Quantization can reduce memory usage.","ref":"量化可以降低内存占用。"}, {"src":"Agent systems need strong safety constraints.","ref":"智能体系统需要强安全约束。"}, ]
def mt_prompt(src): return f"translate English to Chinese: {src}"
mt_greedy=[gen(mt_prompt(x['src']),model_mt,tok_mt,temperature=0.0)for x in mt_data] mt_sample=[gen(mt_prompt(x['src']),model_mt,tok_mt,temperature=0.7,top_p=0.9) for x in mt_data]
for i,x in enumerate(mt_data): print(f"[{i}]", x['src']) print('ref=', x['ref']) print('greedy=', mt_greedy[i]) print('sample=', mt_sample[i]) print('-'*60)
|