HumanEval › The pass@k Metric
Language AI HandbookAll chapters 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 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 (where ).
The metric addresses a subtle but important statistical issue. If we simply reported the fraction of correct samples (), 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 samples and find that of them pass all tests. If we were to randomly select samples without replacement from these , the probability that at least one is correct is given by the hypergeometric distribution:
where:
- : total number of samples generated per problem (the sample pool size)
- : number of correct samples (passing all tests)
- : number of samples selected for evaluation (the budget of attempts)
- : the total number of ways to choose samples from
- : the number of ways to choose samples from the incorrect ones
The formula uses the complement rule: we calculate the probability that all 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 distinct samples from the generated candidates. Without replacement is the correct model here because in practice, we would present distinct solutions to you, not the same solution times.

Estimation with Large n
In practice, researchers often generate samples per problem but report pass@k for various values (typically ). When is large relative to , we can approximate the binomial coefficient ratio. We can expand the ratio of binomial coefficients step-by-step:
When , each term , so the product becomes . This yields the approximation:
where:
- : the empirical probability that any single sample is correct (the maximum likelihood estimate of the true pass rate)
- : the probability that all samples are incorrect, assuming independence
This approximation treats the sampling as approximately independent (with replacement), which is valid when is large and is small relative to . The approximation is useful because it avoids computing large binomial coefficients and gives intuitive insight: the probability of failure decays exponentially with 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:
where:
- : the number of problems in HumanEval ()
- : the pass@k score for the -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.