Sub topic 15
Choosing and reporting metrics for your task
This chapter assumes you can read the BLEU, ROUGE, and BERTScore computations from earlier chapters. You should know clipped precision, the brevity penalty, longest common subsequence, and greedy embedding matching. It also assumes you are comfortable running the sacrebleu, rouge_score, and bert_score packages. The goal here is practical: pick metrics that fit your task, combine them sensibly, and report numbers so another person can reproduce them.
Start from the task, not the metric
Each metric encodes an assumption about what a good output looks like. Pick the metric whose assumption matches your task.
| Task | Typical primary metric | Why | Main risk |
|---|---|---|---|
| Machine translation | SacreBLEU (corpus level), plus a learned or embedding metric | Outputs are close in length and wording to references | Valid paraphrases score low |
| Summarization | ROUGE-1, ROUGE-2, ROUGE-L or ROUGE-Lsum, plus BERTScore | Content coverage matters, so recall-oriented overlap fits | Unfaithful summaries can still score well |
| Headline or caption generation | ROUGE or BLEU with several references, plus BERTScore | Very short outputs, many valid phrasings | Single-reference scores are noisy |
| Open-ended dialogue or story generation | Human evaluation first; BERTScore only as a weak signal | Many valid outputs share no words with the reference | All reference-based metrics correlate weakly |
| Data-to-text or question answering with short answers | Exact match or token F1, plus a factuality check | Correctness is binary or entity-based | Overlap metrics miss wrong numbers and names |
The pattern is that the more open-ended the task, the less any single reference represents the space of good answers, and the less the score tells you.
A decision path
Combine metrics that fail differently
Two metrics add information only if their errors differ. BLEU and ROUGE-2 both reward exact n-gram matches, so they fail in the same way: they penalize correct paraphrases. BERTScore fails differently. It forgives paraphrase, but it can give high scores to fluent text that contradicts the reference, because contextual embeddings of related words are close.
A workable default for summarization is ROUGE-1, ROUGE-2, and ROUGE-L for lexical coverage, BERTScore F1 for semantic closeness, and a separate faithfulness check. For translation, use SacreBLEU plus BERTScore, and add a learned metric if you can afford one.
Do not average different metrics into one number. Their scales differ. BLEU runs 0 to 100 by convention, ROUGE runs 0 to 1, and BERTScore without baseline rescaling sits in a narrow high band. A mean of these has no interpretation.
Report so others can reproduce the number
A bare "BLEU = 31.2" cannot be compared with anyone else's 31.2. Tokenization, casing, smoothing, the number of references, and the model behind BERTScore all change the score. Record the following.
- BLEU: the SacreBLEU signature, which encodes tokenizer, casing, smoothing, number of references, and library version.
- ROUGE: the variants reported, whether stemming was on, whether you used ROUGE-L or ROUGE-Lsum, and which of precision, recall, or F-measure you quote.
- BERTScore: the underlying model, the layer, whether IDF weighting was used, whether baseline rescaling was used, and the library hash string.
- Everywhere: the test set, its version, the number of references per example, and any preprocessing applied to hypotheses and references.
import sacrebleu
from sacrebleu.metrics import BLEU
from rouge_score import rouge_scorer
from bert_score import BERTScorer
hypotheses = [
"the cat sat on the mat",
"there is a dog in the garden",
"he went to the market yesterday",
]
references = [
"the cat is on the mat",
"a dog is in the garden",
"he walked to the market yesterday",
]
# BLEU: one reference stream, with the signature kept for the report
bleu = BLEU()
bleu_result = bleu.corpus_score(hypotheses, [references])
print(f"BLEU {bleu_result.score:.1f}")
print("signature:", bleu.get_signature())
# ROUGE: average F-measure over examples; the order is (target, prediction)
scorer = rouge_scorer.RougeScorer(["rouge1", "rouge2", "rougeL"], use_stemmer=True)
totals = {"rouge1": 0.0, "rouge2": 0.0, "rougeL": 0.0}
for hyp, ref in zip(hypotheses, references):
result = scorer.score(ref, hyp)
for name in totals:
totals[name] += result[name].fmeasure
for name, total in totals.items():
print(name, "F1", round(total / len(hypotheses), 4))
# BERTScore: keep the hash, which records model, layer, IDF, and baseline settings
bert = BERTScorer(lang="en", rescale_with_baseline=True)
P, R, F1 = bert.score(hypotheses, references)
print("BERTScore F1", round(F1.mean().item(), 4))
print("hash:", bert.hash)Paste the printed signature and hash next to the numbers in your paper, README, or experiment log.
Report uncertainty, not just a point value
Test sets are samples. A 0.4 BLEU difference between two systems on 500 sentences is often within noise. Bootstrap resampling gives a confidence interval. Resample whole examples with replacement and recompute the corpus-level metric each time. Do not average sentence-level BLEU scores, because corpus BLEU pools n-gram counts across sentences and the two quantities differ.
import random
import sacrebleu
def corpus_bleu_score(hyps, refs):
return sacrebleu.corpus_bleu(hyps, [refs]).score
def bootstrap_ci(hyps, refs, metric, n_samples=1000, seed=0):
rng = random.Random(seed)
n = len(hyps)
scores = []
for _ in range(n_samples):
idx = [rng.randrange(n) for _ in range(n)]
scores.append(metric([hyps[i] for i in idx], [refs[i] for i in idx]))
scores.sort()
low = scores[int(0.025 * n_samples)]
high = scores[int(0.975 * n_samples) - 1]
return low, high
hyps = [
"the cat sat on the mat",
"there is a dog in the garden",
"he went to the market yesterday",
"she reads a book every evening",
"the train arrives at noon",
"we plan to visit the museum",
]
refs = [
"the cat is on the mat",
"a dog is in the garden",
"he walked to the market yesterday",
"she reads a book every evening",
"the train arrives at noon today",
"we plan to visit the old museum",
]
print("point estimate:", round(corpus_bleu_score(hyps, refs), 1))
print("95% interval:", bootstrap_ci(hyps, refs, corpus_bleu_score))To compare two systems, resample the same indices for both and look at the distribution of the score difference. This paired approach removes variation caused by easy and hard examples. SacreBLEU's command line also offers paired bootstrap testing.
Common mistakes
- Comparing scores across setups. A BLEU computed with your own tokenizer cannot be compared with a published SacreBLEU number. Recompute baselines under the same configuration.
- Using sentence-level BLEU as a headline number. It is unstable and is zero whenever an n-gram order has no match, unless smoothing is applied.
- Reading ROUGE recall alone. A candidate that copies the whole source gets high recall. Report F-measure or show precision and recall together.
- Quoting raw BERTScore as if it were a percentage match. Unrescaled scores cluster in a narrow high range, so differences look tiny. Rescaling with the baseline makes them easier to read but does not change the ranking of systems.
- Ignoring the reference quality. If references are noisy, every reference-based metric inherits the noise. Multiple references raise BLEU and ROUGE scores, so state the number used.
- Tuning to the metric. If you select checkpoints on BLEU and report BLEU on the same set, the number is optimistic. Select on a development set and report on a held-out test set.
Validate the metric against people
Before you trust a metric for a new domain, check that it tracks what you care about. Take 50 to 100 outputs, have people rate them, and compute the rank correlation between metric scores and ratings. If the correlation is weak, the metric is measuring something other than quality for your task. Reference-based metrics are proxies, and the proxy can drift when the domain, the length of outputs, or the model family changes.
Keep a small set of failure cases next to the scores. Examples where the metric disagrees with a reader, such as a correct paraphrase scored low or a wrong number scored high, tell you more than a decimal place on the average.
Exercise
A team reports "BLEU improved from 28.1 to 29.0" for a summarization model, using sentence-level BLEU averaged over 200 examples, with a custom tokenizer. Name three problems and what you would do instead.
Show answer
(1) Sentence-level averages are unstable and understate or zero out sentences without 4-gram matches; use corpus-level SacreBLEU and report its signature. (2) BLEU is precision-oriented and designed for translation, so for summarization report ROUGE-1, ROUGE-2, and ROUGE-L or ROUGE-Lsum, with the settings used, plus BERTScore. (3) A 0.9 gap on 200 examples may be noise; run a paired bootstrap and report an interval. A custom tokenizer also makes the number incomparable with other work, and no faithfulness check is mentioned.
Exercise
You are evaluating a chatbot that gives open-ended replies. BERTScore F1 (rescaled) is 0.31 for model A and 0.33 for model B. What can you conclude, and what would you do next?
Show answer
Very little. Open-ended replies have many valid forms, so a single reference represents the space poorly, and a 0.02 gap may be within noise. Compute a bootstrap interval for the difference, then collect human ratings on a sample of outputs and check the rank correlation with the metric. Report the BERTScore hash alongside the numbers and treat them as a weak signal, not a ranking.