Get startedGet started for free

BLEU translations

Let's get familiar with the BLEU metric.

A pipeline based on the Helsinki-NLP Spanish-English translation model and the BLEU metric has been loaded for you, using evaluate.load("bleu") from the evaluate library.

Given the following inputs and references for evaluation:

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

This exercise is part of the course

Introduction to LLMs in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

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)
Edit and Run Code