[Paper Review] SelfEvolve: A Code Evolution Framework via Large Language Models
SelfEvolve uses a two-step, LLM-driven pipeline where the model first generates self-sourced knowledge to build code, then refines it via an interpreter feedback loop, achieving strong gains across DS-1000, HumanEval, and TransCoder datasets and scalable improvements with GPT-4.
Large language models (LLMs) have already revolutionized code generation, after being pretrained on publicly available code data. However, while various methods have been proposed to augment LLMs with retrieved knowledge and enhance the quality of code generation, the performance of these retrieval-based methods is limited by the strength of the retrievers used. In addition, while LLMs show great emergent ability, they still struggle to produce the correct code in one turn. To address these challenges, we propose a novel two-step pipeline, called \autoknow, that leverages LLMs as both knowledge providers and self-reflective programmers. Unlike retrieval-based methods, \autoknow~obtains the knowledge from input prompts and generates intermediate code based on the generated knowledge. After that, \autoknow~asks LLM to act as an expert programmer to perform debugging for the generated code. This is achieved by receiving the error message from the interpreter, without requiring special test cases for correctness verification. We evaluate \autoknow~on three code generation datasets, including DS-1000 for data science code, HumanEval for software engineering code, and TransCoder for C++-to-Python translation. Our empirical experiments show that \autoknow~outperforms strong baselines by a significant margin on all datasets. We also conduct exhaustive analytical experiments to validate the effectiveness of the two stages of \autoknow, and find that both are superior to other prompting-based methods. Further scalability analysis demonstrates that \autoknow~can be adapted to other more advanced models, such as GPT-4, and bring consistent efficacy improvement.
Motivation & Objective
- Motivate robust data science and software engineering code generation beyond retrieval-based prompts by leveraging LLMs as both knowledge sources and debuggers.
- Remove dependence on external retrievers by enabling the LLM to produce necessary knowledge internally from problem prompts.
- Improve code correctness and robustness through an automatic refinement loop using a Python interpreter to provide error feedback.
- Demonstrate scalability to more capable models (e.g., GPT-4) and across diverse programming tasks.
- Provide empirical evidence that two-stage self-evolution yields superior results compared to strong prompting baselines.
Proposed method
- Two-stage pipeline where the LLM first generates knowledge conditioned on the problem, then produces a trial solution based on that knowledge.
- Knowledge generation uses prompts to extract necessary information from the problem context, potentially bypassing external retrievers (Eq. 4/5).
- A refinement loop uses a runnable program and an interpreter to produce error feedback, prompting the LLM to revise the code until it runs without exceptions or a iteration limit is reached (Eq. 6).
- The approach is evaluated with greedy decoding on DS-1000, HumanEval, and TransCoder benchmarks, comparing against DocPrompting and Self-Debugging baselines.
- The framework is shown to scale with GPT-4, improving performance on several libraries and HumanEval, with iterative refinement contributing additional gains.
Experimental results
Research questions
- RQ1Can a two-step, LLM-driven process that generates self-derived knowledge and refines code via an interpreter outperform retrieval-based prompting baselines?
- RQ2Does self-generated knowledge yield higher quality and more generalizable code than retrieved knowledge?
- RQ3How does the self-refinement loop interact with generated knowledge to improve performance across coding tasks?
- RQ4To what extent can SelfEvolve scale to more powerful models like GPT-4 across datasets such as DS-1000, HumanEval, and TransCoder?
- RQ5What is the impact of iteration depth in the refinement loop on performance across varying task difficulties?
Key findings
- SelfEvolve outperforms strong baselines on DS-1000, achieving a higher pass@1 than Self-Debugging and DocPrompting.
- On HumanEval, SelfEvolve with ChatGPT yields a substantial gain in pass@1 and pass@10, approaching GPT-4 levels.
- In TransCoder-based C++ to Python translation, SelfEvolve with ChatGPT achieves the highest computational accuracy and pass@1 among prompting baselines.
- Ensemble with GPT-4 boosts performance across DS-1000 libraries (Scipy, Pytorch, Sklearn, Matplotlib) and HumanEval, with additional gains from the self-refinement module.
- Self-generated knowledge demonstrates higher precision and recall than retrieved knowledge in a human evaluation, indicating better alignment with problem semantics.
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.