[论文解读] Towards Generating Functionally Correct Code Edits from Natural Language Issue Descriptions
本文提出了 Defects4J-Nl2fix,一个包含 283 个 Java 错误修复的基准数据集,这些修复均配有对所需代码更改的自然语言描述,用于评估大型语言模型(LLMs)生成功能正确代码编辑的能力。结果表明,当前最先进的 LLM 在此任务上的 top-1 准确率最高达到 21.20%,top-5 准确率达到 35.68%,凸显了 LLM 在基于自然语言意图进行代码修复方面的进展与局限性。
Large language models (LLMs), such as OpenAI's Codex, have demonstrated their potential to generate code from natural language descriptions across a wide range of programming tasks. Several benchmarks have recently emerged to evaluate the ability of LLMs to generate functionally correct code from natural language intent with respect to a set of hidden test cases. This has enabled the research community to identify significant and reproducible advancements in LLM capabilities. However, there is currently a lack of benchmark datasets for assessing the ability of LLMs to generate functionally correct code edits based on natural language descriptions of intended changes. This paper aims to address this gap by motivating the problem NL2Fix of translating natural language descriptions of code changes (namely bug fixes described in Issue reports in repositories) into correct code fixes. To this end, we introduce Defects4J-NL2Fix, a dataset of 283 Java programs from the popular Defects4J dataset augmented with high-level descriptions of bug fixes, and empirically evaluate the performance of several state-of-the-art LLMs for the this task. Results show that these LLMS together are capable of generating plausible fixes for 64.6% of the bugs, and the best LLM-based technique can achieve up to 21.20% top-1 and 35.68% top-5 accuracy on this benchmark.
研究动机与目标
- 为解决缺乏用于评估 LLM 从自然语言描述生成功能正确代码编辑的基准的问题。
- 提出 Defects4J-Nl2fix,一个包含 283 个真实世界 Java 错误修复的语料库,附带对预期更改的高层次自然语言描述。
- 使用隐藏回归测试和触发测试,评估最先进的 LLM 在 nl2fix 任务上的表现——即从问题描述生成正确的代码补丁。
- 通过仅使用隐藏测试套件,将此任务与自动化程序修复(APR)区分开来,以模拟真实世界 CI 环境中测试运行成本较高的情况。
提出的方法
- 从 Jira 问题报告中提取自然语言描述,对 Defects4J 数据集进行扩充,重点关注局部化的方法级更改。
- 构建一个提示模板,将存在错误的方法、自然语言问题描述以及系统指令相结合,以指导 LLM 生成候选代码补丁。
- 使用隐藏触发测试验证生成的补丁是否修复了特定缺陷,使用隐藏回归测试确保未引入新的回归问题。
- 使用两个指标评估 LLM 生成的补丁:top-1 准确率(第一个生成的补丁是否正确)和 top-5 准确率(正确补丁是否出现在前五个输出中)。
- 在固定提示和测试集的受控条件下,将评估流程应用于多个最先进的 LLM,包括 Codex 和 GPT-3.5-turbo。

实验结果
研究问题
- RQ1当使用来自真实世界问题报告的自然语言描述作为提示时,现有大型语言模型能否生成功能正确的代码编辑?
- RQ2LLM 在 nl2fix 任务上的表现如何随不同模型架构和温度设置而变化?
- RQ3LLM 生成的补丁在修复缺陷的同时,其功能保持程度如何,通过隐藏回归测试衡量?
- RQ4在使用隐藏测试套件的前提下,LLM 在 nl2fix 上的表现与传统自动化程序修复(APR)技术相比如何?
主要发现
- 表现最佳的 LLM 在 Defects4J-Nl2fix 基准上实现了 21.20% 的 top-1 准确率和 35.68% 的 top-5 准确率,表明尽管已有进展,但仍存在显著的改进空间。
- 总体而言,LLM 对数据集中 283 个错误中的 64.6% 生成了合理的修复方案,展示了其在理解并响应自然语言更改请求方面的非平凡能力。
- LLM 的表现因模型而异,其中基于 Codex 的模型在 top-1 和 top-5 准确率上均优于 GPT-3.5-turbo。
- 使用仅在评估期间可访问的隐藏测试套件,确保了对功能正确性的现实评估,使本基准与依赖已知测试套件的传统 APR 任务区分开来。
- 研究发现,LLM 常常生成语法正确但语义错误的补丁,凸显了从自然语言中推理程序行为的挑战。
- 结果表明,尽管 LLM 能够理解问题描述中的高层次意图,但在实现正确代码转换所必需的精确语义推理方面仍存在困难。

更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。