LLM & Generation Evaluation
P5.evaluation.03 · Audience: guest, it-ml, language-pro · Prerequisites: Embedding Evaluation
Everything measured so far in this track had a ground truth to lean on — a correct label, a reference sentence. A large language model breaks that comfort: a good summary or answer can be phrased a thousand different ways, so counting matching words against one reference punishes correct output, and evaluation itself becomes a modelling problem. In this module you meet the modern answers in turn — scoring generated text by meaning rather than by surface overlap, the big public benchmark suites and the test-set contamination that quietly inflates their scores, using one model to judge another and the biases that come with it, and finally human annotation, whose own reliability must itself be measured. The classical metrics are assumed known from the first module of this track, which this module closes.
BLEU and ROUGE measure surface overlap — matching tokens between hypothesis and reference. For abstractive summarisation, paraphrase, and free-form generation, a correct output may share zero tokens with the reference and still score 0.
The paraphrase problem:
| Hypothesis | Reference | BLEU-1 | Semantic equivalence | BLEU correct? |
|---|---|---|---|---|
| The cat sat on the mat. | A feline rested upon the rug. | 0.000 | ✓ same meaning | ✗ No |
| A feline rested upon the rug. | A feline rested upon the rug. | 1.000 | ✓ same meaning | ✓ Yes |
| The cat sat on the mat. | The cat sat on the mat. | 1.000 | ✓ same meaning | ✓ Yes |
Row 1: the hypothesis is a perfect paraphrase of the reference but BLEU-1 = 0 because no tokens match. BLEU cannot distinguish a wrong answer from a correct paraphrase.
BERTScore (Zhang et al. 2020) replaces exact token matching with contextual embedding similarity — the contextual vectors come from a pretrained BERT-style encoder, the machinery built up in the P10 Transformers pillar:
- Embed all m hypothesis tokens and all n reference tokens with a pretrained BERT-style model.
- Precision: for each hypothesis token, take its maximum cosine similarity to any reference token:
- Recall: for each reference token, take its maximum cosine similarity to any hypothesis token:
- F1: the harmonic mean of PBERT and RBERT.
Key property: 'cat' and 'feline' have high cosine similarity in BERT space, so a paraphrase scores near 1.0 even with no token overlap.
Worked BERTScore example. Hypothesis: 'a canine ran fast'; reference: 'a dog sprinted'. Suppose a BERT model produces the following pairwise cosine similarities (rows = hypothesis tokens, columns = reference tokens):
| a | dog | sprinted | |
|---|---|---|---|
| a | 1.00 | 0.40 | 0.30 |
| canine | 0.40 | 0.92 | 0.55 |
| ran | 0.30 | 0.45 | 0.88 |
| fast | 0.25 | 0.35 | 0.72 |
Precision (row max, then mean): a → 1.00, canine → 0.92, ran → 0.88, fast → 0.72, so P = 0.8800. Recall (column max, then mean): a → 1.00, dog → 0.92, sprinted → 0.88, so R = 0.9333.
P (BERT)
0.8800
R (BERT)
0.9333
F1 (BERT)
0.9059
BERTScore F1 = 2 × 0.8800 × 0.9333 / (0.8800 + 0.9333) = 0.9059. Compare to BLEU-1: only 'a' matches, so BLEU-1 ≈ 0.25 × BP, well below 0.25. BERTScore captures that 'canine'/'dog' and 'ran'/'sprinted' are semantically equivalent.
Other embedding-based metrics:
- MoverScore (Zhao et al. 2019): uses Earth Mover's Distance (Wasserstein distance) between the embedding distributions of hypothesis and reference — captures meaning transportation rather than just token alignment.
- BLEURT (Sellam et al. 2020): fine-tunes BERT specifically to predict human translation-quality judgements — a learned metric that correlates better with human scores than BERTScore on MT.
- COMET (Rei et al. 2020): another learned metric for MT, trained on direct-assessment human scores from WMT — currently state-of-the-art for MT evaluation.
📚 Go Further
The papers and benchmarks this module draws on.
| Type | Resource |
|---|---|
| Paper | Zhang et al. 2020 — BERTScore: Evaluating Text Generation with BERT; see also MoverScore (Zhao et al. 2019), BLEURT (Sellam et al. 2020), COMET (Rei et al. 2020) |
| Paper | Hendrycks et al. 2020 — Measuring Massive Multitask Language Understanding (MMLU) |
| Paper | Liang et al. 2022 — Holistic Evaluation of Language Models (HELM); Srivastava et al. 2022 — BIG-Bench; Suzgun et al. 2022 — BIG-Bench Hard |
| In-app | P10 — the Transformers pillar, for the contextual embeddings BERTScore is built on (attention, encoder blocks, Sentence Embeddings) |
| In-app | P13 — Production ML & MLOps, for evaluation infrastructure: harnesses, regression suites, and eval-in-CI |
Ask the mentor about this module
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
Keeping your files on this device
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
Try it yourself
A scratch console for this page's ideas — ungraded, nothing you run here is recorded.
Scratch console
A scratch console with the scientific stack (pandas, numpy, scikit-learn). Runs on the server — no network, resource-limited and measured.
Output appears here.
My notes on this module
Loading your notes...
Where next?
This module unlocks
Go up a level