A judge that favours the first answer by 10 points crowns the worse model, with a tight error bar. Randomize the order and the truth comes back.
Press Run 2,000 battles with the order fixed. Then switch to random order and run again. Then we build, piece by piece, the instruments that turn taste into a number you can defend: perplexity, pass@k, Bradley-Terry, judge calibration, FID, caption metrics and kappa.
You need a little Python and what a probability is. We build the rest from zero. It helps to have met Metric Design.
Illustrative simulation. Model A truly wins 55% of battles. The judge adds the bias to whichever answer it reads first. The band is a 95% interval from the normal approximation.
Chapter 0
See why scoring a generated poem is a measurement problem, and why the order of two answers can decide the winner
Two models write a poem about frost. You read both and pick one. Now swap which poem you read first. Would you pick the same one? Many readers would not. That habit is the problem this lesson solves.
A classifier has an answer key: the label "dog" is right or wrong. A generative model writes a poem, a caption, an image or a program. There is no single right output, so there is no key. Evaluation becomes a measurement of preference, and every rater, human or model, has habits.
Ten raters vote between two poems of equal quality. Each rater leans toward the poem read first. Pick a seating, then run one panel or a thousand.
Illustrative. A fair rater picks A half the time; the bias adds to the first seat. A wins the panel with 6 or more of 10 votes.
With made-up numbers: the poems are equal, so a fair rater picks A with chance 0.50. Each rater adds 15 points to the first seat. Seat A first and each vote goes to A with chance 0.65. A wins a majority in 75.1% of panels. Seat A second and the chance drops to 9.5%. Same poems, opposite verdicts.
The fix is a coin per rater. Half see A first and half see it second:
0.5 × 0.65 + 0.5 × 0.35 = 0.50
The plus 15 and the minus 15 cancel. Nobody had to estimate the bias.
Bias is an error that points the same way every time. Variance is an error that wobbles around the truth. More raters shrink variance and leave bias alone: with A always first, a thousand raters converge on 0.65 with great confidence. So fix bias by design first. Then buy variance down with samples.
Every problem in this lesson routes into one of three families, by the evidence you have:
| You have | Family | Instrument | Chapter |
|---|---|---|---|
| A verifier (unit tests) | Execution | pass@k | 2 |
| Only pairwise votes | Preference | Bradley-Terry, a calibrated judge, kappa | 3, 4, 7 |
| Only samples | Distribution match | FID, precision and recall | 5 |
Failure. The symptom: a 58 to 42 preference win that no one can reproduce. Split the win rate by which answer came first. Fix: randomize the order of every vote and hide every cue of who wrote what.
Chapter 1
Compute perplexity by hand, then find the three things it cannot see: samples, diversity and memorization
Here is a score that seems to dodge taste. Ask the model how likely it finds good human text. A model that finds good text likely must be a good model. Then why does the single most likely continuation so often read as dull?
A language model gives a probability to each next token. Feed it a held-out sentence of N tokens. Call the probability it gave the true token at position t pt. Perplexity turns those probabilities into one number: how many equally likely tokens the model behaves as if it chooses from.
P-P-L equals e to the power of minus one over N, times the sum over t of the log of p-t.
Take the log of each p-t. Average the logs over the N tokens. Flip the sign and raise e to that power. The result is PPL.
With made-up numbers: five tokens get p-t of 0.5, 0.25, 0.5, 0.125 and 0.25. The logs sum to −6.238; divide by N = 5 to get −1.248. PPL = e1.248 = 3.48. The model hesitates as if among about three and a half tokens.
Blue dots are real data. Teal dots are the model's samples. Move the slider from collapse to spray and watch fidelity and coverage trade places. Then press Memorize.
Illustrative 2-D toy. A sample counts toward fidelity if a real point lies within a fixed radius; a real point counts toward coverage if a sample lies within it. Chapter 5 meets the published version of this idea.
Memorization also hides inside benchmarks. If test items leaked into the training data, a high score measures storage. A common check flags a test item when a run of 13 words also appears in the training data. A 40-word item holds 40 − 13 + 1 = 28 such runs to look up.
Failure. The symptom: the new model has lower perplexity, but people prefer the old model's answers. Measure three things: sweep the decoding settings, check test and training text for overlap, and grade samples with a rubric. Fix: keep perplexity as a cheap alarm for regressions, and gate releases on samples. For how low diversity looks across real models, see Mode Collapse.
Chapter 2
Derive the chance that one of k tries passes, see why the obvious estimate runs low, and count subsets to fix it
Code brings an answer key back: a function passes its unit tests or it does not. But each call gives a different program. If the model tries k times, what is the chance that at least one try passes? That is pass@k.
Call the chance that one try passes p, and the number of tries k.
pass-at-k equals one minus, one minus p, to the power k.
Take the chance that one try fails, 1 minus p. Multiply it by itself k times to get the chance that every try fails. Subtract that from 1.
With made-up numbers: p = 0.3 and k = 5. All five fail with chance 0.75 = 0.168, so pass@5 = 0.832. A 30% coder passes 83% of the time with five tries.
We never know p. We draw n samples and count c that pass. The obvious move puts c/n in place of p. Chen et al. (2021) show that this plug-in estimate runs low: the curve bends downward, so its average over noisy guesses sits under the truth.
The fix: any k of the n samples form a fair k-try experiment. Name the number of ways to choose b things from a things C(a, b), said "a choose b".
pass-at-k hat equals one minus, n minus c choose k, over n choose k.
Count the groups of k that hold only failures. Divide by all groups of k. That is the chance a random group has no pass. Subtract it from 1.
With made-up numbers: n = 10 samples, c = 3 pass, k = 5. C(7, 5) = 21 and C(10, 5) = 252. pass@5 = 1 − 21/252 = 0.917.
The top row is one draw of 10 samples. The chart shows pass@k for k from 1 to 10: the truth (blue, dashed), the plug-in average (purple), the subset estimator average (green). Move p and k.
The averages are exact expectations over c drawn from a binomial with n = 10. The estimator and its bias come from Chen et al. (2021), Appendix A.
At p = 0.3, n = 10, k = 5 the plug-in averages 0.760 against a truth of 0.832: 7.2 points low. The subset estimator averages 0.832. Edge cases: c = 0 gives 0; fewer than k failures gives 1; k = 1 gives c/n.
pythonimport numpy as np def pass_at_k(n, c, k): # Chen et al. (2021), Figure 3 if n - c < k: return 1.0 # every group of k holds a pass return 1.0 - np.prod(1.0 - k / np.arange(n - c + 1, n + 1)) print(pass_at_k(10, 3, 5)) # 0.9167, no giant factorials
Failure. The symptom: pass@10 from n = 10 samples, so each problem gives one 0 or 1. Measure n against the largest k. Fix: draw n well above k; the Codex paper used n = 200 for k up to 100. Report pass@1 too, and fix the temperature.
Chapter 3
Fit one strength per model from pairwise votes, read it on the Elo scale, and put an error bar on it
You hold thousands of A-versus-B votes across ten models. A raw win rate is unfair: a model that met only weak rivals looks great.
Give model i a positive strength si. The Bradley-Terry model (1952) gives i a win chance equal to its share of the two strengths.
The probability that i beats j equals s-i over s-i plus s-j.
Add the two strengths. Model i wins its share, s-i out of the total s-i plus s-j.
With the fitted toy below: s-A = 0.597 and s-B = 0.245. P(A beats B) = 0.597 / 0.842 = 0.709. The votes said 7 of 10.
Toy votes: A beat B 7 of 10, A beat C 8 of 10, B beat C 6 of 10. The fitting loop:
One pass gives 0.50, 0.30, 0.20. The loop settles at 0.597, 0.245, 0.158. Leaderboards print 400 × log10(si/sC), the chess Elo scale. On it, 400 points means 10 to 1 odds: A +231, B +77, C 0.
Each row is a pair of models. Change who won how often, then press Fit. Bootstrap resamples the battles 200 times and draws each model's band. Fewer battles, wider bands.
Battles per pair scales the counts from 10 to 200 at the same win shares. Bands span the middle 95% of 200 refits. A perfect record gets half a virtual win each way.
Chess updates ratings after each game. Call them RA and RB. A's expected score is EA = 1/(1 + 10(RB − RA)/400). Call the real result S (1 for a win, 0 for a loss) and the step size K.
R-A prime equals R-A plus K times, S minus E-A.
Subtract the predicted score E-A from the result S. That is the surprise. Move R-A by K times the surprise.
With made-up numbers: R-A = 1200, R-B = 1000, so E-A = 1/(1 + 10−0.5) = 0.760. A loses, S = 0. R-A′ = 1200 + 32 × (0 − 0.760) = 1175.7, and B rises to 1024.3. An upset costs A 24 points.
Elo depends on the order of the battles. A frozen model does not drift, so order noise is pure error. The Chatbot Arena paper (Chiang et al., 2024) moved from Elo to Bradley-Terry, fitted on all battles at once.
Failure. The symptom: a team announces a lead of 7 Elo points. That gap is a 51.0% chance to win. A 7 of 10 record has a standard error of √(0.7 × 0.3 / 10) = 0.145. Fix: report intervals and call overlaps a tie.
Chapter 4
Measure a judge model's position, length and self-preference habits with one designed experiment each, then cancel them
Human votes cost dollars and days. A judge, a language model that picks the better of two answers, costs cents and seconds. Zheng et al. (2023) found that strong judges such as GPT-4 agree with human preferences over 80% of the time. Humans agree with each other at the same level. The paper also named three habits.
| Habit | The experiment that isolates it | The fix |
|---|---|---|
| Position: the first seat wins | Judge each pair twice, with the seats swapped | Average both orders, or randomize the order |
| Verbosity: the longer answer wins | The same content at two lengths | Length control: fit the effect of length, report at equal length |
| Self-preference: its own family wins | Hide authors; compare with judges from other families | Never let a judge grade its own family; use a jury |
Length-Controlled AlpacaEval (Dubois et al., 2024) fits the judge's preference with the length gap as one input. Then it predicts the preference at a gap of zero. That raised its rank agreement with Chatbot Arena from 0.94 to 0.98.
Judge 100 pairs twice. Call A's win rate when A sits first w1, and when A sits second w2. A position tilt adds to one and subtracts from the other.
w equals w-one plus w-two, over two.
Add w-one and w-two and halve the sum. The tilt rides up in one and down in the other, so it drops out. Half the gap between them is the tilt itself.
With made-up numbers: w-one = 0.60 and w-two = 0.44. w = 1.04 / 2 = 0.52. The tilt is (0.60 − 0.44)/2 = 0.08: the first seat buys 8 points.
Plant a hidden tilt and a true preference. Press the button to judge 100 pairs in both orders. The four boxes sort the pairs; the read-out recovers the tilt you planted.
Illustrative judge. Each pair gets its own true chance that A is better, spread around the true rate; the tilt adds to the first seat. The worked numbers use one fixed outcome: 40, 20, 4 and 36 pairs.
Read the four boxes with the right test. The 20 + 4 pairs that flipped test the seat: 20 against 4 is an exact binomial p of 0.0015, so the tilt is real. The pairs that did not flip test the models: A won 40, B won 36, p = 0.73. There is no evidence that A is better. The flip rate, 24 of 100, says a quarter of the verdicts came from the seat.
Failure. The symptom: "A wins 60%" from a judge that always saw A first. Measure the win rate split by seat. Fix: judge both orders or randomize, and accept a judge only if its agreement with humans reaches the human-human level. Why a judge can agree and still miss real disagreement: Mode Collapse.
Chapter 5
Embed real and generated images, fit a mean and a spread to each cloud, and compute the distance by hand
For images there are two piles of pictures: real and generated. A good model's pile matches the real pile in content and in variety. How far apart are the piles?
Pixels are a bad ruler, so embed each image with a fixed network. The Fréchet Inception Distance (FID, Heusel et al., 2017) uses the 2,048 features of Inception-v3's last pooling layer. Each pile becomes a cloud of points. Fit each cloud with its mean (the centre) and its covariance (the spread and tilt). Call them μr, Σr for real and μg, Σg for generated.
F-I-D equals the squared distance between mu-r and mu-g, plus the trace of: sigma-r plus sigma-g, minus two times the square root of sigma-r times sigma-g.
Square the distance between mu-r and mu-g. Then compare the spreads: when the features are independent, each feature adds (real standard deviation minus generated standard deviation) squared. Add the two terms.
With made-up 2-D numbers: mu-r = (0, 0), mu-g = (1, 1), so the mean term is 1 + 1 = 2. Real standard deviations are 1 and 1; generated ones are 2 and 1. The trace term is (1 − 2)2 + (1 − 1)2 = 1. FID = 3.
Blue is the real cloud, teal the generated one, each drawn with its one and two spread rings. The bar stacks the mean term and the trace term. Try the presets.
A 2-D toy with independent features, so the matrix square root is the square root of each spread squared. Real image FID uses 2,048 features and a full matrix square root.
If the model collapses to one image, its spread goes to zero. The trace term then climbs to the real cloud's total spread, 2 here: the missing variety is the penalty. If features move together, use the full matrix square root. With Σg = [[2, 0.6], [0.6, 1]], scipy's sqrtm gives FID = 2.284.
Neighbours: the Inception Score (Salimans et al., 2016) never looks at real data, so FID replaced it. Precision and recall for generative models (Kynkäänniemi et al., 2019) split FID's one number into Chapter 1's fidelity and coverage. CLIPScore (Hessel et al., 2021) checks whether an image matches its prompt, which FID never asks.
Failure. The symptom: team A reports FID 8.2 on 10,000 samples, team B 9.1 on 50,000. Small sample counts push FID up, so the comparison is void. Fix: recompute both at one count (50,000 is common) with one resize code; Parmar et al. (2022) show resizing alone moves FID. Chong and Forsyth (2020) show the bias also differs by model.
Chapter 6
Give partial credit against many right answers, see how overlap metrics get fooled, and probe for objects that are not there
Ask ten people to describe a photo. You get ten different sentences, most of them right. "A man riding a horse on a beach" and "a rider on horseback by the sea" share almost no words. Exact match fails at once, so every metric for a vision-language model (VLM) is a scheme for partial credit.
VQA accuracy (Antol et al., 2015) collects 10 human answers per question. A model's answer scores the number of humans who gave it, divided by 3, capped at 1. Three matches earn full credit. The official score averages this over the 10 ways to leave one human out. With made-up numbers: 2 of 10 humans said "yellow". The simple rule gives 2/3 = 0.67; the official average gives 0.60.
BLEU counts shared word runs (n-grams). Candidate "the cat sat on the mat", reference "the cat is on the mat":
The scene is a rider on a beach. Pick a candidate. Matched words glow; clipped repeats turn red. BLEU-2 updates. Find the candidate that is right but scores low.
BLEU-2 computed live: clipped counts take the most any one reference allows; the brevity penalty uses the closest reference length. We made up the captions.
| Metric | What it fixes | What it breaks |
|---|---|---|
| BLEU | Exact match: gives partial credit | Synonyms score zero; generic captions farm credit |
| CIDEr (Vedantam et al., 2015) | Weighs rare shared phrases above common ones (TF-IDF) | Scores depend on the reference corpus |
| SPICE (Anderson et al., 2016) | Compares objects, attributes and relations, so synonyms can match | Inherits every error of its parser |
No overlap metric checks that the caption is true of this image. POPE (Li et al., 2023) asks "Is there a <object> in the image?" for present and absent objects at a 1 to 1 ratio. The absent objects come at random, by popularity, or by how often they appear with the objects present. With made-up numbers: 50 present and 50 absent probes; the model says yes to 45 and 15. Precision 45/60 = 0.75, recall 45/50 = 0.90, F1 = 0.82. Its yes ratio is 0.60 on a set where the truth is 0.50: it says yes 10 points too often.
Failure. The symptom: a caption score rises after fine-tuning while users report more invented details. Measure with grounding probes: POPE, or CHAIR (Rohrbach et al., 2018), the share of mentioned objects that are absent. Fix: pair every overlap metric with a grounding metric.
Chapter 7
Subtract the agreement that luck gives for free, find the ceiling for any judge, and design a human study that earns trust
We check every judge and metric against humans. So who checks the humans? Two raters agree on 70% of items. That sounds decent until you count how much agreement luck hands out.
Two raters who each say "acceptable" 90% of the time agree 0.9 × 0.9 + 0.1 × 0.1 = 82% of the time without reading a word. Call the share of items where the raters match the observed agreement po. Call the match rate expected from their base rates alone the chance agreement pe. Cohen's kappa keeps only what they earned above luck.
Kappa equals p-o minus p-e, over one minus p-e.
Subtract the free agreement p-e from the observed p-o. Divide by the room there was above luck, 1 minus p-e. Kappa is the share of that room the raters filled.
With made-up numbers: of 100 answers, both say acceptable 40, both say not 30, they split 20 and 10. p-o = 0.70. Rater 1 says acceptable 60%, rater 2 says 50%, so p-e = 0.6 × 0.5 + 0.4 × 0.5 = 0.50. Kappa = 0.20 / 0.50 = 0.40.
The grid counts 100 answers by what each rater said. The ghost number in each cell is what chance alone would put there. Try the presets: both have 86% raw agreement.
Illustrative counts. "Both not acceptable" is what remains of the 100. A slider stops when the four cells reach 100.
The two presets show the kappa paradox. Both have po = 0.86. With balanced base rates pe = 0.50 and kappa is 0.72. When both raters say acceptable 90% of the time, pe = 0.82 and kappa drops to 0.22. Same raw agreement, a third of the kappa.
Human-human kappa is a ceiling. A judge cannot agree with humans more than humans agree with each other. So report the ratio: with made-up numbers, judge-human kappa 0.42 over human-human 0.45 is 93% of the ceiling. For 3 or more raters use Fleiss' kappa; for ordered scales a weighted kappa; for missing labels Krippendorff's alpha.
A protocol that earns that trust:
With made-up prices: 1,000 pairs × 3 raters × $0.50 = $1,500 and days of waiting, against 2,000 judge calls at $0.002 = $4. Spend the human budget on the ceiling and on audits of the judge.
Failure. The symptom: a pilot kappa of 0.2. Measure which items split the raters. Fix: treat it as a rubric bug, not a rater bug, and rewrite the anchors.
Chapter 8
Corrupt a judge three ways, watch a confident wrong verdict, repair it by design, and only then size the sample
This lab knows the truth: model A beats model B on 55% of prompts. The judge has three habits from Chapter 4. It adds b to the first seat. It adds γ to the longer answer, and B writes longer. It adds s to its own family, and B shares the judge's family.
Purple dials corrupt the judge. Green switches repair the pipeline. The bar shows A's measured win rate with its 95% band, against the truth (blue) and a tie (grey). It starts as the worked case: position bias only. Then raise length and self.
Illustrative. The bias terms add to the chance that the judge picks A. Length control and the other-family judge remove their term entirely, which real fixes do only roughly. The band uses the normal approximation.
Start with every repair off and only b = 10 points. A always sits second, the accident of sorting runs by name. The judge measures 0.55 − 0.10 = 0.45, and B tops the board. The ranking flips for any b above 0.05, the true margin. At 5,000 battles the band is 1.96 × √(0.45 × 0.55 / 5000) = ±0.014, so [0.436, 0.464] excludes 0.5. More data made the wrong answer look firmer.
Now repair by design, in order. A coin per battle gives 0.5(0.55 + b) + 0.5(0.55 − b) = 0.55 for any b. Length control removes γ. A judge from another family removes s. The swap audit catches the first habit before any of this: it costs two judgments on a few hundred pairs.
With bias handled, how many battles separate 0.55 from 0.50? Call the margin you must resolve m, the win rate p, and the 95% multiplier z.
n equals z squared times p times one minus p, over m squared.
Multiply z squared by the noise of one battle, p times 1 minus p. Divide by the margin m squared. Round up.
With m = 0.05, p = 0.5 and z = 1.96: n = 3.8416 × 0.25 / 0.0025 = 384.2, so 385 battles. A 10-point Elo gap is a 51.4% win chance, m = 0.0144, and n is about 4,640.
That is why public arenas need hundreds of thousands of votes. Chatbot Arena reported over 240,000 by early 2024 (Chiang et al., 2024). In August 2024 it added a style control: answer length and markdown counts enter the Bradley-Terry fit as extra inputs. Strength is then read apart from style.
Chapter 9
Keep every instrument, its trap and the audit order on one page
Every number in generative evaluation needs three things: an estimator, the bias that estimator carries, and an error bar. Check the verifier first, then preferences, then distributions. Fix bias by design before you buy samples.
| Instrument | Formula, in words | Use when | Main trap |
|---|---|---|---|
| Perplexity | e to the minus average log probability of the true tokens | A cheap alarm for regressions | Never reads samples; memorizers win |
| pass@k | 1 minus (n minus c choose k) over (n choose k) | A verifier exists | The plug-in runs low; n too close to k |
| Bradley-Terry | P(i beats j) = s-i over (s-i plus s-j) | Pairwise votes become a ranking | Gaps inside the error bars |
| Elo scale | 400 times log base 10 of a strength ratio | Readable leaderboard units | Online updates depend on order |
| Order-free win rate | (w-one plus w-two) over 2 | Any pairwise judge | One seating only |
| FID | squared mean gap plus the trace of the spread mismatch | Only samples; fidelity and variety at once | Sample count, resize code, feature network |
| VQA accuracy | matching humans over 3, capped at 1 | 10 human answers per question | Answer priors such as "yes" |
| BLEU-2 | brevity penalty times the geometric mean of p1 and p2 | A baseline for overlap | Blind to synonyms and to truth |
| Cohen's kappa | (p-o minus p-e) over (1 minus p-e) | Two raters, labels with no order | Skewed base rates |
| Sample size | z squared times p(1 minus p) over m squared | After bias is handled | Tiny margins need huge n |
pythonimport numpy as np def bt_fit(wins, iters=2000): # wins[i][j] = times i beat j, a square array n = wins + wins.T; s = np.ones(len(wins)) / len(wins) for _ in range(iters): den = (n / (s[:, None] + s[None, :])).sum(1) s = wins.sum(1) / den; s /= s.sum() return s # [0.597 0.245 0.158] for the toy def order_free(v_first, v_second): # 1 if the judge picked A, per pair return (v_first.mean() + v_second.mean()) / 2, (v_first != v_second).mean() def kappa(a, b, c, d): # both yes, only 1 yes, only 2 yes, both no n = a + b + c + d; po = (a + d) / n r1, r2 = (a + b) / n, (a + c) / n pe = r1 * r2 + (1 - r1) * (1 - r2) return (po - pe) / (1 - pe) # 0.40 for 40, 20, 10, 30 print(bt_fit(np.array([[0,7,8],[3,0,6],[2,4,0]], float)).round(3), kappa(40, 20, 10, 30))
| Lesson | What it adds |
|---|---|
| Metric Design | What to measure before you estimate it |
| The Statistics of Evaluation | Intervals, the bootstrap and power in depth |
| Plots That Tell the Truth | How to draw pass@k curves and rating bands honestly |
| Experiment Design | Preference data from live A/B tests |
| Regression Testing for ML | These metrics as release gates |
| The Metrics Ladder | From model metrics up to product metrics |
| AI Evaluation | The harness: datasets, suites, judge deployment |
| Agent Evaluation | Benchmarks and grading for agents |
| CS336 L12: Evaluation | Perplexity details and contamination |
| Mode Collapse | Low diversity across models, and judges that miss human disagreement |
| Calibration | When to trust a model's stated confidence |
| CLIP | The embeddings behind CLIPScore |
| Diffusion and VLMs | What the scored models do inside |
Now press Present or Teach and explain from memory: why order bias needs a design fix, the subset count behind pass@k, how a strength becomes an Elo number, and what kappa subtracts. Then go back to the hero and run the biased judge again. This time say which repair moved the verdict and why.