Semi-Instruct: Bridging Natural-Instruct and Self-Instruct for Code Large Language Models

Xianzhen Luo,Qingfu Zhu,Zhiming Zhang,Xu Wang,Qing Yang,Dongliang Xu,Wanxiang Che
2024-03-01
Abstract:Instruction tuning plays a pivotal role in Code Large Language Models (Code LLMs) for the task of program synthesis. Presently, two dominant paradigms for collecting tuning data are natural-instruct (human-written) and self-instruct (automatically generated). Natural-instruct includes diverse and correct codes but lacks instruction-code pairs, and exists improper code formats like nested single-line codes. In contrast, self-instruct automatically generates proper paired data. However, it suffers from low diversity due to generating duplicates and cannot ensure the correctness of codes. To bridge the both paradigms, we propose \textbf{Semi-Instruct}. It first converts diverse but improper codes from natural-instruct into proper instruction-code pairs through a method similar to self-instruct. To verify the correctness of generated codes, we design a novel way to construct test cases by generating cases' inputs and executing correct codes from natural-instruct to get outputs. Finally, diverse and correct instruction-code pairs are retained for instruction tuning. Experiments show that semi-instruct is significantly better than natural-instruct and self-instruct. Furthermore, the performance steadily improves as data scale increases.
Computation and Language
What problem does this paper attempt to address?
### Problems the Paper Aims to Solve This paper aims to address the issue of instruction tuning in code generation large language models (Code LLMs) for program synthesis tasks. Currently, there are two main methods for collecting tuning data: Natural-Instruct (NI) and Self-Instruct (SI). Each of these methods has its own advantages and disadvantages: 1. **Natural-Instruct (NI)**: - **Advantages**: Includes diverse and correct code, usually sourced from platforms like GitHub and Codeforces, carefully selected to ensure code correctness. - **Disadvantages**: Contains non-standard code formats (such as nested single-line code) and lacks high-quality instruction-code pairs. 2. **Self-Instruct (SI)**: - **Advantages**: Can automatically generate standardized instruction-code pairs without human intervention. - **Disadvantages**: The generated data has low diversity, is prone to duplication, and cannot guarantee the correctness of the generated code. To combine the advantages of these two methods, the paper proposes a new method—**Semi-Supervised Instruction (Semi-Instruct, SemI)**. Specifically, SemI is implemented through the following steps: 1. **Generation**: Starting from the original code, use large language models (LLMs) to generate corresponding instructions, test case inputs, and refined code. 2. **Validation**: Execute the original code to obtain the output of the test cases, thereby verifying the correctness of the refined code. Only retain the refined code that passes all test cases. 3. **Ranking**: Rank the generated data based on the number of test cases, with fewer cases indicating more difficult instructions, thus achieving a curriculum learning effect. Through this method, SemI not only addresses the issues of non-standard code formats and lack of high-quality instruction-code pairs in NI but also overcomes the low data diversity and uncertain code correctness in SI. Experimental results show that SemI significantly outperforms NI and SI across multiple data scales, with performance steadily improving as the data volume increases.