Aan de slagGa gratis aan de slag

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

Deze oefening maakt deel uit van de cursus

Introduction to LLMs in Python

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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)
Code bewerken en uitvoeren