TL;DR
Large language models (LLMs) for code generation often struggle because they are trained on static datasets that don't penalize their specific mistakes. This paper introduces Imitation learning from Language Feedback (ILF), a technique that uses a small amount of human-written natural language feedback to correct model errors, creating a high-quality training signal that improves a 6.1B parameter model's performance by 38% relative to its baseline.
What Problem Does This Paper Address?
While LLMs have shown impressive success in program synthesis, they frequently produce code that is almost correct but contains subtle bugs. Traditional training methods rely on "gold" demonstrations (perfectly written code), but this approach has two major drawbacks:
- Distributional Mismatch: Gold code often looks very different from the code the model naturally generates, making it harder for the model to learn from.
- Lack of Negative Signal: Standard pre-training doesn't provide a signal for "trial-and-error." The model isn't explicitly taught why a certain approach is wrong or how to fix its specific recurring bugs.
The authors seek to bridge this gap by incorporating natural language feedback—a rich, expressive form of supervision—directly into the training loop, rather than just using it as a prompt at inference time.
Methods
The authors propose the Imitation learning from Language Feedback (ILF) algorithm. The process follows a specific loop:
- Generate & Filter: The base model ($\pi_\theta$) generates multiple programs for a task. Programs that fail unit tests are identified.
- Human Feedback: Human annotators write brief natural language descriptions of the bugs in the incorrect programs and how to fix them.
- Refinement: A separate "refinement model" ($\pi_{Refine}$) takes the incorrect program and the human feedback to generate a "refinement"—a corrected version of the code.
- Fine-tuning: The base model is then fine-tuned on these successful refinements. Crucially, the model is trained to generate the correct code from the original task description without needing the feedback at test time.
Mathematically, the authors show that this process can be viewed as minimizing the KL divergence between the model's distribution and a target ground-truth distribution, using importance sampling where the feedback helps focus the sampling on high-quality corrections.
Datasets
The primary benchmark used is Mostly Basic Python Problems (MBPP), which contains 974 entry-level Python programming tasks.
- MBPP-Refine: A subset of tasks where the base model failed, used to train the refinement model.
- MBPP-Train: Used to generate the final refinements for fine-tuning the base model.
- MBPP-Test: Used for final evaluation.
The authors collected a new dataset of 195 triples consisting of (incorrect program, human feedback, human refinement) to facilitate this research.
Key Insights and Ideas
- Refinements are "Easier" to Learn: One of the most striking findings is that fine-tuning on refinements works better than fine-tuning on "gold" MBPP solutions. The authors hypothesize this is because refinements are closer to the model's original output distribution (lower perplexity), making the learning task more efficient.
- Feedback is Sample-Efficient: ILF achieved significant gains using only 78 training examples. This suggests that a small amount of targeted feedback is more valuable than a large amount of generic demonstration data.
- Human vs. AI Feedback: While using an LLM (like InstructGPT) to provide feedback is cheaper, it is currently less effective. Human feedback is more descriptive and addresses more bugs per sample, whereas current models often provide generic or irrelevant feedback (e.g., "Great job!" for buggy code).
Key Results
The researchers used CODEGEN-MONO 6.1B as their base model. The main results on the MBPP benchmark include:
- Pass@1 Rate: ILF improved the pass@1 rate from 26% (zero-shot) to 36%, a 38% relative increase.
- Outperforming Baselines: ILF (36%) outperformed fine-tuning on the MBPP "gold" programs (22%) and even fine-tuning on human-written refinements (33%).
- Scaling: As shown in the scaling analysis, while model-generated feedback helps, it requires significantly more data to approach the performance gains provided by a tiny set of human-annotated samples.
Limitations and Future Work
- Refinement Model Bottleneck: The refinement model ($\pi_{Refine}$) struggles when a program has multiple complex bugs. The authors suggest that a multi-turn "Chain-of-Thought" approach to refinement might be necessary for more difficult tasks.
- Human Cost: Collecting high-quality human feedback is expensive and time-consuming (averaging 27 minutes per sample in this study).
- Automation: A key direction for future work is "RL from AI Feedback" (RLAIF), where the feedback generation is fully automated as LLMs become more capable of self-critique.
- Iterative ILF: The authors note that ILF could theoretically be applied in multiple rounds to continuously "boot-strap" model performance as new types of bugs are discovered.
Summary updated