34

Evaluating AI systems

How do you check that an AI system works for your case?

12 minExecutive path

Evaluating AI systems

With voice. You can pause and jump to any step.

Lesson complete

Subtitles

A vendor shows you that its model got the top score on a famous public exam. Sounds good. But the question that matters is a different one: does it work for your case?

Voice

No voice: the lesson advances on its own with subtitles.

The voice for this lesson is being recorded: for now it advances on its own with subtitles.

0:00 / 0:00

What you will achieve

  • Explain what a benchmark is and why its score can mislead: saturation and contamination.
  • Build an evaluation set from your own cases and choose how to grade it: with a program, a rubric, an LLM as judge, or people.
  • Interpret the margin of a score (its confidence interval) and predict how it changes with the number of cases when comparing two systems.

Key ideas

  1. A benchmark is a fixed public exam. It is useful for comparing models in general, but it saturates and can be contaminated: its score does not tell you whether the system works for your case.
  2. Your evaluation set is real cases from your work, with the answer your experts accept, that the system has not seen. Include the frequent, the exceptional, the risky, and what must be refused, and report by group: the average hides where it fails.
  3. A program grades closed answers; open ones need a rubric applied by people or by an LLM as judge. The judge scales, but it has biases (for example, the order of the answers): grade in both orders and check it against people.
  4. Every score carries a margin, its confidence interval: with a hundred cases, about eight points; four times as many cases give half. If two systems differ by less than the margin, it is a tie. Compare them on the same cases.
  5. Evaluating is a routine: a regression test after every change, red teaming to look for the worst case, and business metrics measured in a pilot.

What many people believe

Common belief “This model tops the public benchmarks, so it will be the best one for my organization.”

What is true A benchmark measures one specific exam, and its score can be inflated by contamination or no longer tell anyone apart because of saturation. Only an evaluation on your cases, which the system has not seen and which comes with its margin of error, tells you whether it works for your case.

Check yourself

Four questions. No grade, no account: they just show whether the idea stuck.

ConceptWhat is benchmark contamination?
ConceptAn LLM judge tends to prefer the answer shown first. What simple defense is used?
CalculationWith a hundred cases, a system’s score carries a margin of about eight points. About how many cases does it take to bring it down to about two?
ApplicationYou test two assistants on the same 150 cases from your operation: A scores 81% and B 79%, and B costs half as much. What do you do?

Under the hoodFor those who want the math and the code. You do not need it to follow the course.

The margin of a score

With kk right answers in nn cases, the measured accuracy is p^=k/n\hat p = k/n. Its approximate 95% confidence interval is

p^±1.96 p^ (1−p^)n.\hat p \pm 1.96\,\sqrt{\frac{\hat p\,(1-\hat p)}{n}}.

With 78 of 100: 0.78±1.960.78⋅0.22/100=0.78±0.0810.78 \pm 1.96\sqrt{0.78 \cdot 0.22/100} = 0.78 \pm 0.081, that is, from 70% to 86% (what the scene uses). With 400 cases, ±0.041\pm 0.041. The margin goes with 1/n1/\sqrt n: quadrupling the cases halves it, and in the worst case (p^=0.5\hat p = 0.5) it is almost exactly 1/n1/\sqrt n: 10 points with 100 cases, 5 with 400, 2.5 with 1,600.

The correct reading: if you repeated the evaluation many times with fresh cases, about 95% of the intervals built this way would contain the true accuracy. With few cases, or scores near 0% or 100%, this formula falls short; Brown, Cai, and DasGupta (2001) recommend the Wilson interval, which for 78 of 100 gives 68.9% to 85.0%. Bowyer, Aitchison, and Ivanova (2025) show that with fewer than a few hundred cases, margins based on the normal approximation tend to come out too small.

Comparing two systems on the same cases

For each case ii, let di=ai−bi∈{−1,0,+1}d_i = a_i - b_i \in \{-1, 0, +1\} (A's hit minus B's hit). If only A is right on n10n_{10} cases and only B on n01n_{01}, the measured difference is dˉ=(n10−n01)/n\bar d = (n_{10}-n_{01})/n and its standard error is

SE(dˉ)=(n10+n01)/n−dˉ 2n−1,dˉ±1.96 SE.\mathrm{SE}(\bar d) = \sqrt{\frac{(n_{10}+n_{01})/n - \bar d^{\,2}}{n-1}}, \qquad \bar d \pm 1.96\,\mathrm{SE}.

In the lesson's simulation, on each case both are right with probability 0.66, only A 0.12, only B 0.08, and neither 0.14. The variance of did_i is 0.12+0.08−0.042=0.1980.12 + 0.08 - 0.04^2 = 0.198; if each system were tested on different cases, their variances would add up, 0.78⋅0.22+0.74⋅0.26=0.3640.78\cdot0.22 + 0.74\cdot0.26 = 0.364: almost double. That is why, with the same cases, you need almost half as many.

The exact probability that A comes out ahead (from the multinomial distribution) is 78.5% with 100 cases, 88.4% with 200, 95.9% with 400, and 99.75% with 1,000; the scene's 100 comparisons give 78, 88, 96, and 100. With different cases, 400 cases give about 90%, and it takes about 650 to reach 95%; with the same cases, about 360 are enough. A winning is not the same as proving the difference: for the interval of dˉ\bar d to exclude zero 80% of the time takes n≈(1.96+0.84)2⋅0.198/0.042≈970n \approx (1.96 + 0.84)^2 \cdot 0.198/0.04^2 \approx 970 cases.

Miller (2024) sums up the craft: report standard errors, compare in pairs (case by case), cluster cases that are not independent (for example, several questions about the same document), and plan the sample size before evaluating.

Contamination: the example's arithmetic

If a model always gets right what it saw, solves a fraction aa of the rest, and saw a fraction cc of the exam, its score is

score=c+(1−c) a.\text{score} = c + (1-c)\,a.

With a=0.70a = 0.70: c=0.2c = 0.2 gives 0.2+0.8⋅0.7=0.760.2 + 0.8 \cdot 0.7 = 0.76, the same as B, and c=0.4c = 0.4 gives 0.820.82. It is a simplified model: real memory is partial. Contamination is searched for with text matches between the exam and the corpus (the GPT-4 report used three 50-character substrings per question; that is how it found that part of BIG-bench had slipped into training by accident, and it estimated that a quarter of HumanEval was in its data), with equivalent fresh problems, or by measuring how much probability the model assigns to the exam's questions. GSM1k (Zhang et al., 2024) is 1,205 problems written by people in the style of GSM8k: some model families dropped by up to 8 points, with bigger drops the more likely the model was to generate GSM8k examples; frontier models barely dropped.

The automatic judge

Zheng et al. (2023) compared GPT-4 as a judge with human experts on MT-bench: not counting ties, they agreed 85% of the time, more than the experts with each other (81%). They also measured its biases. Order: with two nearly identical answers, the verdict held when the order was swapped 65.0% of the time with GPT-4, 46.2% with GPT-3.5, and 23.8% with Claude-v1. Length: when 23 answers were padded with a repeated list that added no information, Claude-v1 and GPT-3.5 preferred the padded version in 21 of 23 (91.3%), and GPT-4 in 2 (8.7%). Their defense against order bias: grade twice, swapping the order, and declare an answer the winner only if it wins both times.

To measure agreement with people without being fooled by chance, Cohen's κ\kappa is used: κ=(po−pe)/(1−pe)\kappa = (p_o - p_e)/(1 - p_e), where pop_o is the observed agreement and pep_e the agreement expected by chance. Human evaluation is also done at scale: Chatbot Arena gathered over 240,000 votes from people comparing answers blind (Chiang et al., 2024), but on questions that are not yours.

Scores expire, and exams have flaws too

Chen, Zaharia, and Zou (2023) measured the same service in March and in June 2023 with 500 prime and 500 composite numbers: GPT-4 went from 84.0% to 51.1%, because the June version almost always answered “composite” (99.7%) and stopped following the step-by-step reasoning it was asked for. It is a change in behavior more than in ability, but for anyone who depends on the service the effect is the same, and you only notice by measuring again.

Exams contain errors: Gema et al. (2024) estimate that 6.49% of MMLU questions have one (57% of those reviewed in virology). And they run out: Phan et al. (2025) built a new 2,500-question exam because the best models already scored above 90% on MMLU.

In code

import numpy as np

def margin(k, n, z=1.96):
    """Half the 95% confidence interval for k right answers out of n cases."""
    p = k / n
    return z * np.sqrt(p * (1 - p) / n)

for n in (100, 400, 1600):
    print(n, round(100 * margin(0.78 * n, n), 1))
# 100 8.1
# 400 4.1
# 1600 2.0

# Two systems on the same cases: both right 0.66; only A, 0.12; only B, 0.08; neither, 0.14
rng = np.random.default_rng(0)
def a_ahead(n, reps=20000):
    c = rng.multinomial(n, [0.66, 0.12, 0.08, 0.14], size=reps)   # both, only A, only B, neither
    return round(float(np.mean(c[:, 1] > c[:, 2])), 2)

for n in (100, 200, 400, 1000):
    print(n, a_ahead(n))
# 100 0.78
# 200 0.88
# 400 0.96
# 1000 1.0

What comes next

Measured quality is one axis; risk is another: privacy, manipulation through instructions, bias, and regulation. Lesson 35 walks through them, and lesson 36 uses this evaluation inside a pilot that scales.

Decision lens

What this idea means if your job is to decide, not to code.

  • Before buying, ask for the full evidence behind each figure: which exam, with what instructions, which model version, on what date, and how contamination was ruled out. Without that, two figures cannot be compared.
  • Evaluate with your data: a few hundred real, anonymized cases, with the answer your experts accept, that the vendor has not seen. Include the frequent, the exceptional, the risky, and what must be refused, and ask for results by group.
  • Demand the margin of every score. If two systems differ by less than the margin, treat them as a tie and decide on cost, speed, and risk. If an LLM judge does the grading, ask how often it agrees with people and whether it graded in both orders.
  • Make evaluation a routine: rerun it after every change of model, instructions, or data; have a team attack the system before launch; and decide in advance which business result justifies going on, measured in a pilot.

Terms in this lesson

Full transcript
CommentsThis lesson’s public conversation: questions, facts to check, ideas.

Comments live in GitHub Discussions, in the course’s public repository; writing one requires a GitHub account. They load from giscus.app when you open this section. The course reviewers read them, and if a change is accepted, it is applied in both languages. Open the thread on GitHub

Sources