開始使用免費開始

BLEU 翻譯

來熟悉一下 BLEU 評估指標。

我們已為你載入了一個以 Helsinki-NLP 西班牙文到英文的翻譯模型為基礎、並使用 BLEU 指標的 pipeline,透過 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)
編輯並執行程式碼