Instruction fine-tuning model system for code generation and method thereof

CN122924735APending Publication Date: 2026-10-16DEZHOU POWER SUPPLY COMPANY OF STATE GRID SHANDONG ELECTRIC POWER +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510444990.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-09
Publication Date
2026-10-16

AI Technical Summary

Technical Problem

[0007]综上所述,现有的代码生成模型在多样性和正确性方面存在明显的不足,这些问题在一定程度上限制了代码生成技术的广泛应用和发展

Benefits of technology

[0025]4.代码生成:通过多样性指令微调后的模型进行代码生成,并在生成过程中结合自评估模块的反馈,对生成结果进行优化。通过这种方式,生成的代码不仅具有较高的准确性,还能涵盖多种可能的解决方案。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122924735A_ABST
    Figure CN122924735A_ABST
Patent Text Reader

Abstract

The present application relates to a kind of instruction fine-tuning model system and its method for code generation, belong to artificial intelligence and code generation field.The system improves the diversity and correctness of code generation model by the combination of diversity instruction fine-tuning and self-evaluation module.Firstly, the system generates multiple code solutions with different reasoning paths using different system prompts, ensuring the diversity of generated code;Then, the self-evaluation module is used to evaluate the syntax, logic and efficiency of the generated code, and further optimize the code generation capability based on the evaluation results.The system uses a multi-task learning framework to combine the code generation task with the code evaluation task, and improves the overall performance of the model in code generation and evaluation through joint training.The present application significantly improves the accuracy and diversity of code generation model, especially in complex code generation tasks, and can be widely used in code automatic generation, program design assistance and other fields.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence, particularly the application of Natural Language Processing (NLP) and Machine Learning (ML) in code generation tasks. With the rapid development of AI technology, Large Language Models (LLMs) have demonstrated superior performance in various NLP tasks, among which code generation, as an important application, has received widespread attention. Code generation aims to automatically transform programming requirements described in natural language into executable code through models, which has significant practical implications for improving software development efficiency, lowering the programming threshold, and assisting programming education. However, existing code generation models still face many challenges in practical applications, such as insufficient diversity of generated code and difficulty in identifying potential subtle errors. Therefore, this invention focuses on how to improve the diversity and correctness of code generation models through innovative model architectures and methods to better meet the complex needs of real-world programming scenarios and promote the further development and application of code generation technology in the field of artificial intelligence. Background Technology

[0002] With the rapid development of artificial intelligence technology, large language models (LLMs) have demonstrated enormous potential in numerous fields, especially in natural language processing (NLP) and code generation tasks. In recent years, code-based LLMs have emerged continuously. These models, by learning from large amounts of code data, are able to generate code snippets with certain syntactic and logical structures, bringing new possibilities for automated and assisted programming. However, existing code generation models still face some unresolved issues in practical applications, which to some extent limit the widespread application and development of code generation technology.

[0003] On the one hand, existing models typically focus on a single correct answer when generating code, ignoring the diversity of possible solutions. In real-world programming scenarios, a problem often has multiple solutions, each with its own advantages in terms of code structure, algorithm efficiency, and readability. However, traditional code generation models often only generate one or a few fixed code patterns, making the generated code inflexible and incomplete when facing complex and ever-changing programming needs. For example, when solving an algorithmic problem, there may be multiple different algorithmic approaches, but existing models often only generate a common algorithm implementation, failing to provide other possible, better solutions. This singular generation pattern not only limits the programmer's thinking but may also lead to the inability to find the most suitable code implementation for a specific problem in certain situations.

[0004] On the other hand, while code snippets generated by current models may be syntactically and logically correct, they often fail to identify potential subtle errors. In actual programming, code correctness depends not only on its syntactic and logical correctness but also on many other factors, such as boundary condition handling, exception handling, and performance optimization. Existing models often focus only on the surface structure of the code when generating it, lacking a deep understanding and detection capability for these potential problems. For example, the generated code may run normally under normal circumstances but exhibit errors or abnormal behavior under certain special input conditions, and the model cannot identify and correct these problems. Furthermore, existing models also struggle to adequately consider code readability and maintainability when generating code; the generated code may be structurally complex and difficult to understand, posing challenges for subsequent code maintenance and expansion.

[0005] In addition to the issues mentioned above, existing code generation models also have some shortcomings in the training and optimization process. Most models employ a single pre-training objective, such as maximum likelihood estimation (MLE). While this training method allows the model to learn the syntax and logical structure of the code to some extent, it fails to fully exploit the rich semantic information and potential code patterns within the code data. Furthermore, existing models lack effective feedback mechanisms during training, making it impossible to dynamically adjust and optimize based on the quality and performance of the generated code. This also negatively impacts the model's generation effectiveness and performance.

[0006] To address these issues and improve the diversity and correctness of generated code, researchers have conducted extensive exploration and research. Some studies have attempted to enhance the semantic understanding and generation capabilities of models by introducing external knowledge bases or datasets, but these methods often require significant additional resources and computational costs, and the results are not ideal. Other studies have tried to improve model performance by refining model architecture or training algorithms, but these methods often lead to a decrease in the correctness of generated code while increasing the diversity of generated code, or vice versa. Therefore, how to maintain the diversity of generated code while improving its correctness and performance has become a critical problem that urgently needs to be solved.

[0007] In summary, existing code generation models suffer from significant shortcomings in terms of diversity and accuracy, which to some extent limit the widespread application and development of code generation technology. Therefore, this invention proposes an instruction fine-tuning model system and method for code generation, aiming to address the problems of insufficient diversity and low accuracy in existing models through innovative model architecture and training methods, thereby promoting the further development and application of code generation technology in the field of artificial intelligence. Summary of the Invention

[0008] To address the shortcomings of existing code generation models in terms of diversity and correctness, this invention proposes an instruction fine-tuning model system and method for code generation. This system and method significantly improve code generation capability and correctness through the organic combination of diverse instruction fine-tuning, self-evaluation, and multi-objective learning, especially excelling in handling complex code generation tasks.

[0009] The system of this invention mainly includes the following key modules:

[0010] Diverse instruction fine-tuning module

[0011] The diversity instruction fine-tuning module is one of the core components of this invention. This module guides the model to generate diverse code solutions by using different system prompts. Specifically, system prompts are carefully designed instructions that inspire the model to solve problems from different perspectives and reasoning paths. For example, for the same programming task, system prompts may include different algorithmic approaches, coding style requirements (such as object-oriented or procedural programming styles), and performance optimization goals (such as optimization of time or space complexity). In this way, the model can generate multiple different code implementations to meet the needs of different users.

[0012] To further improve the quality and diversity of the generated code, the diversity instruction fine-tuning module also employs heuristic rules to filter low-quality and similar data. These heuristic rules can be evaluated based on multiple dimensions such as code syntax structure, logical complexity, and similarity. For example, by detecting the similarity between code snippets, highly similar code is removed, thus ensuring sufficient diversity in the generated code. Simultaneously, by evaluating the syntactic integrity and logical rationality of the code, code snippets that clearly violate programming standards or contain logical errors are filtered out. Ultimately, the filtered code data forms a high-quality, diverse code instruction dataset, providing rich training material for subsequent model training.

[0013] The self-evaluation module is another important innovation of this invention. Its main function is to self-evaluate the generated code and determine its correctness. Specifically, the self-evaluation module utilizes a pre-trained model to perform a multi-dimensional evaluation of the generated code through a natural language generation task. These evaluation dimensions include, but are not limited to, the code's syntactic correctness, logical rationality, execution efficiency, and compliance with specific programming standards.

[0014] During the self-evaluation process, the model analyzes and evaluates the generated code line by line according to preset evaluation criteria. For example, for syntactic correctness, the model checks whether the code conforms to the syntax rules of the specific programming language and whether there are spelling errors, syntax errors, or other issues. For logical rationality, the model analyzes the logical structure of the code to determine whether the code can correctly achieve the expected function and whether there are logical loopholes or potential errors. For execution efficiency, the model evaluates the algorithm complexity, resource consumption, etc., to determine whether the code can complete the task within a reasonable time and whether it has good performance. Through these multi-dimensional evaluations, the model can output a comprehensive evaluation result to determine whether the code passes the evaluation. The self-evaluation module can not only evaluate the generated code but also provide feedback information based on the evaluation results. This feedback information can be used to guide the optimization and improvement of the model. For example, if the evaluation result shows that the generated code has syntax errors, the model can adjust the generation strategy based on the feedback information to avoid similar problems in subsequent generation; if the evaluation result shows that the code has low execution efficiency, the model can try to use more efficient algorithms or optimization techniques to improve the code. In this way, the self-evaluation module can effectively improve the model's generation capability and code quality.

[0015] Multi-objective learning module

[0016] The multi-objective learning module is another key component of this invention. Its main function is to combine code generation and code evaluation tasks, training both tasks simultaneously using a multi-task learning approach. Specifically, by sharing model parameters and feature representations, the multi-objective learning module enables the model to learn code generation and code evaluation capabilities simultaneously. This multi-task learning approach not only improves the model's generation capabilities but also enhances its evaluation capabilities, thereby achieving synergistic optimization of code generation and code evaluation.

[0017] In the multi-objective learning module, training begins on a code evaluation task. Through extensive labeled data, the model learns the standards and rules for code evaluation, thus acquiring the ability to accurately evaluate code. Then, fine-tuning continues on diverse instruction data. During fine-tuning, the model not only learns diverse code generation methods but also optimizes and improves the generated code based on feedback from the self-evaluation module. In this way, the model can ensure the correctness and quality of the generated code while generating diverse code.

[0018] Code generator

[0019] The code generator is the core component of the system of this invention, responsible for generating code based on a pre-trained code model. During the generation process, the code generator fully utilizes the capabilities of the diversity instruction fine-tuning module and the self-evaluation module, combined with the optimization results of the multi-objective learning module, to generate high-quality code. Specifically, after receiving the programming requirements input by the user, the code generator first generates multiple code solutions with different reasoning paths through the diversity instruction fine-tuning module. Then, the self-evaluation module evaluates the generated code and selects the optimal code solution based on the evaluation results. Finally, the code generator outputs the generated code to the user.

[0020] To further improve the quality and diversity of generated code, the code generator employs various optimization techniques during the generation process. For example, by incorporating contextual information, the model can better understand user needs and generate code that better matches user intent; by adopting a probabilistic generation strategy, the model can generate multiple different code implementations to meet the needs of diverse users. Furthermore, the code generator can dynamically adjust its generation strategy based on user feedback, further enhancing the quality of generated code and the user experience.

[0021] The method of the present invention includes the following steps:

[0022] 1. Diverse Instruction Fine-tuning: Employing a multi-system prompt-based approach, multiple code solutions with different reasoning paths are generated. Carefully designed system prompts guide the model to solve problems from different angles and reasoning paths, thus generating diverse code solutions. Simultaneously, heuristic rules are used to filter low-quality and similar data, ultimately forming a high-quality, diverse code instruction dataset.

[0023] 2. Self-Evaluation: The generated code is self-evaluated using a pre-trained model. Through a natural language generation task, the model assesses the code's syntax, logic, and execution efficiency, outputting a pass or fail result. Based on the evaluation results, the model can optimize and improve the generated code, thereby enhancing its quality and correctness.

[0024] 3. Multi-objective learning: This approach combines code generation and code evaluation tasks, training both tasks simultaneously using a multi-task learning method. First, the model is trained on the code evaluation task, then fine-tuned on diverse instruction data to improve overall model performance.

[0025] 4. Code Generation: Code is generated using a model fine-tuned with diverse instructions, and the generation process incorporates feedback from a self-evaluation module to optimize the results. This approach ensures that the generated code not only has high accuracy but also covers a variety of possible solutions.

[0026] This invention significantly improves the accuracy and diversity of code generation through diverse instruction fine-tuning and multi-task learning, especially excelling in handling complex code generation tasks. Compared with existing technologies, this invention has the following significant advantages:

[0027] 1. Increased code generation diversity: By fine-tuning the module with diverse instructions, the model can generate multiple different code solutions to meet the needs of different users. This diversified code generation method not only provides programmers with more choices but also stimulates their innovative thinking, helping them find better solutions.

[0028] 2. Improved Code Generation Correctness: Through self-evaluation and multi-objective learning modules, the model can accurately evaluate and optimize the generated code, thereby improving its correctness and quality. This self-evaluation and optimization mechanism effectively avoids potential errors and problems in the generated code, improving its reliability and stability.

[0029] 3. Improve code generation efficiency: Through the multi-task learning module, the model can simultaneously learn code generation and code evaluation capabilities, thereby achieving collaborative optimization of code generation and code evaluation. This collaborative optimization approach not only improves the model's generation capabilities but also increases code generation efficiency, reducing generation time and computational resource consumption.

[0030] 4. High adaptability: The system and method of this invention are highly adaptable and can be applied to various programming languages ​​and tasks. By simply adjusting the system prompts and evaluation criteria, the model can quickly adapt to different programming scenarios and needs, and has broad application prospects.

[0031] In summary, this invention, through its innovative model architecture and methodology, effectively addresses the shortcomings of existing code generation models in terms of diversity and correctness, significantly improving code generation capabilities and performance. This invention not only provides programmers with more efficient and reliable code generation tools but also promotes the further development and application of code generation technology in the field of artificial intelligence. Attached Figure Description

[0032] Figure 1 This is a schematic diagram of the system architecture of the present invention, illustrating the specific components of the diverse instruction fine-tuning and multi-objective learning framework. Detailed Implementation

[0033] In practical implementation, the system and method of the present invention can be implemented through the following steps.

[0034] 1. Fine-tuning of diverse instructions

[0035] 1.1 System Prompt Design

[0036] The core of the diversity instruction fine-tuning module is the design of system prompts. System prompts are a key factor in guiding the model to generate diverse code. These prompts can include, but are not limited to, the following types:

[0037] - Algorithm hints: Specify different algorithm implementation methods, such as "implement using dynamic programming" or "implement using greedy algorithm".

[0038] - Code style hints: Specify the style requirements for your code, such as "use object-oriented programming style" or "use functional programming style".

[0039] -Performance optimization tips: Specify the performance optimization goals for the code, such as "optimize the time complexity to O(n)" or "optimize the space complexity to O(1)".

[0040] - Boundary condition hints: Specify the boundary conditions that the code needs to handle, such as "consider the case of empty input" or "consider the case of negative input".

[0041] Through these diverse system prompts, the model can generate code from different perspectives and reasoning paths, thus achieving code diversity.

[0042] 1.2 Code Generation and Filtering

[0043] After receiving the programming requirements from the user, the diversity instruction fine-tuning module generates multiple code solutions with different reasoning paths based on the pre-designed system prompts. For example, for a simple sorting task, the system prompts may include "use bubble sort," "use quick sort," "use merge sort," etc., and the model will generate different sorting code implementations based on these prompts.

[0044] The generated code solutions will be filtered using heuristic rules to ensure the quality and diversity of the generated code. Heuristic rules may include:

[0045] - Syntax check: Filter out code with syntax errors.

[0046] -Logic check: Detects whether there are logical vulnerabilities in the code.

[0047] - Similarity check: Remove highly similar code snippets to ensure diversity.

[0048] -Performance check: Evaluate the execution efficiency of the code and filter out code with poor performance.

[0049] Ultimately, the filtered code data forms a high-quality, diverse dataset of code instructions, providing rich training material for subsequent model training.

[0050] 2. Self-assessment

[0051] 2.1 Setting Evaluation Criteria The main function of the self-evaluation module is to perform a self-evaluation of the generated code and determine its correctness. Evaluation criteria may include the following aspects:

[0052] - Syntax correctness: Checks whether the code conforms to the syntax rules of a specific programming language.

[0053] - Logical rationality: Analyze the logical structure of the code to determine whether the code can correctly achieve the expected function.

[0054] - Execution efficiency: Evaluate the algorithm complexity and resource consumption of the code to determine its performance.

[0055] - Programming standards: Check whether the code conforms to specific programming standards, such as naming conventions and commenting conventions.

[0056] 2.2 Evaluation Process

[0057] During the self-evaluation process, the model analyzes and evaluates the generated code line by line according to preset evaluation criteria. For example: - Syntax checking: The syntax analyzer checks the code for spelling errors, syntax errors, and other problems.

[0058] - Logic check: Check the code for logical loopholes or potential errors using a logic analyzer.

[0059] -Performance evaluation: Evaluate the algorithm complexity and resource consumption of the code using a performance analyzer to determine the code's execution efficiency.

[0060] - Code style check: Checks whether the code conforms to specific programming standards using a code style analyzer.

[0061] The evaluation result can be a comprehensive score or a pass / fail judgment. Based on the evaluation results, the model can optimize and improve the generated code.

[0062] 3. Multi-objective learning

[0063] 3.1 Task Design

[0064] The main function of the multi-objective learning module is to combine code generation and code evaluation tasks, training both tasks simultaneously using a multi-task learning approach. Specifically, the multi-objective learning module includes the following two tasks:

[0065] - Code evaluation task: Train a model to accurately evaluate code and judge its correctness and quality.

[0066] - Code generation task: Train the model to generate high-quality code to meet users' programming needs.

[0067] 3.2 Training Process

[0068] During training, the model is first trained on a code evaluation task. Through a large amount of labeled data, the model learns the standards and rules for code evaluation, thereby gaining the ability to accurately evaluate code. Labeled data can include code snippets and their corresponding evaluation results (such as pass / fail, score, etc.).

[0069] Then, fine-tuning continues on diverse instruction data. During fine-tuning, the model not only learns diverse code generation methods but also optimizes and improves the generated code based on feedback from the self-evaluation module. In this way, the model can ensure the correctness and quality of the generated code while generating diverse code.

[0070] 4. Implementation of the code generator

[0071] 4.1 Generation Process

[0072] The code generator is the core component of the system of this invention, responsible for generating code based on a pre-trained code model. During the generation process, the code generator fully utilizes the capabilities of the diversity instruction fine-tuning module and the self-evaluation module, combined with the optimization results of the multi-objective learning module, to generate high-quality code.

[0073] The specific steps are as follows:

[0074] 1. Receiving programming requirements: The code generator receives programming requirements input by the user, such as programming tasks described in natural language.

[0075] 2. Generate diverse code: Based on the design of the module for fine-tuning diverse instructions, generate multiple code solutions with different reasoning paths.

[0076] 3. Evaluation and Optimization: The generated code is evaluated by a self-evaluation module, and the optimal code solution is selected based on the evaluation results. If the evaluation results indicate that the code has errors or deficiencies, the code generator will optimize and improve the code based on the feedback information.

[0077] 4. Output the final code: Output the optimized code to the user.

[0078] 4.2 Optimization Techniques

[0079] To further improve the quality and diversity of generated code, the code generator also employs several optimization techniques during the generation process: - Context information introduction: By introducing context information, the model can better understand the user's needs and generate code that better matches the user's intent.

[0080] - Probabilistic generation strategy: By adopting a probabilistic generation strategy, the model can generate a variety of different code implementations to meet the needs of different users.

[0081] - Dynamic adjustment: Based on user feedback, the model can dynamically adjust the generation strategy to further improve the quality of generated code and user experience.

[0082] 5. Implementation Cases

[0083] 5.1 Programming Task Examples

[0084] Suppose the user's programming requirement is "Write a function to calculate the greatest common divisor (GCD) of two integers".

[0085] 1. System prompt design:

[0086] Hint 1: Implement using the Euclidean algorithm.

[0087] - Hint 2: Use brute force to achieve this.

[0088] - Tip 3: Optimize the time complexity to O(log(min(a,b))).

[0089] 2. Code generation and filtering:

[0090] Based on the above prompts, the model generates the following code solution:

[0091] - Code implementation using the Euclidean algorithm.

[0092] - Code implementation using brute force.

[0093] - Optimize the code implementation in terms of time complexity.

[0094] - Use heuristic rules to filter out code with syntax and logic errors, retaining high-quality code solutions.

[0095] 3. Self-assessment:

[0096] - Evaluate the generated code, checking for syntax correctness, logical rationality, execution efficiency, etc.

[0097] The evaluation results show that the code implementation using the Euclidean algorithm has high correctness and performance.

[0098] 4. Multi-objective learning:

[0099] - Train on code evaluation tasks to learn the standards and rules for code evaluation.

[0100] - Fine-tune the code generation strategy based on diverse instruction data.

[0101] 5. Code generation and output:

[0102] - The code generator generates the final code based on the optimized model and outputs it to the user.

[0103] The final generated code is as follows (example):

[0104]

[0105] 6. Performance Optimization and Testing

[0106] 6.1 Performance Optimization

[0107] To improve system performance and efficiency, this invention employs various optimization techniques during its implementation:

[0108] - Parallel processing: Parallel processing techniques are used in the fine-tuning and self-evaluation of diverse instructions to improve the efficiency of code generation and evaluation.

[0109] - Caching mechanism: Cache the generated high-quality code to avoid repeated generation and evaluation, improving system response speed. - Resource management: Optimize the model's resource consumption to ensure stable system operation under high load.

[0110] 6.2 Testing and Verification

[0111] To verify the effectiveness and performance of the system of the present invention, extensive testing and verification were conducted. The testing included, but was not limited to, the following aspects:

[0112] - Code diversity test: Verify the diversity of code generated by the system through a variety of programming tasks.

[0113] - Code correctness testing: Verify the correctness and reliability of the generated code through a large number of test cases.

[0114] -Performance testing: Verify the system's performance and efficiency through high-load testing.

[0115] Test results show that the system of the present invention performs well in terms of the diversity and correctness of code generation, and can significantly improve the quality and efficiency of code generation, meeting the complex needs in actual programming scenarios.

[0116] Through the detailed steps and methods described above, the system and method of the present invention can effectively solve the shortcomings of existing code generation models in terms of diversity and correctness, and significantly improve the ability and performance of code generation.

Claims

1. A system for fine-tuning instruction models in code generation, characterized in that, The system includes: - Diversity instruction fine-tuning module, configured to generate diverse code solutions using different system prompts; - Self-evaluation module, configured to evaluate the correctness of generated code and enhance code generation capabilities based on the evaluation results; - A code generator that generates code based on a pre-trained code model and improves the overall performance of code generation and evaluation through a multi-objective learning framework.

2. The system according to claim 1, characterized in that, The diversity instruction fine-tuning module expands the diversity of user instructions by using different system prompts, generating code solutions for different reasoning paths.

3. The system according to claim 1 or 2, characterized in that, The self-evaluation module uses a natural language generation task to evaluate the code in order to determine the syntax, logic, and execution efficiency of the generated code.

4. The system according to any one of claims 1 to 3, characterized in that, The code generator is trained on both the code generation and code evaluation tasks simultaneously through multi-task learning, thereby optimizing the model's ability to evaluate and improve code generation.

5. The system according to any one of claims 1 to 4, characterized in that, The diversity instruction fine-tuning module uses heuristic rules to filter low-quality and similar data in order to improve the quality and diversity of generated code.

6. The system according to any one of claims 1 to 5, characterized in that, The self-evaluation module can output a pass or fail evaluation result and provide feedback information based on the evaluation result to guide the optimization of the model.

7. The system according to any one of claims 1 to 6, characterized in that, The multi-objective learning framework achieves collaborative optimization of code generation and code evaluation tasks by sharing model parameters and feature representations.

8. A method for improving the performance of a code generation model, characterized in that, The method includes: - Use multiple system suggestions to generate diverse code solutions; - Self-evaluate the generated code solution to determine its correctness; - Optimize the code generation model's generation capabilities based on the evaluation results; - Simultaneously perform joint learning for code generation and code evaluation tasks.

9. The method according to claim 8, characterized in that, The generated diverse code solutions improve the quality of the generated code by eliminating low-quality and similar data.

10. The method according to claim 8 or 9, characterized in that, The self-evaluation assesses the logical correctness and execution efficiency of the code through natural language generation, and the code generation model is trained in multiple stages, first on the code evaluation task, and then fine-tuned on diverse instruction data.