LLM & Generation Evaluation
P5.evaluation.03 · Audience: guest, it-ml, language-pro · Prerequisites: Embedding Evaluation
Modern evaluation methods for large language models — embedding-based metrics, benchmark frameworks, LLM-as-judge methodology, and human annotation protocols. Classical metrics (precision/recall/F1, BLEU, ROUGE) are assumed known from P5.evaluation.01; the contextual embeddings that power BERTScore are the ones built in the P10 Transformers pillar. This module closes the evaluation track.
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.
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.
Where next?
This module unlocks
Go up a level