[论文解读] SelfEvolve: A Code Evolution Framework via Large Language Models
SelfEvolve 使用一个两步、LLM驱动的管线,模型首先生成自源知识来构建代码,然后通过解释器反馈循环对其进行改进,在 DS-1000、HumanEval 和 TransCoder 数据集上实现显著提升,并且在 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.
研究动机与目标
- 通过将 LLM 作为知识源和调试工具,激发超越基于检索的提示的稳健数据科学与软件工程代码生成能力。
- 通过使 LLM 能够从问题提示内部产生必要知识,移除对外部检索器的依赖。
- 通过使用 Python 解释器提供错误反馈的自动改进循环来提升代码的正确性与鲁棒性。
- 展示对更强大模型(如 GPT-4)以及多样化编程任务的可扩展性。
- 提供经验证据表明两阶段自我演化相较于强提示基线能够获得更优结果。
提出的方法
- 两个阶段的管线:LLM 先基于问题条件生成知识,然后基于该知识产生一个试验解。
- 知识生成使用提示从问题上下文提取必要信息,可能绕过外部检索器(Eq. 4/5)。
- 一个改进循环使用可运行的程序和解释器来产生错误反馈,促使 LLM 修订代码,直到代码无异常运行或达到迭代上限(Eq. 6)。
- 该方法在 DS-1000、HumanEval 和 TransCoder 基准测试上采用贪婪解码进行评估,并与 DocPrompting 与 Self-Debugging 基线进行比较。
- 该框架在 GPT-4 上显示出可扩展性,在若干库(如 Scipy、Pytorch、Sklearn、Matplotlib)和 HumanEval 上提升性能,迭代改进带来额外收益。
实验结果
研究问题
- RQ1一个两步、由 LLM 驱动的过程,生成自派生知识并通过解释器对代码进行改进,能否超越基于检索的提示基线?
- RQ2自生成的知识是否比检索得到的知识产生更高质量、具有更好泛化性的代码?
- RQ3自我改进循环如何与生成的知识互动以提升跨编码任务的性能?
- RQ4SelfEvolve 在多大程度上可以扩展到更强大的模型(如 GPT-4),覆盖 DS-1000、HumanEval 和 TransCoder 等数据集?
- RQ5改进循环中的迭代深度对不同难度任务的性能有何影响?
主要发现
- SelfEvolve 在 DS-1000 上优于强基线,pass@1 高于 Self-Debugging 和 DocPrompting。
- 在 HumanEval 上,SelfEvolve 与 ChatGPT 的组合在 pass@1 和 pass@10 上获得显著提升,接近 GPT-4 水平。
- 在基于 TransCoder 的 C++ 到 Python 翻译中,SelfEvolve 与 ChatGPT 在提示基线中实现最高的计算准确率和 pass@1。
- 与 GPT-4 的组合提升了 DS-1000 的库(Scipy、Pytorch、Sklearn、Matplotlib)和 HumanEval 的性能,并且自我改进模块带来额外增益。
- 自生成的知识在人工评估中表现出比检索知识更高的精准度和召回率,表明与问题语义更好对齐。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。