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, covering a broad range of implicit tasks such as comment insertion, code optimization, and code refactoring. To facilitate this, we introduce InstructCoder, the first dataset designed to adapt LLMs for general-purpose code editing, containing highdiversity code-editing tasks. It consists of over 114,000 instruction-input-output triplets and covers multiple distinct code editing scenarios. The dataset is systematically expanded through an iterative process that commences with code editing data sourced from GitHub commits as seed tasks. Seed and generated tasks are used subsequently to prompt ChatGPT for more task data. Our experiments demonstrate that open-source LLMs fine-tuned on InstructCoder can edit code correctly based on users' instructions most of the time, exhibiting unprecedented code-editing performance levels. Such results suggest that proficient instruction-finetuning can lead to significant amelioration in code editing abilities. The dataset and the source code are available at https://github.com/qishenghu/CodeInstruct.
翻译:代码编辑涵盖了开发者日常处理的多种实际任务。尽管其具有相关性和实际用途,但在深度学习模型的发展中,自动代码编辑仍是一个探索不足的领域,部分原因在于数据稀缺。本文中,我们探索了利用大规模语言模型(LLM)根据用户指令编辑代码的方法,覆盖了包括注释插入、代码优化和代码重构在内的广泛隐性任务。为此,我们引入了InstructCoder,这是首个专为适配通用代码编辑而设计的LLM数据集,包含高多样性的代码编辑任务。该数据集包含超过11.4万个指令-输入-输出三元组,覆盖多种不同的代码编辑场景。数据集通过迭代过程系统性地扩展,该过程以从GitHub提交中提取的代码编辑数据作为种子任务,随后利用种子任务和生成的任务提示ChatGPT生成更多任务数据。实验表明,基于InstructCoder微调的开源LLM在大多数情况下能根据用户指令正确编辑代码,展现出前所未有的代码编辑性能水平。这些结果表明,熟练的指令微调能显著提升代码编辑能力。数据集和源代码可在https://github.com/qishenghu/CodeInstruct获取。