[Paper Review] Self-Edit: Fault-Aware Code Editor for Code Generation
This paper proposes Self-Edit, a generate-and-edit framework that improves code generation from large language models (LLMs) by executing generated code on example test cases and using execution feedback—wrapped as comments—to guide a fault-aware neural code editor. The method boosts pass@1 accuracy by 89% on APPS-dev and 48% on HumanEval across nine LLMs, outperforming both direct generation and reranking-based post-processing methods with lower computational cost.
Large language models (LLMs) have demonstrated an impressive ability to generate codes on competitive programming tasks. However, with limited sample numbers, LLMs still suffer from poor accuracy. Inspired by the process of human programming, we propose a generate-and-edit approach named Self-Edit that utilizes execution results of the generated code from LLMs to improve the code quality on the competitive programming task. We execute the generated code on the example test case provided in the question and wrap execution results into a supplementary comment. Utilizing this comment as guidance, our fault-aware code editor is employed to correct errors in the generated code. We perform extensive evaluations across two competitive programming datasets with nine different LLMs. Compared to directly generating from LLMs, our approach can improve the average of pass@1 by 89\% on APPS-dev, 31\% on APPS-test, and 48\% on HumanEval over nine popular code generation LLMs with parameter sizes ranging from 110M to 175B. Compared to other post-processing methods, our method demonstrates superior accuracy and efficiency.
Motivation & Objective
- To address the low accuracy of LLMs in competitive programming, where pass@1 rates remain under 10% on standard benchmarks.
- To mimic human programming workflows by generating, executing, and iteratively refining code using feedback from test case execution.
- To develop a lightweight, fault-aware code editor that improves code quality using execution results as guidance.
- To demonstrate the effectiveness and efficiency of the generate-and-edit paradigm compared to existing post-processing methods like reranking.
- To evaluate generalization across diverse LLMs and out-of-distribution benchmarks such as HumanEval.
Proposed method
- Use a pre-trained LLM as a black-box code generator to produce initial programs from natural language problem descriptions.
- Execute the generated code on provided example test cases to collect runtime outputs and error messages.
- Wrap execution results into structured supplementary comments using templates to preserve diagnostic information.
- Train a fault-aware neural code editor to take the original code and supplementary comments as input and generate corrected code.
- Apply the editor in a single-round refinement step to improve code correctness without re-generating from scratch.
- Extend the framework using in-context learning with GPT-3 to enable zero-shot editing without fine-tuning.
Experimental results
Research questions
- RQ1Can execution feedback from example test cases significantly improve the pass@1 accuracy of LLM-generated code in competitive programming?
- RQ2How does the generate-and-edit pipeline compare to direct generation and reranking-based post-processing in terms of accuracy and efficiency?
- RQ3To what extent can a lightweight, fine-tuned code editor generalize across different LLMs and benchmarks?
- RQ4Can in-context learning with GPT-3 replicate the performance of a fine-tuned editor without additional training?
- RQ5How does the size and construction of the editor training dataset impact performance?
Key findings
- Self-Edit improves pass@1 by 89% on APPS-dev and 31% on APPS-test across nine LLMs, with the largest gain observed on smaller models.
- Even for GPT-3-175B, the method increases pass@1 from 26.6% to 32.4% on APPS-dev, demonstrating effectiveness on state-of-the-art models.
- On the out-of-distribution HumanEval benchmark, Self-Edit improves pass@1 by 48%, showing strong generalization capability.
- The method achieves superior accuracy with significantly fewer LLM calls and lower computational cost than state-of-the-art reranking baselines like CodeRanker.
- In-context learning self-edit using text-davinci-002 achieves strong performance comparable to fine-tuned editors, validating the zero-shot applicability of the framework.
- Ablation studies reveal a performance gap in multi-round editing due to current implementation limitations, suggesting room for architectural improvements.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.