CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
huggingface

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: huggingface/notebooks
Path: blob/main/course/videos/bleu_metric.ipynb
Views: 2542
Kernel: Unknown Kernel

This notebook regroups the code sample of the video below, which is a part of the Hugging Face course.

#@title from IPython.display import HTML HTML('<iframe width="560" height="315" src="https://www.youtube.com/embed/M05L1DhFqcw?rel=0&amp;controls=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>')

Install the Transformers and Datasets libraries to run this notebook.

! pip install datasets transformers[sentencepiece]
from datasets import load_metric bleu = load_metric("bleu") predictions = [["I", "have", "thirty", "six", "years"]] references = [ [["I", "am", "thirty", "six", "years", "old"], ["I", "am", "thirty", "six"]] ] bleu.compute(predictions=predictions, references=references)
predictions = [["I", "have", "thirty", "six", "years"]] references = [ [["I", "am", "thirty", "six", "years", "old"], ["I", "am", "thirty", "six"]] ] bleu.compute(predictions=predictions, references=references)
predictions = [["I", "have", "thirty", "six", "years"]] references = [ [["I", "am", "thirty", "six", "years", "old"], ["I", "am", "thirty", "six"]] ] bleu.compute(predictions=predictions, references=references)
! pip install sacrebleu
sacrebleu = load_metric("sacrebleu") # SacreBLEU operates on raw text, not tokens predictions = ["I have thirty six years"] references = [["I am thirty six years old", "I am thirty six"]] sacrebleu.compute(predictions=predictions, references=references)