GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
★ Read firstarXiv preprint

Evaluating Large Language Models Trained on Code

OpenAI wrote 164 Python problems with unit tests and scored generated code by whether it passes. Codex-12B solved 28.8% with one sample and 72% with 100, which is where pass@k comes from.

Breakdown by FDE Interviews · 13 min read · Updated

About the original · 2021
AUTHORS
Chen, Tworek, Jun, Yuan et al.
FROM
OpenAI
PUBLISHED
Jul 2021 · arXiv preprint
CITED BY
12,787Semantic Scholar · Nov 2026
IN THIS BREAKDOWN · 10 SECTIONS

You can read 20% of this breakdown.

01

The paper in one minute

Before this paper, generated code was usually graded by comparing it with a reference solution, token by token or with BLEU. A correct program that names its variables differently scores poorly; a broken program that looks like the reference scores well. The authors propose grading by execution: run the generated function against unit tests, the way a developer would accept a pull request.

To do that without training-set leakage they wrote HumanEval: 164 Python problems by hand, each with a function signature, a docstring, a reference body and an average of 7.7 unit tests. The problems test language comprehension, simple algorithms and arithmetic, some at the level of an easy interview question. They then fine-tuned GPT models of up to 12 billion parameters on 159 GB of Python collected from 54 million public GitHub repositories in May 2020, and called the result Codex. A descendant powered GitHub Copilot.

The metric is pass@k: draw k samples per problem and count the problem solved if any one passes. Computing it naively from exactly k samples is noisy, so the paper draws n = 200 samples and uses an unbiased estimator, 1 - C(n-c, k)/C(n, k) where c samples passed. With one sample, Codex-12B passed 28.8% of problems, GPT-J 11.4% and every GPT-3 model close to 0%. With 100 samples, at least one passed for 72.3%. A further fine-tune on about 50,000 standalone functions with tests, Codex-S, reached 37.7% with one sample and 77.5% with 100.

The paper also studies how to choose one sample without tests (mean log-probability works best), a docstring-writing model (Codex-D), the APPS contest benchmark, limitations on long specifications, and a broad hazard analysis.

THE IDEA, VISUALLY
PICK ONE OF 100 SAMPLES (CODEX-S-12B) one sample 37.7% best mean log-prob of 100 44.5% any of 100 passes the tests 77.5% Without tests at selection time, the best heuristic recovers 7 of the 40 points that tests would. A SPEC THAT DISAGREES WITH ITS TEST (APP. C) "remove every third character from the string" reference code a b c d e f g h i -> bcefhi plain reading a b c d e f g h i -> abdegh A model that follows the words fails every test of block 6; a 5-block chain contains block 6 or 12 57% of the time. PASS@1, TABLE 1, WITH A 164-PROBLEM 95% BAR GPT-Neo 2.7B 6.4 21 @100 Codex-85M 8.2 22 @100 GPT-J 6B 11.6 28 @100 Codex-300M 13.2 36 @100 Codex-679M 16.2 41 @100 Codex-2.5B 21.4 60 @100 Codex-12B 28.8 72 @100 0% 20% 40% 60% 80% bar = pass@1 with its 95% interval (our calculation); open dot = pass@100. Abstract: 70.2% for Codex-12B at 100. arXiv 2107.03374, OpenAI
Codex-S-12B, the version fine-tuned on standalone functions, solves 37.7% of HumanEval with one sample. Drawing 100 samples and keeping the one with the highest mean token log-probability raises that to 44.5% without running anything; keeping any sample that passes the unit tests raises it to 77.5%. On the right, Table 1's pass@1 by model size, with the 95% interval a 164-problem test set allows (our calculation), and one of the paper's own synthetic specifications whose reference code removes characters 1, 4 and 7 when the text says every third.
Research notes: the problem, approach and results
28.8% to 72.3%

Codex-12B, one sample against at least one passing sample among 100 (Table 1)

44.5% vs 77.5%

Codex-S-12B picking 1 of 100 samples by mean log-probability against picking by unit tests (Section 1)

+/- 6.9 pts

95% interval on a 28.8% pass@1 measured on 164 problems (our calculation)

THE PROBLEM

Code models were scored by BLEU or exact match against a reference solution. Neither tells you whether the code works, and many different programs are correct. Public benchmarks built from GitHub or contest sites were also likely to be in the training data.

THE IDEA

Write 164 new Python problems by hand, each a signature, a docstring and unit tests, and count a problem solved when generated code passes the tests. Define pass@k, the chance that at least one of k samples passes, with an unbiased estimator from n samples.

THE RESULT

Codex-12B, GPT fine-tuned on 159 GB of GitHub Python, solved 28.8% with one sample; GPT-3 solved none and GPT-J 11.4%. With 100 samples per problem 72.3% had a passing one. Fine-tuning on standalone functions (Codex-S) raised one-sample accuracy to 37.7%.

02

Why it matters to an FDE

Grade generated code by running it. When a customer wants a model that writes SQL, scripts or transformations, the evaluation that matters is whether the output executes and produces the right result on test inputs. The paper's Figure 8 shows that wrong programs often score higher BLEU than right ones, so a text-similarity score can rank the worse model first.

Pick the k that matches the product. An autocomplete shows one suggestion, so pass@1 is the number. An agent that can run tests and retry is closer to pass@k, because it can throw away samples that fail. The gap is large: 28.8% against 72.3% for the same model. Quoting pass@100 for a product that shows one answer overstates it by more than a factor of two.

Tune the temperature to k. The best temperature for pass@1 was 0.2 and for pass@100 was 0.8. If you sample many candidates and filter, low temperature wastes the budget on near-duplicates.

Run generated code in a sandbox. The authors executed untrusted code inside gVisor containers with eBPF firewall rules blocking network access. Any customer system that executes model-written code needs the same isolation before it needs a better model.

Know how wide your test set's error bar is. With 164 problems, a 28.8% score carries a 95% interval of about plus or minus 7 points. Two models a few points apart on HumanEval are not separated by it, and the same holds for a customer's own 150-item golden set.

THE FULL BREAKDOWN

Understand the mechanism. Try it on a real problem.

Unlock this breakdown and 290 more papers.

Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.

6 months · One payment · No auto-renewal

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦2 results tables
  • ?5 interview questions with answers
  1. 03Key takeaways

    The benchmark, pass@k and its estimator, the model family, selection without tests, and limits

    Free account
  2. 04How it works

    The data, the model, sampling and stop sequences, the estimator, the sandbox, and Codex-S

    Premium
  3. 05The numbers that matter

    Table 1 by model, Codex-S, selection heuristics, APPS, Codex-D and the chained-docstring test

    Premium
  4. 06Try it yourself

    Test the pass@k estimators, recheck Table 1 and its error bars, and run two of the paper's own specs

    Premium
  5. 07Where it breaks

    Short standalone functions, small test suites, leakage over time, an oracle pass@k, and slips

    Premium
  6. 08Using it on a deployment

    Build an execution-based eval, decide where sampling and tests sit, and size the test set

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →