HumanEval › The pass@k Metric

Michael BrenndoerferMarch 2, 20265 min read
Language AI HandbookAll chapters
Part 54 of 67Benchmark Evaluation
Chapter 418HumanEval › The pass@k Metric
Reading section 5 of 15 · The pass@k Metric · 5 minSection 5 of 15 · 5 min

Book contents

Section 5 of 15 · 5 min read

HumanEval › The pass@k MetricOne section · Sections in this chapter5 / 15 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

The primary metric for HumanEval is pass@k, which measures the probability that at least one of kk samples from the model passes the test suite for a given problem. This metric shows a practical reality: we rarely expect perfect code on the first attempt, and modern coding assistants often generate multiple suggestions for you to choose from. Because we cannot sample infinitely from the model, we estimate this probability using a finite number of samples nn (where n≥kn \geq k).

The metric addresses a subtle but important statistical issue. If we simply reported the fraction of correct samples (c/nc/n), we would underestimate a model's utility in scenarios where users can examine multiple options. For example, if a model generates 100 samples and 10 pass, the single-sample accuracy is 10%, but the probability of finding a working solution when allowed to see 10 samples is substantially higher than 10%. Pass@k quantifies this cumulative probability, capturing the model's capacity to generate diverse, correct solutions within a search budget.

Mathematical Formulation

For a given problem, suppose we generate nn samples and find that cc of them pass all tests. If we were to randomly select kk samples without replacement from these nn, the probability that at least one is correct is given by the hypergeometric distribution:

pass@k=1−(n−ck)(nk)\text{pass@k} = 1 - \frac{\binom{n-c}{k}}{\binom{n}{k}}

where:

  • nn: total number of samples generated per problem (the sample pool size)
  • cc: number of correct samples (passing all tests)
  • kk: number of samples selected for evaluation (the budget of attempts)
  • (nk)\binom{n}{k}: the total number of ways to choose kk samples from nn
  • (n−ck)\binom{n-c}{k}: the number of ways to choose kk samples from the n−cn-c incorrect ones

The formula uses the complement rule: we calculate the probability that all kk selected samples are incorrect (the ratio of binomial coefficients) and subtract this from 1 to get the probability that at least one is correct. This approach assumes sampling without replacement, which is appropriate when selecting kk distinct samples from the nn generated candidates. Without replacement is the correct model here because in practice, we would present kk distinct solutions to you, not the same solution kk times.

Out[3]:
Visualization
Line chart showing pass@k for four success rates as k increases from 1 to 100. All curves converge toward 1.0 with higher rates saturating sooner.
Pass@k curves for four base success rates (c/n = 0.1, 0.25, 0.5, 0.75) as k increases from 1 to 100. Higher success rates saturate toward perfect scores faster, while the lowest success rate still reaches near-certainty well before k=100, illustrating the compounding benefit of additional samples.

Estimation with Large n

In practice, researchers often generate n=200n = 200 samples per problem but report pass@k for various kk values (typically k∈{1,10,100}k \in \{1, 10, 100\}). When nn is large relative to kk, we can approximate the binomial coefficient ratio. We can expand the ratio of binomial coefficients step-by-step:

(n−ck)(nk)=(n−c)!k!(n−c−k)!⋅k!(n−k)!n!(expand definitions)=(n−c)!(n−c−k)!⋅(n−k)!n!(cancel k! terms)=∏i=0k−1n−c−in−i(write as product of k terms)\begin{aligned} \frac{\binom{n-c}{k}}{\binom{n}{k}} &= \frac{(n-c)!}{k!(n-c-k)!} \cdot \frac{k!(n-k)!}{n!} && \text{(expand definitions)} \\ &= \frac{(n-c)!}{(n-c-k)!} \cdot \frac{(n-k)!}{n!} && \text{(cancel } k! \text{ terms)} \\ &= \prod_{i=0}^{k-1} \frac{n-c-i}{n-i} && \text{(write as product of } k \text{ terms)} \end{aligned}

When n≫kn \gg k, each term n−c−in−i≈1−cn\frac{n-c-i}{n-i} \approx 1 - \frac{c}{n}, so the product becomes (1−cn)k\left(1 - \frac{c}{n}\right)^k. This yields the approximation:

pass@k≈1−(1−cn)k\text{pass@k} \approx 1 - \left(1 - \frac{c}{n}\right)^k

where:

  • c/nc/n: the empirical probability that any single sample is correct (the maximum likelihood estimate of the true pass rate)
  • (1−c/n)k(1 - c/n)^k: the probability that all kk samples are incorrect, assuming independence

This approximation treats the sampling as approximately independent (with replacement), which is valid when nn is large and kk is small relative to nn. The approximation is useful because it avoids computing large binomial coefficients and gives intuitive insight: the probability of failure decays exponentially with kk when the base success probability is fixed.

Aggregation Across Problems

The final pass@k score is the mean pass@k across all problems in the benchmark, giving a single number that characterizes model performance:

pass@koverall=1N∑i=1Npass@ki\text{pass@k}_{\text{overall}} = \frac{1}{N} \sum_{i=1}^{N} \text{pass@k}_i

where:

  • NN: the number of problems in HumanEval (N=164N = 164)
  • pass@ki\text{pass@k}_i: the pass@k score for the ii-th problem

This macro-averaging approach gives equal weight to each problem, regardless of difficulty. An alternative would be to pool all samples across problems, but averaging per-problem scores prevents easy problems from dominating the metric and gives progress on hard problems equal weight. The choice of macro-averaging has an important implication: a model that perfectly solves 82 problems and fails all remaining 82 reaches the same pass@1 as a model that has a 50% success rate on every problem, even though these stand for qualitatively different capability profiles.