NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

SelfEvolve: A Code Evolution Framework via Large Language Models

Shuyang Jiang, Yuhao Wang, Yu Wang 0027arXiv 2023 · DOI

Introduction

Large Language Models (LLMs) have revolutionized software development, yet they frequently encounter hurdles when generating code for complex logic or specialized libraries. Traditional approaches often rely on Retrieval-Augmented Generation (RAG) to provide external documentation. However, these methods frequently suffer from a "reasoning gap," where retrievers fail to accurately map natural language queries to technical documentation. Researchers from Shanghai Jiao Tong University and Shanghai AI Laboratory have proposed SELFEVOLVE, a novel framework that empowers LLMs to become self-sufficient by generating their own task-specific knowledge and iteratively refining code through real-time feedback.

The SELFEVOLVE Framework

SELFEVOLVE operates as a two-stage, zero-shot pipeline designed to bridge the gap between model training and specific task requirements without the need for external databases or fine-tuning.

The SELFEVOLVE framework pipeline, illustrating the two-stage process of knowledge generation and iterative code refinement.

1. Self-Augmented Knowledge Generation

In the first stage, the framework prompts the LLM to externalize its internal knowledge before attempting to write code. By generating API specifications or algorithmic steps relevant to the problem first, the model establishes a factual context. This "pre-coding" step significantly reduces hallucinations, as the model is forced to reason about the required tools before applying them.

2. Iterative Self-Refinement

The second stage mimics the workflow of a human developer. Once the initial code is generated, it is executed within a Python interpreter. If the code fails, the model receives the resulting traceback or error message. Using this feedback, along with example cases provided in the problem description, the model iteratively "evolves" the code until it passes. This process ensures that the final output is not only syntactically correct but also functionally sound.

Experimental Evaluation

The researchers evaluated SELFEVOLVE across three major benchmarks:

  • DS-1000: 1,000 data science problems involving libraries like Pandas, NumPy, and Scipy.
  • HumanEval: Standard algorithmic tasks in Python.
  • TransCoder: C++ to Python code translation.

Key Results and Insights

SELFEVOLVE demonstrated substantial performance gains across all evaluated datasets. On the DS-1000 benchmark, it achieved a 57.10% Pass@1 score, outperforming the base ChatGPT model (49.30%) and the previous state-of-the-art "Self-Debugging" method (53.00%).

Performance comparison on the DS-1000 benchmark across various perturbations, demonstrating SELFEVOLVE's superiority over prior work.

A critical insight from the study is that LLMs often serve as better "retrievers" of their own internal knowledge than specialized external models. By bridging the semantic gap between user intent and technical terminology internally, the LLM provides more relevant context for code generation. Furthermore, the study highlights that simple interpreter feedback (e.g., tracebacks) provides a sufficiently strong signal for high-capacity models to correct their own logic without needing exhaustive unit tests.

Conclusion

SELFEVOLVE represents a significant step toward self-sufficient AI programming. By combining self-augmented knowledge generation with iterative refinement, the framework overcomes the limitations of traditional RAG and one-turn generation. While future work may focus on optimizing prompt engineering and knowledge filtering, SELFEVOLVE currently provides a robust, zero-shot solution for enhancing the coding capabilities of Large Language Models.

Summary updated

BibTeX
@misc{jiang2023selfevolve,
  author = {Shuyang Jiang and Yuhao Wang and Yu Wang},
  title = {{SelfEvolve: A Code Evolution Framework via Large Language Models}},
  year = {2023},
  eprint = {2306.02907},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2306.02907},
}
Figure