pass@k for Code Generation

medium
Unit 13 · Evaluation I0/2 to milestone

How good is a code model if you let it try k times? Generate n ≥ k samples per problem, count the c that pass the tests, and use the unbiased estimator from the Codex paper:

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

Binomials overflow quickly for large n, so compute it as a product: 1−∏i=n−c+1n(1−ki)1 - \prod_{i=n-c+1}^{n} \left(1 - \frac{k}{i}\right). If n−c<kn - c < k, the answer is exactly 1.0.

Implement pass_at_k(n, c, k) and mean_pass_at_k(results, k), where results is a list of (n, c) pairs, one per problem.

#evaluation#code-generation#probability2 visible + 3 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
pass@k for Code Generation · TechGradify