Code editing encompasses a variety of pragmatic tasks that developers deal with daily. Despite its relevance and practical usefulness, automatic code editing remains an underexplored area in the evolution of deep learning models, partly due to data scarcity. In this work, we explore the use of Large Language Models (LLMs) to edit code based on user instructions. Evaluated on a novel human-written execution-based benchmark dubbed EditEval, we found current models often struggle to fulfill the instructions. In light of this, we contribute InstructCoder, the first instruction-tuning dataset designed to adapt LLMs for general-purpose code editing, containing high-diversity code-editing tasks such as comment insertion, code optimization, and code refactoring. It consists of over 114,000 instruction-input-output triplets and covers multiple distinct code editing scenarios. The collection process starts with filtered commit data sourced from GitHub Python repositories as seeds. Subsequently, the dataset is systematically expanded through an iterative process, where both seed and generated tasks are used to prompt ChatGPT for more data. Our findings reveal that open-source LLMs fine-tuned on InstructCoder can significantly enhance the accuracy of code edits, exhibiting superior code-editing performance matching advanced proprietary LLMs. The datasets and the source code are publicly available at https://github.com/qishenghu/CodeInstruct.
翻译:代码编辑涵盖了开发人员日常处理的多种实用任务。尽管其具有相关性和实际用途,但在深度学习模型的发展中,自动代码编辑仍是一个尚未充分探索的领域,部分原因在于数据稀缺。在本工作中,我们探索了使用大型语言模型(LLMs)根据用户指令编辑代码。在一个名为EditEval的新型人工编写且基于执行的基准测试上进行评估后,我们发现当前模型通常难以完成指令。鉴于此,我们贡献了InstructCoder,这是首个旨在使LLMs适应通用代码编辑的指令微调数据集,包含高多样性的代码编辑任务,例如注释插入、代码优化和代码重构。它由超过114,000个指令-输入-输出三元组组成,并涵盖多个不同的代码编辑场景。数据集的收集过程从来自GitHub Python仓库的过滤提交数据作为种子开始。随后,通过迭代过程系统地扩展数据集,其中种子任务和生成的任务均用于提示ChatGPT以获取更多数据。我们的研究结果表明,在InstructCoder上微调的开源LLMs能够显著提升代码编辑的准确性,展现出与先进专有LLMs相匹配的卓越代码编辑性能。该数据集和源代码可在https://github.com/qishenghu/CodeInstruct公开获取。