Skip to main content
QUICK REVIEW

[Paper Review] Improving Code Generation by Training with Natural Language Feedback

Angelica Chen, Jérémy Scheurer|arXiv (Cornell University)|Mar 28, 2023
Software Engineering ResearchComputer Science10 citations
TL;DR

The paper introduces Imitation Learning from Language Feedback (ILF), a training-time method where human-written natural language feedback and refinements repair incorrect code and improve a CodeGen model’s pass rates, outperforming baseline fine-tuning.

ABSTRACT

The potential for pre-trained large language models (LLMs) to use natural language feedback at inference time has been an exciting recent development. We build upon this observation by formalizing an algorithm for learning from natural language feedback at training time instead, which we call Imitation learning from Language Feedback (ILF). ILF requires only a small amount of human-written feedback during training and does not require the same feedback at test time, making it both user-friendly and sample-efficient. We further show that ILF can be seen as a form of minimizing the KL divergence to the ground truth distribution and demonstrate a proof-of-concept on a neural program synthesis task. We use ILF to improve a Codegen-Mono 6.1B model's pass@1 rate by 38% relative (and 10% absolute) on the Mostly Basic Python Problems (MBPP) benchmark, outperforming both fine-tuning on MBPP and fine-tuning on repaired programs written by humans. Overall, our results suggest that learning from human-written natural language feedback is both more effective and sample-efficient than training exclusively on demonstrations for improving an LLM's performance on code generation tasks.

Motivation & Objective

  • Motivate improving code generation by leveraging human-written feedback during training rather than at test time.
  • Formalize ILF as minimizing KL divergence to a ground-truth distribution of higher-quality code.
  • _show that ILF can outperform standard fine-tuning on MBPP and human-repaired data_.

Proposed method

  • Define a reward-based objective where refinements increase unit-test pass rates.
  • Create a refinement model πRefine trained to transform incorrect code x0 using feedback f into correct code x1.
  • Construct a proposal distribution qt that preferentially samples high-quality refinements incorporating feedback.
  • Fine-tune the base model θ on refinements generated by πRefine to obtain θ*, enabling iterative improvement.
  • Use MBPP with CodeGen-Mono 6.1B as the base model and evaluate pass@k metrics.
  • Compare ILF to baselines including zero-shot, MBPP gold fine-tuning, and InstructGPT-generated refinements.
Figure 1: An overview of imitation learning from language feedback (ILF) for code generation. Given an initial LLM $\pi_{\theta}$ , we sample programs from $\pi_{\theta}$ that do not pass unit tests (indicated by the red X). Human annotators write natural language feedback for the incorrect program
Figure 1: An overview of imitation learning from language feedback (ILF) for code generation. Given an initial LLM $\pi_{\theta}$ , we sample programs from $\pi_{\theta}$ that do not pass unit tests (indicated by the red X). Human annotators write natural language feedback for the incorrect program

Experimental results

Research questions

  • RQ1Can training with human-written natural language feedback improve code generation performance beyond standard demonstrations?
  • RQ2How does ILF compare to training on gold MBPP data or human-written refinements alone?
  • RQ3What is the impact of using human versus model-generated feedback on final pass rates?
  • RQ4How does the refinement quality and handling of multiple bugs affect the ILF effectiveness?

Key findings

  • ILF improves CodeGen-Mono 6.1B pass@1 on MBPP by 38% relative (10% absolute) over zero-shot.
  • ILF outperforms fine-tuning on MBPP gold programs and fine-tuning on human refinements for pass@1 (14% absolute, 64% relative; and 3% absolute, 9% relative, respectively).
  • Fine-tuning on πRefine-generated refinements yields substantial gains over single-shot feedback and improves refinement pass rates (Pass@1: 19% vs 0% zero-shot; Pass@10: 47% vs 0%).
  • Human-written feedback addresses more bugs and is more informative than InstructGPT feedback, contributing to higher gains.
  • Training with a small set of human-written refinements can yield competitive improvements, and ILF can be effective with relatively few feedback samples (total 122 pieces).
  • ILF can be viewed as a practical, sample-efficient form of supervised learning that minimizes KL divergence to higher-quality code distributions.
Figure 2: An example of a zero-shot LLM prompt for repairing incorrect code based on human-written feedback.
Figure 2: An example of a zero-shot LLM prompt for repairing incorrect code based on human-written feedback.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.