Coeditor:利用上下文变更进行多轮代码自动编辑
Coeditor: Leveraging Contextual Changes for Multi-round Code Auto-editing
AI总结:
本文提出专为代码编辑任务微调的语言模型 Coeditor,通过行 diff 格式和静态分析构建上下文,基于代码库近期变更预测代码编辑,在单轮与多轮编辑任务中显著超越 GPT-3.5 等模型。
摘要:
开发者常耗费大量时间维护和重构现有代码。然而,以往关于代码生成模型的研究多聚焦于创建新代码,忽视了编辑现有代码的特殊需求。本文探索了一种多轮代码自动编辑设置,旨在基于同一代码库内的近期变更预测对某代码区域的编辑。我们的模型 Coeditor 是专门为代码编辑任务微调的语言模型。我们使用行 diff 格式表示代码变更,并利用静态分析构建大规模定制化模型上下文,以确保预测时具备适当信息。我们从 1650 个开源 Python 项目的提交历史中收集了代码编辑数据集,用于训练和评估。在简化的单轮单编辑任务中,Coeditor 显著优于 GPT-3.5 和 SOTA 开源代码补全模型(将精确匹配准确率从 34.7 提升至 60.4),证明了融入编辑历史对代码补全的益处。在多轮多编辑设置中,我们通过迭代地基于额外用户编辑进行条件化,观察到显著提升。我们已开源代码、数据和模型权重以鼓励未来研究,并发布了由该模型驱动的 VSCode 扩展,用于交互式 IDE 使用。
英文摘要:
Developers often dedicate significant time to maintaining and refactoring existing code. However, most prior work on generative models for code focuses solely on creating new code, overlooking the distinctive needs of editing existing code. In this work, we explore a multi-round code auto-editing setting, aiming to predict edits to a code region based on recent changes within the same codebase. Our model, Coeditor, is a fine-tuned language model specifically designed for code editing tasks. We represent code changes using a line diff format and employ static analysis to form large customized model contexts, ensuring the availability of appropriate information for prediction. We collect a code editing dataset from the commit histories of 1650 open-source Python projects for training and evaluation. In a simplified single-round, single-edit task, Coeditor significantly outperforms GPT-3.5 and SOTA open-source code completion models (bringing exact-match accuracy from 34.7 up to 60.4), demonstrating the benefits of incorporating editing history for code completion. In a multi-round, multi-edit setting, we observe substantial gains by iteratively conditioning on additional user edits. We have open-sourced our code, data, and model weights to encourage future research and have released a VSCode extension powered by our model for interactive IDE usage.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。