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.
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
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 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 it is the pass rate of a single sample; the larger is, the closer it gets to what the model can do when it is “given tries”.
Drawing exactly samples for each score has a large variance. The paper instead samples answers per problem, counts the of them that pass the tests, uses the unbiased estimate below and averages over all problems:
Here is the number of problems and is the number of passing samples for problem . The meaning: draw of the samples at random without replacement; the probability that all of them fail is , and subtracting it from 1 gives the probability that at least one passes. When the drawn samples must include a passing one, and the result is 1.
What not to do is estimate first and then compute . is a convex function of , so by Jensen’s inequality its expectation is higher than , 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 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 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 takes scoring, voting or reranking; the paper found that choosing the sample with the highest mean token log-probability beats picking at random.
- Report , and the sampling temperature. A higher temperature gives more diverse samples and a better score at large ; 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 passing samples out of 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 .
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 and the number of questions , with each question scored right or wrong and independent of the others. The standard error and the 95% confidence interval of the score are
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 ; the variance of the gap is
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 you need enough questions. With significance and power , the number of questions needed is
where , and . For two models that both score around 80%, with each question scored right or wrong, the results are:
| Gap | Paired (correlation 0.5) | Unpaired (correlation 0) |
|---|---|---|
| 5 points | 548 questions | 1,091 questions |
| 3 points | 1,472 questions | 2,940 questions |
| 2 points | 3,256 questions | 6,507 questions |
| 1 point | 12,792 questions | 25,580 questions |
Halving the gap takes about four times as many questions, because is inversely proportional to . 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:
- Compute the standard error of the mean with the central limit theorem and report it with the score.
- When questions come in groups (for example several questions about the same passage), use clustered standard errors.
- Reduce variance by sampling each question repeatedly and by analyzing next-token probabilities.
- When comparing two models, draw statistical inference on the paired per-question differences.
- 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 ; do not extrapolate with .
- 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 samples per problem, one problem has 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 of the formula). 65.1% is what the naive form 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 . 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 ; 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 it is 3,256 questions; unpaired it is about 6,507.
Exercises
- One problem is sampled times and samples pass the tests. Compute the unbiased and the naive estimates of pass@k for .
- 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?
- 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
- 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 , , while , so the naive form is too low.
- Paired: , standard error , 95% half-width about 2.9 points, , . That is just past the 5% line, so the evidence is weak. Unpaired: standard error about 0.0235, half-width about 4.6 points, , , 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.
- 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 , that is questions; drag the question slider to between 500 and 600 to check.
Further reading
- Miller, Adding Error Bars to Evals (2024); statistical methods for evaluations and the five recommendations
- Chen et al., Evaluating Large Language Models Trained on Code (2021); HumanEval and the unbiased pass@k estimator in Appendix A
- LLM Evaluation Methodology: Benchmarks, Contamination and a Workflow
- LLM-as-a-Judge: Using a Model as the Grader, Its Biases and Calibration: open-ended evaluation and judge bias
- An example of recovering the trial counts and attaching confidence intervals to each cell: the RT-2 breakdown.
- Two-proportion z tests on a paper’s comparisons and a check of the abstract’s conventions: the OpenVLA breakdown.
- An example of estimating the resolution of a robot evaluation with only 10 trials per bar, using Clopper–Pearson intervals and Fisher’s exact test: the π0 breakdown.
- An example of sign tests and a bootstrap over tasks, a parametric bootstrap for rows with 10 trials, and two tables of one paper that disagree: the GR00T N1 breakdown.
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.