BLEU 翻译
让我们熟悉一下 BLEU 指标。
已为您加载了一个基于 Helsinki-NLP 西班牙语-英语翻译模型和 BLEU 指标的流水线,使用 evaluate 库中的 evaluate.load("bleu")。
给定以下用于评估的输入与参考译文:
input_sentence_1 = "Hola, ¿cómo estás?"
reference_1 = [
["Hello, how are you?", "Hi, how are you?"]
]
input_sentences_2 = ["Hola, ¿cómo estás?", "Estoy genial, gracias."]
references_2 = [
["Hello, how are you?", "Hi, how are you?"],
["I'm great, thanks.", "I'm great, thank you."]
]
本练习是课程的一部分
Python 中的 LLM 入门
交互式实操练习
通过完成这段示例代码来试试这个练习。
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-es-en")
# Translate the first input sentence then calucate the BLEU metric for translation quality
translated_output = ____
translated_sentence = translated_output[0]['translation_text']
print("Translated:", translated_sentence)
results = bleu.____(predictions=____, references=____)
print(results)