NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Evaluating Large Language Models Trained on Code

Mark Chen, Jerry Tworek, Heewoo Jun, Qiming Yuan, Henrique Pondé de Oliveira Pinto, Jared Kaplan, Harri Edwards, Yuri Burda, Nicholas Joseph, Greg Brockman, Alex Ray, Raul Puri, Gretchen Krueger, Michael Petrov, Heidy Khlaaf, Girish Sastry, Pamela Mishkin, Brooke Chan, Scott Gray, Nick Ryder, Mikhail Pavlov, Alethea Power, Lukasz Kaiser, Mohammad Bavarian, Clemens Winter, Philippe Tillet, Felipe Petroski Such, Dave Cummings, Matthias Plappert, Fotios Chantzis, Elizabeth Barnes, Ariel Herbert-Voss, William Hebgen Guss, Alex Nichol, Alex Paino, Nikolas Tezak, Jie Tang, Igor Babuschkin, Suchir Balaji, Shantanu Jain, William Saunders, Christopher Hesse, Andrew N. Carr, Jan Leike, Joshua Achiam, Vedant Misra, Evan Morikawa, Alec Radford, Matthew Knight, Miles Brundage, Mira Murati, Katie Mayer, Peter Welinder, Bob McGrew, Dario Amodei, Sam McCandlish, Ilya Sutskever, Wojciech ZarembaarXiv 2021

Introduction

Program synthesis—the automated generation of code from high-level descriptions—has long been a central goal in computer science. While large language models (LLMs) like GPT-3 have demonstrated a rudimentary capacity for code generation, they were not specifically optimized for the structural and logical rigors of programming. OpenAI's Codex addresses this by fine-tuning GPT-3 on a massive corpus of public code from GitHub.

The development of Codex highlights two critical challenges in the field:

  1. Training Mismatch: General-purpose natural language models are not inherently tuned for the logic-heavy nature of source code.
  2. Evaluation Gap: Traditional NLP metrics such as BLEU are inadequate for code, where minor character changes can lead to total functional failure. This research emphasizes functional correctness—verifying code through execution against unit tests.

Methodology

Codex is based on the GPT-3 architecture, fine-tuned on 159 GB of Python code. To optimize performance, the researchers implemented several technical innovations:

  • Specialized Tokenization: A custom tokenizer handles whitespace more efficiently, reducing token count by approximately 30%.
  • The pass@k Metric: To account for the stochastic nature of generation, the authors utilize pass@k, an unbiased estimator of the probability that at least one of $k$ generated samples passes all unit tests.
  • Supervised Fine-Tuning (Codex-S): The base model was further refined on curated competitive programming data and integration traces to prioritize functional logic over repository "noise."
  • Safe Execution: Code is evaluated in a sandboxed environment using gVisor to mitigate security risks during testing.

The models were evaluated on HumanEval, a new benchmark of 164 original programming problems designed to avoid data contamination, and the APPS competitive programming dataset.

Key Insights: Temperature and Sampling

A primary finding of the study is the significant performance gain achieved through repeated sampling. While a single attempt (pass@1) may yield modest results, generating multiple candidates (pass@100) and selecting the best via unit tests dramatically increases success rates.

Furthermore, the optimal "temperature" (a parameter controlling the randomness of the model's output) depends heavily on the number of samples $k$. For $k=1$, a low temperature is preferred to ensure predictable, high-probability outputs. Conversely, for larger $k$, higher temperatures are more effective as they encourage the exploration of diverse logical paths.

Pass@K performance across different temperatures and sample sizes.

The researchers also identified a phenomenon termed "bug mimicry," where the model may intentionally produce buggy code if the input prompt contains stylistic errors, reflecting its training on diverse (and sometimes flawed) human-written code.

Results and Scaling

Codex demonstrates a substantial leap over general-purpose models. On the HumanEval benchmark, GPT-3 failed to solve any problems (0%), whereas the 12B parameter Codex achieved a 28.8% pass@1 rate. The supervised Codex-S variant further improved this to 37.7%.

Performance scales predictably with model size, following a power law similar to that observed in natural language tasks. Advanced reranking techniques, such as mean log-probability reranking or oracle selection, further push the boundaries of the model's capabilities.

Pass rate scaling across model sizes for GPT-3, Codex, and Codex-S variants.

Limitations and Security

Despite its proficiency, Codex remains sample-inefficient compared to human learners. It struggles with long-chain logic (e.g., sequences of more than a few operations) and occasionally commits basic errors in variable binding or loop counters.

From a safety perspective, the authors note that Codex can generate insecure code or be used to assist in malware creation. However, they conclude that it does not yet significantly lower the barrier for sophisticated cyberattacks, though it warrants ongoing monitoring as the technology matures.

Summary updated

BibTeX
@misc{chen2021evaluating,
  author = {Mark Chen and Jerry Tworek and Heewoo Jun and Qiming Yuan and Henrique Pondé de Oliveira Pinto and Jared Kaplan and Harri Edwards and Yuri Burda and Nicholas Joseph and Greg Brockman and Alex Ray and Raul Puri and Gretchen Krueger and Michael Petrov and Heidy Khlaaf and Girish Sastry and Pamela Mishkin and Brooke Chan and Scott Gray and Nick Ryder and Mikhail Pavlov and Alethea Power and Lukasz Kaiser and Mohammad Bavarian and Clemens Winter and Philippe Tillet and Felipe Petroski Such and Dave Cummings and Matthias Plappert and Fotios Chantzis and Elizabeth Barnes and Ariel Herbert-Voss and William Hebgen Guss and Alex Nichol and Alex Paino and Nikolas Tezak and Jie Tang and Igor Babuschkin and Suchir Balaji and Shantanu Jain and William Saunders and Christopher Hesse and Andrew N. Carr and Jan Leike and Joshua Achiam and Vedant Misra and Evan Morikawa and Alec Radford and Matthew Knight and Miles Brundage and Mira Murati and Katie Mayer and Peter Welinder and Bob McGrew and Dario Amodei and Sam McCandlish and Ilya Sutskever and Wojciech Zaremba},
  title = {{Evaluating Large Language Models Trained on Code}},
  year = {2021},
  eprint = {2107.03374},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2107.03374},
}
Figure