Sub topic 12
Measuring quality with ROUGE, BLEU and chrF
This chapter assumes you can run a Hugging Face generate call, know what a reference text is, and have read the earlier chapters on summarisation and translation. You will learn what the three common automatic metrics count, how to compute them correctly, and where they mislead.
Why automatic metrics exist
A summary or translation has no single correct answer. Human judges give the best signal, but they are slow and costly. Automatic metrics compare a model's output (the hypothesis or prediction) with one or more human-written references and return a number. You can compute that number thousands of times while tuning decoding settings or fine-tuning.
All three metrics in this chapter work by overlap. They count shared pieces of text between the prediction and the reference. None of them reads the text for meaning or checks facts. Keep that in mind throughout.
| Metric | Typical task | Unit compared | Favours |
|---|---|---|---|
| ROUGE-N | Summarisation | Word n-grams | Recall of reference content |
| ROUGE-L | Summarisation | Longest common subsequence of words | Shared word order |
| BLEU | Translation | Word n-grams (1 to 4) | Precision, with a length penalty |
| chrF | Translation | Character n-grams | Balance of precision and recall (recall weighted more) |
ROUGE for summaries
ROUGE stands for Recall-Oriented Understudy for Gisting Evaluation. Its main variants are:
- ROUGE-1 counts shared single words (unigrams).
- ROUGE-2 counts shared word pairs (bigrams). It rewards some local phrasing.
- ROUGE-L uses the longest common subsequence (LCS). The matched words must appear in the same order, but they need not be adjacent.
- ROUGE-Lsum computes LCS per sentence and sums the results. It is the usual choice for multi-sentence summaries, and the Hugging Face implementation expects sentences separated by newlines.
For each variant, the library reports precision, recall and F1:
- Precision is the share of prediction n-grams that also appear in the reference.
- Recall is the share of reference n-grams that appear in the prediction.
- F1 is the harmonic mean of the two.
The evaluate ROUGE implementation returns the F1 values by default. A long prediction can reach high recall just by containing many words, which is why F1 is the safer single number.
A worked example
Take a reference of the council approved 40 km of new bike lanes (9 words after lowercasing) and a prediction of the council approved new bike lanes (6 words).
The prediction's unigrams are all in the reference, so precision is 6/6 = 1.0. Six of the nine reference unigrams are matched, so recall is 6/9 = 0.667. F1 is 2 × 1.0 × 0.667 / (1.0 + 0.667) = 0.8.
Bigrams give a lower score. The prediction has five bigrams. Three of them (the council, council approved, new bike... and bike lanes) need checking. the council, council approved, new bike and bike lanes all occur in the reference, but approved new does not, because the reference has approved 40. So precision is 4/5 = 0.8, and recall is 4/8 = 0.5, because the reference has eight bigrams. ROUGE-2 F1 is about 0.615. Dropping the words 40 km of hurts bigram scores more than unigram scores.
BLEU for translations
BLEU (Bilingual Evaluation Understudy) was designed for machine translation. It has three parts:
- Modified n-gram precision for n = 1 to 4. Each prediction n-gram is credited at most as many times as it appears in the reference. This stops a prediction like
the the the thefrom scoring well. - A geometric mean of the four precisions. If any precision is zero, the whole score is zero unless smoothing is applied.
- A brevity penalty. BLEU has no recall term, so a very short output could score a high precision. The penalty reduces the score when the prediction is shorter than the reference.
BLEU is computed over a whole test set (corpus level), not as an average of sentence scores. Sentence-level BLEU is unstable because short sentences often have no matching 4-grams. The score runs from 0 to 100 in SacreBLEU. Scores are only comparable on the same test set, the same references and the same settings.
Use SacreBLEU
Older papers reported BLEU with their own tokenisation, which made numbers hard to compare. SacreBLEU fixes this. It applies its own standard tokenisation to raw text and records its settings in a signature string, so that other people can reproduce your number. Pass detokenised text, as a user would read it, and report the signature along with the score.
chrF for translations
chrF (character n-gram F-score) compares character n-grams instead of words. The default compares character n-grams up to length 6 and combines precision and recall with an F-score that weights recall twice as much as precision (β = 2). chrF++ also adds word unigrams and bigrams.
Character-level matching has practical advantages:
- Languages with rich inflection, such as German, Finnish or Turkish, produce many word forms. BLEU gives no credit for
HäusernagainstHaus, while chrF gives partial credit for the shared characters. - It needs no word tokeniser, so it is easier to apply to languages written without spaces.
- It works better at sentence level than BLEU.
Computing the metrics
The evaluate library wraps all three. Install it with pip install evaluate rouge_score sacrebleu.
import evaluate
rouge = evaluate.load("rouge")
sacrebleu = evaluate.load("sacrebleu")
chrf = evaluate.load("chrf")
summary_predictions = ["The council approved 40 km of new bike lanes."]
summary_references = ["The city council approved 40 kilometres of new bike lanes."]
rouge_scores = rouge.compute(
predictions=summary_predictions,
references=summary_references,
use_stemmer=True,
)
print(rouge_scores)
translation_predictions = ["Das Haus ist wunderbar.", "Wo ist der nächste Bahnhof?"]
translation_references = [
["Das Haus ist wunderbar."],
["Wo ist der nächstgelegene Bahnhof?"],
]
bleu_scores = sacrebleu.compute(
predictions=translation_predictions,
references=translation_references,
)
print(round(bleu_scores["score"], 1), bleu_scores["sys_len"], bleu_scores["ref_len"])
chrf_scores = chrf.compute(
predictions=translation_predictions,
references=translation_references,
)
print(round(chrf_scores["score"], 1))Points to notice:
- ROUGE returns values between 0 and 1 under the keys
rouge1,rouge2,rougeLandrougeLsum. SacreBLEU and chrF return values between 0 and 100. use_stemmer=Truereduces words to stems, solanesandlanematch. The stemmer is English-only. The default ROUGE tokeniser also removes non-ASCII characters, so it is not suitable for German, Chinese or Arabic text as it stands.- SacreBLEU and chrF take a list of reference lists. Each prediction can have several references, and every inner list must have the same length across the whole corpus.
- The
sys_lenandref_lenfields let you check the brevity penalty. Asys_lenmuch smaller thanref_lenmeans the output is too short.
Scoring model output
In a real evaluation you generate predictions for a held-out test set first, then score them. Keep the order of predictions and references aligned. Decode with skip_special_tokens=True, and replace any -100 padding in labels with the pad token ID before decoding them as references.
Test inputs -> model.generate -> decode -> predictions
Test targets -> decode (labels, -100 replaced) -> references
predictions + references -> metric -> scoreThe same flow in a diagram:
What the numbers mean
Absolute values depend on the dataset. A ROUGE-1 near 44 and ROUGE-L near 30 on the CNN/DailyMail news benchmark is considered strong, while the same model on another domain may score far lower. For translation, BLEU values above 30 are often good for high-resource pairs, and values below 10 usually mean the output is hard to understand. Treat these as rough guides only.
Differences are what matter. Before claiming one system beats another:
- Use the same test set, references and metric settings for both.
- Check that the difference is larger than random variation. SacreBLEU supports bootstrap resampling and paired significance tests. A gain of 0.2 points on a small test set is often noise.
- Read a sample of outputs. A metric can rise while quality falls.
Limits and failure modes of overlap metrics
- Paraphrase blindness. A correct summary using different words scores low.
The mayor resignedandThe city leader stepped downshare almost nothing. - No fact checking. A summary can copy many reference words and still state a wrong fact, such as the wrong number. ROUGE and BLEU do not reliably penalise hallucination.
- Reference dependence. A single reference captures only one acceptable output. Multiple references raise scores and make them more stable.
- Length effects. ROUGE recall rewards long outputs. BLEU's brevity penalty punishes short ones. Changing
max_lengthorlength_penaltycan move the score without changing quality. - Word-order and grammar. ROUGE-1 ignores order entirely. BLEU's 4-gram term catches some fluency problems but not all.
- Rare terms and names. Mistranslating a product name counts the same as missing a common word, even though users may care far more.
- Tokenisation mismatches. Different tokenisation changes the numbers. This is why SacreBLEU exists.
- Metric gaming. Extractive summaries that copy source sentences can score well on ROUGE yet read poorly.
Learned metrics such as COMET and BERTScore compare meaning using neural embeddings and correlate better with human judgements. They cost more to run and depend on their own models, so many teams report one overlap metric plus one learned metric, and still review samples by hand.
Choosing a metric
- For summarisation, report ROUGE-1, ROUGE-2 and ROUGE-Lsum as F1. Add a factual-consistency check or human review if accuracy matters.
- For translation, report SacreBLEU with its signature and chrF. Use chrF when the target language is morphologically rich or lacks spaces.
- Compute scores at corpus level. Use sentence-level scores only to find bad examples.
- Keep the evaluation set fixed while you change decoding settings, so changes in score come from the model.
Exercise
A summariser's ROUGE-1 recall is 0.90 but its precision is 0.30 against a 50-word reference. What is wrong with the output, and which single number would you report instead of recall?
Show answer
The output is much too long. It contains most of the reference words (recall 0.90) but about 70% of its words are not in the reference. Roughly 45 reference words matched; with precision 0.30, the prediction has about 150 words. Report ROUGE-1 F1, which here is 2 × 0.30 × 0.90 / (0.30 + 0.90) = 0.45, so the padding is penalised.
Exercise
You score a German translation system with SacreBLEU and get 0.0 although the output looks reasonable. The test set has very short sentences. Give one likely cause and two ways to get a more informative number.
Show answer
With short sentences, the corpus may contain no matching 4-grams, so the geometric mean of the n-gram precisions becomes zero. Compute the score over a larger corpus rather than per sentence, and report chrF, which uses character n-grams and does not collapse to zero. Applying BLEU smoothing for sentence-level use also helps.