Towards Self-Improving Language Models for Code Generation

Michaël Defferrard, Corrado Rainone, David W. Zhang, Blazej Manczak, Natasha Butt, Taco CohenLLMAgents @ ICLR 2024

TL;DR

This paper introduces an "expert iteration" (ExIt) framework to train language models for code generation from scratch, without relying on human-written code. By combining a neural network's intuition with a powerful search algorithm, the model generates its own training data, leading to progressively better code generation capabilities and self-improvement.

What Problem Does This Paper Address?

Large language models (LLMs) have shown remarkable success in code generation, but their performance is heavily dependent on the vast amounts of human-written code they are trained on. This human-generated data is a finite and often slow-growing resource, and crucially, only a small fraction of it is of high quality. The paper addresses the challenge of how to enable LLMs to improve autonomously, starting from scratch, without needing a constant stream of high-quality human data. This is akin to developing a "System 2" reasoning capability in LLMs, complementing their existing "System 1" pattern recognition.

Methods

The core of the proposed method is an expert iteration (ExIt) scheme, inspired by techniques used in game playing (like AlphaZero). ExIt involves two main phases:

  1. Search Stage: A neural network (acting as the "intuitive" System 1) guides a search algorithm (acting as the "reasoning" System 2) to generate candidate programs for a given programming task (specified by input-output examples).
  2. Training Stage: The programs generated by the search stage, particularly those that are successful, are used as training data to fine-tune the neural network. This creates a virtuous cycle where the search becomes more effective with an improved neural network, which in turn generates better training data.

The paper explores two search methods:

  • Sampling & Filtering (S&F): A simpler method that samples programs based on the neural network's policy and filters for the best ones.
  • Monte Carlo Tree Search (MCTS): A more sophisticated method that leverages both the neural network's policy and a value function prediction to guide its search more effectively.

The neural network used is a Transformer, trained as a language model on sequences representing program generation trajectories.

Datasets

The paper uses two main datasets for evaluation:

  • Add-N: This dataset consists of tasks where the goal is to write a program that sums a list of N integers. The difficulty increases with N, creating a natural curriculum where solving a task for N-1 inputs can inform the solution for N inputs.
  • Random Programs: This dataset is generated procedurally, creating programs and their corresponding input-output specifications. This dataset is designed to test generalization across qualitatively distinct tasks, as opposed to the related tasks in Add-N.

Key Insights and Ideas

  • Self-Improvement from Scratch: The most significant insight is demonstrating that LLMs can learn to generate code effectively from random initialization, solely by generating their own training data through a search-and-learn loop. This bypasses the bottleneck of needing high-quality human code.
  • Curriculum Learning Emergence: The Add-N dataset naturally creates a curriculum. As the model improves, it can leverage its knowledge of simpler addition tasks to solve more complex ones, mimicking how humans learn. This is a key factor in the success of ExIt for this dataset.
  • Search vs. Training Trade-off: The paper investigates how to best allocate computational resources between search and training. It highlights that a minimal amount of search is crucial for progress, but beyond that, the optimal balance can be task-dependent, with some tasks showing diminishing returns from excessive search.
  • MCTS vs. S&F: While MCTS is generally more powerful and can achieve higher performance, especially with sufficient simulations, S&F offers more stable and predictable performance, making it a viable alternative depending on the task and computational budget.

Key Results

  • The proposed ExIt framework successfully trains language models to generate programs from scratch, achieving significant performance improvements as compute increases.
  • For the Add-N tasks, performance shows a clear improvement curve with increasing compute, demonstrating the model's ability to climb the programming difficulty ladder.
  • For Random Programs, while performance also increases with compute, the convergence behavior is more erratic, suggesting that the lack of an inherent curriculum makes learning more challenging.
  • The paper shows that combining both policy and value learning within the neural network leads to better performance than using either alone.

Limitations and Future Work

  • Dataset Scope: The experiments were conducted on relatively simple datasets (Add-N and procedurally generated programs). The authors acknowledge that these datasets are limited in scope and it will be interesting to see how the findings generalize to more complex programming tasks and real-world code generation scenarios.
  • Asymptotic Performance: The paper does not definitively answer whether final performance will asymptotically reach 100% for all tasks, especially for the Random Programs dataset, as their runs were not long enough to observe this.
  • Optimal Search Budget: While the paper identifies a minimal search budget requirement, it notes that the optimal search budget for asymptotic performance is not strongly impacted by the search budget once it's above this minimum. However, determining the absolute best budgeting for unlimited FLOPs is beyond the scope of this work.
  • Future Work: The authors suggest exploring how these findings generalize to other settings and investigating the optimal search budget for unlimited computational resources. They also leave open the question of whether final performance can reach 100% for all tasks.

Summary updated

BibTeX
@inproceedings{defferrard2024towards,
  author = {Michaël Defferrard and Corrado Rainone and David W. Zhang and Blazej Manczak and Natasha Butt and Taco Cohen},
  title = {{Towards Self-Improving Language Models for Code Generation}},
  booktitle = {LLMAgents @ ICLR},
  year = {2024},
  url = {https://openreview.net/forum?id=SA2zPf03zQ},
}
Figure