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.

Step 1 / 4Beyond Classical Metrics — BERTScore and Semantic Similarity

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:

HypothesisReferenceBLEU-1Semantic equivalenceBLEU 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:

  1. Embed all m hypothesis tokens and all n reference tokens with a pretrained BERT-style model.
  2. Precision: for each hypothesis token, take its maximum cosine similarity to any reference token:
    PBERT=1mj=1mmaxicos(r^j,ri)P_{\text{BERT}} = \frac{1}{m} \sum_{j=1}^{m} \max_{i} \cos(\hat{r}_j, r_i)
  3. Recall: for each reference token, take its maximum cosine similarity to any hypothesis token:
    RBERT=1ni=1nmaxjcos(ri,r^j)R_{\text{BERT}} = \frac{1}{n} \sum_{i=1}^{n} \max_{j} \cos(r_i, \hat{r}_j)
  4. 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):

adogsprinted
a1.000.400.30
canine0.400.920.55
ran0.300.450.88
fast0.250.350.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.

TypeResource
PaperZhang 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)
PaperHendrycks et al. 2020 — Measuring Massive Multitask Language Understanding (MMLU)
PaperLiang et al. 2022 — Holistic Evaluation of Language Models (HELM); Srivastava et al. 2022 — BIG-Bench; Suzgun et al. 2022 — BIG-Bench Hard
In-appP10 — the Transformers pillar, for the contextual embeddings BERTScore is built on (attention, encoder blocks, Sentence Embeddings)
In-appP13 — 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.

Ctrl/Cmd + Enter to send

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.