TL;DR
This paper introduces InstructCoder, the first large-scale dataset for instruction-tuning Large Language Models (LLMs) specifically for code editing tasks. By fine-tuning on InstructCoder, open-source LLMs achieve code editing accuracy comparable to advanced proprietary models, demonstrating the critical role of instruction tuning for this challenging domain.
What Problem Does This Paper Address?
Developers spend a significant portion of their time editing code, performing tasks like optimization, refactoring, and bug fixing. While LLMs have shown promise in code generation and completion, their ability to perform nuanced code edits based on natural language instructions remains an underexplored area. This is largely due to a scarcity of high-quality, diverse datasets that capture the complexities of code editing. Existing benchmarks often fall short, and current LLMs struggle to accurately follow instructions and modify code while preserving its functionality.
Methods
The authors tackle this problem by creating a new dataset and evaluating LLMs on a novel benchmark.
- InstructCoder Dataset Creation: They employ a Self-Instruct-like approach, starting with filtered GitHub commit data as seed tasks. These seeds are then used to prompt ChatGPT to generate new instructions, input code, and corresponding output code. A key innovation is the introduction of scenario-conditional generation, where specific real-world scenarios are provided to guide the generation process, ensuring more diverse and contextually relevant code edits. This iterative process, combined with manual curation and deduplication, results in over 114,000 instruction-input-output triplets covering a wide array of code editing tasks.
- EditEval Benchmark: To rigorously evaluate code editing capabilities, the authors introduce EditEval, a novel benchmark consisting of 194 code editing tasks. These tasks are derived from GitHub commits, MBPP, and HumanEval, and are accompanied by human-written solutions. Edits are considered correct only if they pass all automated test cases, providing an objective evaluation metric.
Datasets
- InstructCoder: A newly introduced dataset of over 114,000 instruction-input-output triplets for general-purpose code editing.
- EditEval: A new benchmark dataset for evaluating code editing models, comprising 194 tasks.
- GitHub Commit Data: Used as initial seed data for InstructCoder.
- MBPP and HumanEval: Datasets that contributed to the creation of EditEval.
Key Insights and Ideas
- Code Editing is Distinct from Code Completion: The paper emphasizes that code editing requires not just generating code but also understanding existing code, following instructions precisely, and ensuring the modified code remains functional and integrated within its context.
- Instruction Tuning is Crucial for Code Editing: Fine-tuning LLMs on the InstructCoder dataset significantly boosts their code editing accuracy, highlighting the importance of explicit instruction following for this task.
- Scenario-Conditional Generation Enhances Data Quality: Incorporating real-world scenarios during dataset generation leads to more diverse, contextually relevant, and higher-quality code editing examples compared to those generated without scenarios.
- Open-Source LLMs Can Compete: With proper instruction tuning on datasets like InstructCoder, open-source LLMs can achieve performance levels comparable to advanced proprietary models, democratizing access to powerful code editing capabilities.
Key Results
- LLMs fine-tuned on InstructCoder show significant improvements in code editing accuracy on the EditEval benchmark.
- Code LLaMA 13B, fine-tuned with InstructCoder, achieved an accuracy of 57.22%, closely matching ChatGPT.
- GPT-4 achieved the highest performance on EditEval at 68.56%, while ChatGPT scored 57.73% in zero-shot settings.
- The quality and volume of instruction-tuning data are critical factors influencing code editing performance.
- Fine-tuning with InstructCoder significantly outperformed using raw GitHub commits for training, especially on larger models.
Limitations and Future Work
- Multi-file Contexts: The current approach does not encompass code changes involving multiple files, which is a common scenario in real-world development. The authors hope to explore this in future work.
- Language Support: The current dataset and evaluation focus primarily on Python. Expanding to other programming languages is a potential future direction.
- Dataset Scale: While InstructCoder is large, the authors suggest that larger datasets could lead to further improvements, especially for larger models.
Summary updated