Paper Breakdowns  /  Codex
Paper 74~10 min readOpenAI · 2021worked math + runnable code
Paper Breakdown

Codex,
explained.

Take GPT, feed it a mountain of public code, and it learns to write programs from a comment. That model, Codex, became the engine of GitHub Copilot and put AI pair-programming in millions of editors. But the paper's quiet, lasting contribution isn't the model — it's how to measure one. You can't grade code by how similar it looks to an answer key; you have to run it. Codex's answer, pass@k, asks the honest question: if the model takes a few shots at a problem, does at least one of them actually work? Here's the model, the benchmark, and the metric that reshaped how code AI is judged.

Video breakdown
The animated walkthrough is in production.
Read the full breakdown below in the meantime ↓
01

GPT that writes code

Code is text, and a lot of it is public. Codex's recipe was simply to take the GPT architecture and fine-tune it on billions of lines of source code from GitHub. The result is a language model whose "language" includes Python, JavaScript, and dozens of others — a model that, given a function signature and a docstring, continues the "sentence" by writing the function body. Because programming languages have tighter structure than natural language, and because so much example code exists, the model became strikingly capable at turning intent into working code.

That capability, wrapped in an editor, became GitHub Copilot — autocomplete that finishes not just the line but the whole function. But shipping a code model raised a sharp evaluation problem the natural-language world had mostly dodged: how do you know if generated code is good? That question is where the paper made its deepest mark.

The one-sentence version

Fine-tune GPT on public code to get a programming assistant, and measure it by whether generated programs actually pass tests — pass@k — not by how they look.

02

Run it, don't match it

The old way to score generated text is to compare it to a reference with a similarity metric like BLEU. For code this is badly broken: a correct program can be written a hundred different ways, so a working solution that looks different from the reference scores terribly, while a broken one that looks similar scores well. Text similarity measures the wrong thing entirely.

Codex insisted on functional correctness: a generated program is right if and only if it passes the unit tests. To measure this it introduced HumanEval — 164 hand-written problems, each a function signature, a docstring describing the task, and a set of hidden tests. Generate a solution, run it against the tests, and it counts only if every test passes. Hand-writing the problems (rather than scraping them) was deliberate, to reduce the chance they'd leaked into training data. Grade by execution, not appearance.

03

The pass@k metric

Now the subtle part. A code model is a sampler — ask it twice and you get two different programs. So the right question isn't "is its single output correct" but "if it takes k attempts, does at least one work?" That's pass@k: the probability that at least one of k sampled solutions passes the tests. Estimating it naively (sample k, check) is high-variance, so Codex uses an unbiased estimator: sample a larger n, count c that pass, and compute the chance a random k-subset contains no passing one, subtracted from 1:

pass@k = 1 − C(n − c, k) / C(n, k)  ·  pass@1 = c/n  ·  if n − c < k → 1

C(n−c, k)/C(n, k) is the probability that all k drawn solutions come from the failing ones — so 1 minus it is the probability at least one passes. It reduces to the fraction correct at k = 1, hits 1 when every solution passes (or when there are fewer failures than k), and 0 when none pass. Computing it from a big n gives a stable estimate of a small-k quantity. The runnable version below computes the whole pass@k curve.

04

Sampling helps

The pass@k framing exposes a practical truth: more attempts dramatically raise your odds. A model with a modest 30% chance of solving a problem on the first try has a much higher chance that one of ten tries works — because the failures are somewhat independent, ten shots cover far more ground than one.

pass@k climbs with attempts (30% per-sample)
pass@1~30% — one shot, the raw solve rate.
pass@5~84% — five shots cover much more.
pass@10~98% — ten shots almost always land one.
CatchYou still must pick the right one — sampling raises "a solution exists," not "you'll choose it."

That gap between "one of these works" and "I know which one" is the crux. High pass@k says the model can produce a solution if you can verify which sample is correct — which for code you often can, by running tests. This is exactly the generate-and-verify asymmetry: generating many candidates is cheap, checking them is cheap (run the tests), so sampling plus a verifier is a powerful recipe. Codex made that concrete for code and standardized how to measure it.

RUN IT YOURSELF

The pass@k curve

pass@k is the unbiased estimator 1 − C(n−c, k)/C(n, k), and it behaves exactly as intuition says. This computes it: pass@1 equals the raw solve fraction (30/100 = 0.30), and the curve climbs steeply with more samples — 0.30 at one shot, 0.84 at five, 0.98 at ten — because independent attempts cover more ground. It also checks the edges: all solutions correct gives 1.0, none gives 0.0, and when there are fewer failing solutions than k every k-subset must include a passing one. Change the counts and watch the curve move.

CPython · WebAssembly
05

Copilot

Codex's headline numbers were strong for 2021 — solving a meaningful fraction of HumanEval on the first try and much more with sampling — but its real impact was in production:

OutcomeSignificance
GitHub CopilotThe first widely-used AI coding assistant, built on Codex, in millions of editors.
HumanEval + pass@kBecame the standard benchmark and metric for code generation, used by nearly every model since.
Functional correctnessEstablished test-based evaluation as the norm — grade code by running it.
Honest about limitsThe paper documented failure modes and safety concerns (buggy or insecure suggestions) up front.

The productization mattered as much as the research: Copilot made everyday developers' first real contact with a large language model, years before ChatGPT, normalizing the idea of AI as a coding collaborator. And the evaluation contribution outlived the specific model — every code model is still reported in pass@k on HumanEval-style benchmarks.

06

What it set up

Codex kicked off the code-model era: a lineage of ever-stronger coding models, richer benchmarks (MBPP, SWE-bench, and beyond), and eventually the coding agents that don't just autocomplete but plan, edit, run, and debug across a repository. The through-line from Codex is the pairing it made standard — a generative model plus an executable check.

That pairing is its deepest legacy. Code is special among AI tasks because correctness is mechanically verifiable — you can just run it. Codex leaned into that: measure by execution (pass@k), and exploit it (sample many, keep what passes). The same generate-and-verify structure now underlies coding agents that iterate against tests and reasoning systems trained on verified answers. Codex was where "let the machine write it, then check it actually works" became the organizing principle of AI for code.

Worth knowing

pass@k's exploitable gap — high "a solution exists," lower "you picked it" — is why later systems add a selection step: run the samples against the visible tests and submit one that passes, converting pass@k into an actual solve.

Frequently asked

Quick answers

What is Codex?

A GPT model fine-tuned on public code that writes programs from descriptions; it powered GitHub Copilot and introduced HumanEval and pass@k.

What is pass@k?

The probability that at least one of k sampled solutions passes the tests, estimated unbiasedly as 1 − C(n−c, k)/C(n, k) from n samples with c passing.

Why test-based evaluation?

Code can be correct in many forms, so text similarity misleads. Running against unit tests checks what matters — does it work.

Why does sampling help?

Independent attempts cover more ground, so pass@10 far exceeds pass@1 — provided you can verify which sample is correct (run the tests).

Finished this one? 0 / 101 Paper Breakdowns done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns