Bắt đầu ngayBắt đầu miễn phí

Dịch BLEU

Hãy làm quen với thước đo BLEU.

Một pipeline dựa trên mô hình dịch Tây Ban Nha–Anh của Helsinki-NLP và thước đo BLEU đã được tải sẵn cho bạn, sử dụng evaluate.load("bleu") từ thư viện evaluate.

Với các đầu vào và tham chiếu để đánh giá như sau:

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."]
     ]

Bài tập này là một phần của khóa học

Nhập môn LLMs trong Python

Xem khóa học

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

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)
Chỉnh sửa và Chạy Mã