Preprint
Machine Learning

CodeGen

Erik Nijkamp, Bo Pang, Hiroaki Hayashi, Lifu Tu, Haiquan Wang, Yingbo Zhou, S. Savarese, Caiming Xiong
March 1, 2022International Conference on Learning Representations1,552 citations

1.6k

Citations

135

Influential Citations

International Conference on Learning Representations

Venue

2022

Year

Abstract

An LLM trained for program synthesis using input-output examples and natural language descriptions.

Analysis

Why This Paper Matters

Code generation has become a cornerstone application of large language models, with systems like OpenAI's Codex setting high bars. However, most prior work focused on single-turn prompts—where a user provides a complete description and expects a final code output. CodeGen challenges this paradigm by showing that breaking down programming problems into multiple conversational turns can yield better results. This is especially relevant for complex tasks where the initial specification is incomplete or ambiguous. By releasing a 16.1B parameter model and a new benchmark, the authors provide the community with tools to explore multi-turn synthesis more systematically.

How It Works

Figure 1

CodeGen is an autoregressive transformer trained with a standard next-token prediction objective. The key innovation lies in its sequential training pipeline over three distinct datasets:

  • CodeGen-NL: Trained on The Pile, a large English text corpus, to learn natural language understanding.
  • CodeGen-Multi: Initialized from CodeGen-NL and fine-tuned on a subset of the BigQuery dataset containing code in C, C++, Go, Java, JavaScript, and Python.
  • CodeGen-Mono: Initialized from CodeGen-Multi and further trained on BigPython, a large corpus of Python code.

Approximate statistics for training corpora along the pre-processing steps.

This staged approach allows the model to first acquire general linguistic knowledge, then learn cross-language programming patterns, and finally specialize in Python. The authors train models at four scales: 350M, 2.7B, 6.1B, and 16.1B parameters. All models use the same transformer architecture with hyperparameters detailed in the paper.

Hyper-parameters for model specification and optimization for the family of CodeGen models.

For multi-turn evaluation, the authors introduce the Multi-Turn Programming Benchmark (MTPB). In this benchmark, each problem is presented as a series of prompts that gradually refine the specification. The model must generate code after each turn, and the final solution is evaluated against test cases. This setup mimics real-world programming where requirements evolve through conversation.

Results

Evaluation results on the HumanEval benchmark

On the standard HumanEval benchmark, CodeGen models show clear scaling trends. CodeGen-NL already matches or exceeds GPT-Neo and GPT-J. CodeGen-Multi improves further, and CodeGen-Mono delivers the best performance. Notably, CodeGen-Mono 2.7B competes with Codex 2.5B, CodeGen-Mono 6.1B approaches Codex 12B, and CodeGen-Mono 16.1B is competitive with or outperforms Codex 12B.

Evaluation results on the Multi-Turn Programming Benchmark.

On MTPB, the authors report pass rates for 5 test cases with 40 samples per model per problem. Performance improves consistently with model size and data size, confirming that multi-turn synthesis benefits from larger models. This suggests that the ability to handle iterative specification is not a separate skill but emerges from scaling.

Significance

CodeGen's main contribution is twofold: it provides an open-source, competitive code generation model, and it systematically demonstrates the value of multi-turn prompting. The sequential training approach—from natural language to multi-language to Python—offers a blueprint for building specialized code models without sacrificing generality. The MTPB benchmark fills a gap in evaluating iterative code synthesis, which is more aligned with practical software development than single-turn benchmarks.

However, the paper has limitations. The MTPB is small (only 5 test cases), and the evaluation does not cover zero-shot or few-shot scenarios outside the training distribution. Additionally, the model's performance on languages other than Python is not thoroughly assessed. Future work could extend the multi-turn paradigm to other domains and explore more diverse benchmarks.

Overall, CodeGen advances the state of the art in program synthesis by showing that conversational interaction can unlock better code generation, and by providing the community with a strong open-source baseline for further research.