扩散语言模型应如何编辑代码?
How Should Diffusion Language Models Edit Code?
- The University of Hong Kong(香港大学)
- Huawei Technologies Ltd.(华为技术有限公司)
- City University of Hong Kong(香港城市大学)
- Peking University(北京大学)
机构由 AI 辅助整理,请以论文原文为准。
AI总结:
本研究通过四种编辑界面比较掩码扩散语言模型的代码编辑能力,发现提供编辑位置时性能良好但预测位置时存在组合差距,强调界面需覆盖所有修改并限制未更改代码的重生成。
AI中文摘要:
代码编辑要求模型决定在哪里进行修改、生成新内容并保留其余部分。我们研究了掩码扩散语言模型如何在四种编辑界面中分配这些职责:整文件重写、搜索替换、定位后填充和令牌级编辑。在CanItEdit上的实验揭示了一个组合差距:当提供正确的编辑位置时,扩散模型能够生成协调的修改,但当这些位置必须被预测时,这种能力的大部分会丧失。访问完整的原始代码有助于模型填充多个编辑区域,但并不能解决选择这些区域的困难。在保持生成模型和解码过程固定的情况下,通过改变可编辑区域,我们识别出成功编辑的两个不同要求:覆盖每个必要的修改并为其设置精确的边界。遗漏一个必需区域会阻止相应的修改,而扩大区域以确保覆盖可能因需要重新生成未更改的代码而急剧降低成功率。一个句子级的Wiki编辑探针显示,在代码之外,提供的位置与预测的位置之间存在相同的定性差距。这些发现解释了为什么强大的填充能力本身并不能确保可靠的编辑:界面必须暴露所有必需的修改,同时限制未更改代码的重新生成。
英文摘要:
Code editing requires a model to decide where to make changes, generate the new content, and preserve everything else. We study how masked diffusion language models divide these responsibilities across four editing interfaces: whole-file rewriting, search-and-replace, locate-then-infill, and token-level editing. Experiments on CanItEdit reveal a composition gap: diffusion models can generate coordinated changes when the correct edit locations are supplied, but much of this capability is lost when those locations must be predicted. Access to the intact original code helps the model fill multiple edit regions, yet does not resolve the difficulty of selecting those regions. By varying the editable regions while holding the generation model and decoding procedure fixed, we identify two distinct requirements for successful editing: covering every required change and placing precise boundaries around it. Missing a required region prevents the corresponding change, while widening regions to ensure coverage can sharply reduce success by requiring unchanged code to be regenerated. A sentence-level Wiki editing probe shows the same qualitative gap between supplied and predicted locations beyond code. These findings show why strong infilling capability alone does not ensure reliable editing: the interface must expose all required changes while limiting regeneration of unchanged code.