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 公开提供。