10 Evaluation 2 / 6
  1. In this chapter
  2. LLM Evaluation Methodology
  3. The Statistics of Evaluation
  4. LLM-as-a-Judge
  5. Building Evaluation Sets
  6. Benchmark Contamination
  7. Production evaluation for LLMs
All chapters →

Chapter 10 · Evaluation 10.2

The Statistics of Evaluation: pass@k, Confidence Intervals and Sample Size

A benchmark score is an estimate from a finite set of questions and carries error. Learn the unbiased pass@k estimator, confidence intervals for accuracy, paired comparison of two models and how many questions detecting a gap takes, with runnable code and interactive widgets.

Intermediate 13 min read Updated Companion code ↓

After this page you will be able to

  • Write down the unbiased estimator of pass@k and implement it in code.
  • Compute a confidence interval for accuracy and say how large the error of a benchmark score is.
  • Compare two models with paired differences and decide whether the gap is significant.
  • Estimate how many questions it takes to detect a given gap.
On this page
  1. The metric for code evaluation: pass@k
  2. How large is the error in a score
  3. Comparing two models: use the paired difference
  4. How many questions it takes to detect a gap
  5. Practical advice
  6. Summary and exercises
  7. Exercises
  8. Further reading
  9. FAQ

A benchmark score is an estimate from a finite set of questions, not the true value of a model’s ability. This page answers three questions: how to estimate pass@k for code problems without bias, how large the error of an accuracy is, and when a gap between two models counts. All three expand on the question “how large is the error” from LLM Evaluation Methodology.

The metric for code evaluation: pass@k

Code problems can be graded automatically, but a model produces a different answer each time it samples. How should one problem be scored? HumanEval’s answer is pass@k: generate kk answers per problem, count the problem as solved if at least one of them passes all the tests, and take the average over problems as the benchmark score (Chen et al., 2021). With k=1k=1 it is the pass rate of a single sample; the larger kk is, the closer it gets to what the model can do when it is “given kk tries”.

Drawing exactly kk samples for each score has a large variance. The paper instead samples n≥kn \ge k answers per problem, counts the cc of them that pass the tests, uses the unbiased estimate below and averages over all problems:

pass@k=1N∑i=1N[ 1−(n−cik)(nk) ]\mathrm{pass@}k = \frac{1}{N}\sum_{i=1}^{N}\left[\,1 - \frac{\binom{n-c_i}{k}}{\binom{n}{k}}\,\right]

Here NN is the number of problems and cic_i is the number of passing samples for problem ii. The meaning: draw kk of the nn samples at random without replacement; the probability that all of them fail is (n−ck)/(nk)\binom{n-c}{k}/\binom{n}{k}, and subtracting it from 1 gives the probability that at least one passes. When n−c<kn-c<k the kk drawn samples must include a passing one, and the result is 1.

What not to do is estimate p^=c/n\hat p = c/n first and then compute 1−(1−p^)k1-(1-\hat p)^k. (1−p^)k(1-\hat p)^k is a convex function of p^\hat p, so by Jensen’s inequality its expectation is higher than (1−p)k(1-p)^k, which makes this estimate systematically too low. The bias grows as samples get fewer, so a run with more samples looks better than one with fewer (Chen et al., 2021, Appendix A).

from math import comb

def pass_at_k(n: int, c: int, k: int) -> float:
    """Unbiased estimate of pass@k for one problem: n samples drawn, c of them pass the tests."""
    if n - c < k:
        return 1.0
    return 1.0 - comb(n - c, k) / comb(n, k)

correct = [10, 7, 3, 1, 0]      # 5 problems, n=10 samples each, number of passing samples per problem
n = 10
for k in (1, 5, 10):
    exact = sum(pass_at_k(n, c, k) for c in correct) / len(correct)
    naive = sum(1 - (1 - c / n) ** k for c in correct) / len(correct)
    print(f"pass@{k:<2d} unbiased {exact:.4f}   naive {naive:.4f}")

# Output:
# pass@1  unbiased 0.4200   naive 0.4200
# pass@5  unbiased 0.6833   naive 0.6478
# pass@10 unbiased 0.8000   naive 0.7246

With 5 problems and 10 samples each, pass@1 is 42%, pass@5 rises to 68.3% and pass@10 to 80%; the last is simply the fraction of problems for which any of the 10 samples passes. At k=5k=5 the naive form gives 64.8%, about 3.5 points too low. For real numbers, compare Codex-12B on HumanEval: pass@1, pass@10 and pass@100 are 28.81%, 46.81% and 72.31% (Chen et al., 2021, Table 1).

Three things to remember when reading pass@k:

  • pass@1 measures how reliably the model is right on the first try; a large kk measures the ceiling when you can sample and verify. They answer different questions.
  • pass@k assumes an oracle that can tell right from wrong, which in the paper is the unit tests. Where there are no tests, picking one answer out of kk takes scoring, voting or reranking; the paper found that choosing the sample with the highest mean token log-probability beats picking at random.
  • Report nn, kk and the sampling temperature. A higher temperature gives more diverse samples and a better score at large kk; in the paper the best temperature for the 679M model is 0.2 for pass@1 and 0.8 for pass@100.

The widget below puts two things together. The top half estimates pass@k for a single problem from cc passing samples out of nn and compares it with the naive estimate; the bottom half looks at a whole benchmark in which problems differ in difficulty and shows how pass@k grows with kk.

How large is the error in a score

A benchmark’s questions are only one sample of all possible questions; change the questions and the score changes. Let the accuracy be pp and the number of questions nn, with each question scored right or wrong and independent of the others. The standard error and the 95% confidence interval of the score are

SE=p(1−p)n,p±1.96 SE\mathrm{SE}=\sqrt{\frac{p(1-p)}{n}},\qquad p \pm 1.96\,\mathrm{SE}

Take 80% accuracy and plug in the sizes of a few benchmarks: HumanEval’s 164 questions give ±6.1 percentage points, GSM8K’s 1,319 give ±2.2 and MMLU’s 14,079 give ±0.7. On a 164-question benchmark, two models 3 points apart are practically indistinguishable.

This formula covers only the error from sampling questions. When a model answers the same question several times, it can also be right sometimes and wrong at other times. Miller (2024) separates out that part of the variance and points out that sampling each question several times and averaging, or analyzing the next-token probabilities directly, can reduce it.

Comparing two models: use the paired difference

When comparing A and B, do not compute an interval for each and check whether they overlap. The two models answer the same questions, hard questions are easy for both to get wrong, and their outcomes are usually positively correlated. Let the per-question score difference be sA−sBs_A-s_B; the variance of the gap is

Var(μ^A−μ^B)=Var(sA)+Var(sB)−2 Cov(sA,sB)n\mathrm{Var}(\hat\mu_A-\hat\mu_B)=\frac{\mathrm{Var}(s_A)+\mathrm{Var}(s_B)-2\,\mathrm{Cov}(s_A,s_B)}{n}

When the covariance is positive, the variance is smaller than if the two models were treated as independent samples (Miller, 2024). The code below demonstrates this with simulated data: the two models share the question difficulty, and the correlation of their outcomes is about 0.5.

import numpy as np

rng = np.random.default_rng(2)
n = 164                                       # the number of HumanEval problems
difficulty = rng.normal(scale=3.0, size=n)    # problem difficulty, shared by both models

def answers(skill: float) -> np.ndarray:      # 1 = correct, 0 = wrong
    p = 1 / (1 + np.exp(-(skill - difficulty)))
    return (rng.random(n) < p).astype(float)

a, b = answers(3.0), answers(2.2)
diff = a - b

se_a = a.std(ddof=1) / np.sqrt(n)
se_unpaired = np.sqrt(a.var(ddof=1) / n + b.var(ddof=1) / n)
se_paired = diff.std(ddof=1) / np.sqrt(n)
print(f"A {a.mean():.3f} ± {1.96 * se_a:.3f}   B {b.mean():.3f}   correlation {np.corrcoef(a, b)[0, 1]:.2f}")
print(f"gap {diff.mean():+.3f}   95% half-width: unpaired {1.96 * se_unpaired:.3f}, paired {1.96 * se_paired:.3f}")
lo, hi = diff.mean() - 1.96 * se_unpaired, diff.mean() + 1.96 * se_unpaired
print(f"unpaired 95% interval [{lo:+.3f}, {hi:+.3f}]")
lo, hi = diff.mean() - 1.96 * se_paired, diff.mean() + 1.96 * se_paired
print(f"paired   95% interval [{lo:+.3f}, {hi:+.3f}]")

idx = rng.integers(0, n, size=(10000, n))     # bootstrap: resample problems, keeping both models' results on a problem together
boot = diff[idx].mean(axis=1)
print("paired bootstrap 95% interval:", np.percentile(boot, [2.5, 97.5]).round(3))

# Output:
# A 0.829 ± 0.058   B 0.756   correlation 0.50
# gap +0.073   95% half-width: unpaired 0.088, paired 0.062
# unpaired 95% interval [-0.014, +0.161]
# paired   95% interval [+0.011, +0.136]
# paired bootstrap 95% interval: [0.012 0.14 ]

On the same data, the unpaired interval of [−1.4, +16.1] percentage points contains 0, while the paired interval of [+1.1, +13.6] does not; a bootstrap that resamples the questions gives [1.2, 14.0], in line with the paired formula. This is a single simulation with a fixed random seed, and a different seed gives different numbers. It shows why pairing is more powerful, not that A is certainly better than B.

How many questions it takes to detect a gap

Conversely, to detect a real gap δ\delta you need enough questions. With significance α=0.05\alpha=0.05 and power 1−β=0.81-\beta=0.8, the number of questions needed is

n=(z1−α/2+z1−β)2 Var(sA−sB)δ2n=\frac{(z_{1-\alpha/2}+z_{1-\beta})^2\,\mathrm{Var}(s_A-s_B)}{\delta^2}

where z0.975≈1.96z_{0.975}\approx 1.96, z0.8≈0.84z_{0.8}\approx 0.84 and (1.96+0.84)2≈7.85(1.96+0.84)^2\approx 7.85. For two models that both score around 80%, with each question scored right or wrong, the results are:

GapPaired (correlation 0.5)Unpaired (correlation 0)
5 points548 questions1,091 questions
3 points1,472 questions2,940 questions
2 points3,256 questions6,507 questions
1 point12,792 questions25,580 questions

Halving the gap takes about four times as many questions, because nn is inversely proportional to δ2\delta^2. That is why arguing over 1 or 2 points on a benchmark of a few hundred questions is pointless.

from math import ceil, sqrt
from statistics import NormalDist

z = NormalDist().inv_cdf

def half_width(p: float, n: int, level: float = 0.95) -> float:
    """Half-width of the confidence interval when accuracy p is measured on n questions."""
    return z(0.5 + level / 2) * sqrt(p * (1 - p) / n)

def questions_needed(p_a: float, p_b: float, rho: float, alpha: float = 0.05, power: float = 0.80) -> int:
    """Questions needed to detect the gap p_a - p_b when two models answer the same questions.
    rho is the correlation between their right/wrong outcomes."""
    var = p_a * (1 - p_a) + p_b * (1 - p_b) - 2 * rho * sqrt(p_a * (1 - p_a) * p_b * (1 - p_b))
    return ceil((z(1 - alpha / 2) + z(power)) ** 2 * var / (p_a - p_b) ** 2)

for name, n in [("HumanEval", 164), ("GSM8K", 1319), ("MMLU", 14079)]:
    print(f"{name:9s} n={n:6d}  accuracy 80% ± {100 * half_width(0.8, n):.1f} points")
for gap in (5, 3, 2, 1):
    p_b = 0.80 - gap / 100
    print(f"{gap}-point gap: {questions_needed(0.80, p_b, 0.5):6d} questions at correlation 0.5, {questions_needed(0.80, p_b, 0.0):6d} at correlation 0")

# Output:
# HumanEval n=   164  accuracy 80% ± 6.1 points
# GSM8K     n=  1319  accuracy 80% ± 2.2 points
# MMLU      n= 14079  accuracy 80% ± 0.7 points
# 5-point gap:    548 questions at correlation 0.5,   1091 at correlation 0
# 3-point gap:   1472 questions at correlation 0.5,   2940 at correlation 0
# 2-point gap:   3256 questions at correlation 0.5,   6507 at correlation 0
# 1-point gap:  12792 questions at correlation 0.5,  25580 at correlation 0

All of this assumes the reference answers are right. When they are not, the number of questions needed grows by a further factor: 1.198 times for four-option questions with a label error rate of 6.49%; the derivation and the experiment are in Building Evaluation Sets.

The widget below puts these formulas together: choose the size of a benchmark, set the accuracy of two models and the correlation between them, and read off the confidence intervals, the probability that the measured ranking is right, and how many questions it takes to detect that gap.

Practical advice

Miller (2024) condenses this line of thought into five recommendations:

  1. Compute the standard error of the mean with the central limit theorem and report it with the score.
  2. When questions come in groups (for example several questions about the same passage), use clustered standard errors.
  3. Reduce variance by sampling each question repeatedly and by analyzing next-token probabilities.
  4. When comparing two models, draw statistical inference on the paired per-question differences.
  5. Use power analysis to judge whether an evaluation set can test the hypothesis you care about.

In day-to-day work, report the number of questions and the interval along with the score, and compare two versions with a paired analysis on the same questions. When the set is too small, admit that it cannot resolve small gaps, then decide whether to enlarge it or to switch to a more sensitive way of evaluating, such as averaging over several samples.

Summary and exercises

  • A benchmark score is an estimate from a finite set of questions; report the number of questions and a confidence interval with it.
  • Compute pass@k with the unbiased estimate 1−(n−ck)/(nk)1-\binom{n-c}{k}/\binom{n}{k}; do not extrapolate with 1−(1−c/n)k1-(1-c/n)^k.
  • Compare two models with a paired analysis. Detecting a 1-point gap takes over ten thousand questions, and a benchmark of a few hundred cannot resolve gaps within 2 points.

1. With n=10n=10 samples per problem, one problem has c=1c=1 passing sample. What is the unbiased estimate of pass@10 for this problem?

  • 10%
  • 65.1%
  • 100%
  • 0%

Drawing 10 of the 10 samples without replacement must include the one that passes, so the estimate is 1 (the branch n−c=9<k=10n-c=9<k=10 of the formula). 65.1% is what the naive form 1−(1−0.1)101-(1-0.1)^{10} gives, which is systematically too low.

2. On a 164-question benchmark, model A scores 80% and model B scores 77%. Which statement is the most accurate?

  • A is significantly better than B
  • The two cannot be told apart from this gap alone: each 95% interval is about ±6 points and the interval of the gap is about ±9 points
  • B is significantly better than A
  • The interval depends only on model size, not on the number of questions

The standard error is p(1−p)/n\sqrt{p(1-p)/n}. With only 164 questions the half-width at 80% accuracy is about 6.1 points; for an unpaired comparison the half-width of the gap is about 8.9 points, so a 3-point gap lies within the noise.

3. On the same questions, why does a paired analysis usually give a narrower interval than an unpaired one?

  • The two models’ outcomes are usually positively correlated, so the variance of the per-question difference is smaller
  • Pairing doubles the number of questions
  • Pairing raises the accuracy of both models
  • Pairing just changes the significance level from 5% to 10%

The variance of the gap is (Var(sA)+Var(sB)−2Cov(sA,sB))/n(\mathrm{Var}(s_A)+\mathrm{Var}(s_B)-2\mathrm{Cov}(s_A,s_B))/n; when the covariance is positive it is smaller than in the independent case.

4. Both models score around 80% on the same questions and the correlation of their outcomes is 0.5. About how many questions are needed to detect a 2-point gap with 5% significance and 80% power?

  • About 160
  • About 800
  • About 3,300
  • About 33,000

By the formula n=(z1−α/2+z1−β)2Var(sA−sB)/δ2n=(z_{1-\alpha/2}+z_{1-\beta})^2\mathrm{Var}(s_A-s_B)/\delta^2 it is 3,256 questions; unpaired it is about 6,507.

Exercises

  1. One problem is sampled n=20n=20 times and c=3c=3 samples pass the tests. Compute the unbiased and the naive estimates of pass@k for k=1,5,10k=1,5,10.
  2. An internal evaluation set has 500 questions; the old model scores 82% and the new one 85%, and the correlation between their outcomes is assumed to be 0.6. Is the 3-point improvement credible?
  3. Use the widget on this page: set the number of questions to 164, the two models’ accuracies to 78% and 75%, and the correlation to 0.5. What is the probability that the ranking is right? About how many questions does it take to raise it above 95%?
Reference answers
  1. The unbiased estimates are 0.1500, 0.6009 and 0.8947; the naive estimates are 0.1500, 0.5563 and 0.8031. For example at k=5k=5, 1−(175)/(205)=1−6188/15504≈0.60091-\binom{17}{5}/\binom{20}{5}=1-6188/15504\approx 0.6009, while 1−0.855≈0.55631-0.85^5\approx 0.5563, so the naive form is too low.
  2. Paired: Var=0.82×0.18+0.85×0.15−2×0.6×0.1476×0.1275≈0.1105\mathrm{Var}=0.82\times0.18+0.85\times0.15-2\times0.6\times\sqrt{0.1476\times0.1275}\approx 0.1105, standard error 0.1105/500≈0.0149\sqrt{0.1105/500}\approx 0.0149, 95% half-width about 2.9 points, z≈2.02z\approx 2.02, p≈0.044p\approx 0.044. That is just past the 5% line, so the evidence is weak. Unpaired: standard error about 0.0235, half-width about 4.6 points, z≈1.28z\approx 1.28, p≈0.20p\approx 0.20, not significant. The conclusion depends on the assumed correlation, so compute the paired difference directly from the real per-question results and confirm it on a larger evaluation set.
  3. The gap is 3 points and the paired standard error is about 3.3 points; if the true gap is 3 points, the probability that the measured ranking is right is about 81.8%. To raise it above 95% you need ∣δ∣/SE≥1.645|\delta|/\mathrm{SE}\ge 1.645, that is n≥1.6452×Var/δ2=1.6452×0.1797/0.032≈540n\ge 1.645^2\times\mathrm{Var}/\delta^2=1.645^2\times 0.1797/0.03^2\approx 540 questions; drag the question slider to between 500 and 600 to check.

Further reading

FAQ

How is pass@k computed, and why not use 1−(1−pass@1)^k?
If you sample n answers for a problem and c of them pass the tests, the unbiased estimate of pass@k for that problem is 1 − C(n−c, k) / C(n, k), averaged over all problems. Computing pass@1 first and extrapolating with 1 − (1 − c/n)^k is systematically too low. It is off by more when samples are few, and it makes a run with more samples per problem look better than one with fewer.
Is a 2-point gap between two models significant?
It depends on the number of questions and on how correlated the two models' outcomes are. With accuracy around 80%, 5% significance and 80% power, and both models answering the same questions with a correlation of 0.5, detecting a 2-point gap takes about 3,300 questions; an unpaired analysis needs about 6,500. HumanEval has only 164 questions and basically cannot resolve a gap that small.
How many questions does an evaluation set need?
It is set by the smallest gap you want to detect, and the number of questions is inversely proportional to the square of the gap: halve the gap and you need about four times as many questions. With accuracy around 80%, two models answering the same questions and a correlation of 0.5, detecting 5 points takes about 550 questions and detecting 1 point about 12,800 (5% significance, 80% power).
What is a paired analysis and why is it more powerful than an unpaired one?
A paired analysis draws inference on the per-question score difference between two models, rather than computing an interval for each model and comparing them. On the same questions the two models' right and wrong answers are usually positively correlated, so the variance of the per-question difference is smaller, the interval is narrower, and the same number of questions detects a smaller gap.
How is the confidence interval of accuracy computed?
When each question is scored right or wrong and the questions are independent, the standard error of accuracy p on n questions is sqrt(p(1−p)/n) and the 95% confidence interval is p ± 1.96 standard errors. For example, 80% accuracy on the 164 questions of HumanEval gives about ±6.1 points. When questions come in clusters, use a clustered standard error instead.