Instruction optimization method and device, electronic equipment and storage medium

Through the instruction correction model based on the Markov decision-making process, the instruction optimization data set is built and the model is fine-tuned, which solves the problem of low efficiency in manual optimization instructions and achieves the effect of rapid generation of high-quality code.

CN120372299AActive Publication Date: 2025-07-25JINAN INSPUR DATA TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202510870952.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-26
Publication Date
2025-07-25
Estimated Expiration
2045-06-26

AI Technical Summary

Technical Problem

In the prior art, manual optimization instructions are inefficient and costly, and it is difficult to quickly determine instructions that meet the needs, which hinders the efficiency of code generation in large language models.

Method used

Through the preset instruction correction model built based on the Markov decision-making process, the instruction optimization data set is generated, the instruction optimization model is fine-tuned, the instructions input by the user are automatically optimized, and the code that meets the needs is generated.

Benefits of technology

It realizes the rapid determination of instructions that meet the needs, improves instruction optimization efficiency, and automatically generates high-quality code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120372299A_ABST
    Figure CN120372299A_ABST
Patent Text Reader

Abstract

The invention discloses an instruction optimization method and device, electronic equipment and a storage medium, and relates to the technical field of data processing, and the method comprises the steps: generating a fine tuning data set, namely an instruction optimization data set, for adjusting an instruction optimization model based on a model constructed in a Markov decision process, and performing fine tuning on the instruction optimization model based on the instruction optimization data set. Therefore, the instruction optimization model can optimize the to-be-optimized instruction so as to help the user to generate the code meeting the requirement, and the instruction input by the user can be automatically optimized. Therefore, the technical problem of how to quickly determine the instruction meeting the requirement to improve the optimization efficiency of the instruction can be solved, and the technical effects of quickly determining the instruction meeting the requirement and improving the optimization efficiency of the instruction are achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of data processing, and in particular, to a method and device for optimizing instructions, an electronic device, and a storage medium. Background Art

[0002] Large Language Models (LLMs) have demonstrated excellent performance in the field of natural language processing and can have a significant impact on various tasks, including text generation, image generation, translation, and code generation. However, despite their powerful language capabilities, the output quality of LLMs highly depends on the quality of the input instructions. Especially in code generation tasks, the accuracy of instructions is particularly important, and incorrect or unclear coding instructions can easily lead to the model generating incorrect code.

[0003] In the prior art, manually optimizing instructions is a common method to improve the quality of code generated by LLMs. By repeatedly modifying the instructions into high-quality coding instructions to improve the performance of LLMs. However, manually optimizing instructions is inefficient and costly, and it is difficult to quickly write instructions that meet the requirements, thus hindering the efficiency of code generation by LLMs. Therefore, how to quickly determine instructions that meet the requirements to improve the efficiency of instruction optimization is an urgent problem to be solved currently. Summary of the Invention

[0004] This application provides a method and device for optimizing instructions, an electronic device, and a storage medium to at least solve the problem in the related art of how to quickly determine instructions that meet the requirements to improve the efficiency of instruction optimization.

[0005] This application provides a method for optimizing instructions, including: Inputting the obtained first training data set into a preset code generation model for code generation processing to obtain a generation failure data set in the first training data set, where the generation failure data set includes multiple generation failure instructions and failure information corresponding to each of the multiple generation failure instructions; Performing instruction optimization processing on the multiple generation failure instructions respectively by a preset instruction correction model according to the failure information to obtain an instruction optimization data set, where the instruction optimization data set at least includes multiple generation failure instructions, optimized instructions corresponding to each of the multiple generation failure instructions, and optimization process data, and the preset instruction correction model is a model constructed based on a Markov decision process; Performing model training processing on a preset instruction optimization model according to the instruction optimization data set to obtain a trained instruction optimization model, and performing instruction optimization processing on an instruction to be optimized by the trained instruction optimization model to obtain a target instruction.

[0006] The present application also provides a device for optimizing instructions, including: A generating unit, configured to input the obtained first training data set into a preset code generation model for code generation processing, so as to obtain a generation failure data set in the first training data set, where the generation failure data set includes a plurality of generation failure instructions and failure information corresponding to each of the plurality of generation failure instructions; A first optimization unit, configured to optimize each of the plurality of generation failure instructions according to the failure information through a preset instruction correction model to obtain an instruction optimization data set, where the instruction optimization data set at least includes a plurality of generation failure instructions, optimized instructions corresponding to each of the plurality of generation failure instructions, and optimization process data, and the preset instruction correction model is a model constructed based on a Markov decision process; A training unit, configured to perform model training processing on a preset instruction optimization model according to the instruction optimization data set to obtain a trained instruction optimization model; A second optimization unit, configured to optimize the instruction to be optimized through the trained instruction optimization model to obtain a target instruction.

[0007] The present application also provides an electronic device, including: a memory, configured to store a computer program; a processor, configured to implement the steps of any of the above methods for optimizing instructions when executing the computer program.

[0008] The present application also provides a computer-readable storage medium, in which a computer program is stored, where the computer program, when executed by a processor, implements the steps of any of the above methods for optimizing instructions.

[0009] The present application also provides a computer program product, including a computer program, where the computer program, when executed by a processor, implements the steps of any of the above methods for optimizing instructions.

[0010] The method and device for optimizing instructions, electronic device, and storage medium of the present application generate a fine-tuning data set for adjusting the instruction optimization model, that is, an instruction optimization data set, through a model constructed based on a Markov decision process, and fine-tune the instruction optimization model based on the instruction optimization data set, so that the instruction optimization model can optimize the instruction to be optimized, thereby helping the user generate code that meets the requirements and automatically optimizing the instructions input by the user. Therefore, the technical problem of how to quickly determine instructions that meet the requirements to improve the instruction optimization efficiency can be solved, and the technical effect of quickly determining instructions that meet the requirements and improving the instruction optimization efficiency can be achieved. Description of the Drawings

[0011] To more clearly illustrate the embodiments of the present application, the accompanying drawings required for use in the embodiments will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can be obtained based on these drawings.

[0012] Figure 1 It is a schematic flowchart of a method for optimizing instructions provided by an embodiment of the present application; Figure 2 It is a schematic diagram of the principle of a method for optimizing instructions provided by an embodiment of the present application; Figure 3 It is a schematic structural diagram of a device for optimizing instructions provided by an embodiment of the present application; Figure 4 It is a schematic structural diagram of another device for optimizing instructions provided by an embodiment of the present application. Detailed implementation manners

[0013] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only some embodiments of the present application, rather than all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the protection scope of the present application.

[0014] It should be noted that in the description of the present application, the terms "include", "comprise" or any other variant thereof are intended to cover a non-exclusive inclusion, such that a process, method, article or device including a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article or device. The terms "first", "second", etc. in the present application are used to distinguish similar objects and are not used to describe a specific order or sequence.

[0015] To enable those skilled in the art of this technology to better understand the solution of the present application, the present application will be further described in detail below in conjunction with the accompanying drawings and specific implementation manners.

[0016] Figure 1 It is a schematic flowchart of a method for optimizing instructions provided by an embodiment of the present application. The method will be described in detail in combination with the execution process of the method for optimizing instructions.

[0017] As Figure 1 shown, the method for optimizing instructions includes: Step 101: Input the obtained first training dataset into a preset code generation model for code generation processing to obtain a generation failure dataset in the first training dataset, where the generation failure dataset includes multiple generation failure instructions and the failure information corresponding to each of the multiple generation failure instructions.

[0018] In an embodiment of the present application, the first training dataset refers to a high-quality code generation dataset screened from an open-source community, including but not limited to: instruction-code pairs and test cases, such as: the Mostly Basic Python Problems (MBPP) dataset that meets specific quality standards, etc. The MBPP dataset is a dataset specifically used to evaluate and improve Python code generation models. The preset code generation model is a large language model for performing code generation tasks.

[0019] To facilitate understanding of the implementation principle of the present application, the present application provides a schematic diagram of the principle of a method for optimizing instructions, as Figure 2 shown. Among them, the method for optimizing instructions in the present application mainly includes the construction of a fine-tuning dataset (instruction optimization dataset); the fine-tuning of a large model (the model training of a preset instruction optimization model); model testing and tool development.

[0020] Input the first training dataset into a preset code generation model (for example: a large language model with code generation capabilities such as a pre-trained language model (General Language Model, GLM), etc.) to perform code generation processing. The code generation process refers to that the preset code generation model automatically outputs the corresponding code snippet according to the natural language instructions (i.e., coding task descriptions) in the first training dataset. The generation results go through a strict code verification process (including but not limited to semantic comparison with the true value code and dynamic execution of test cases), and the samples that fail to pass the verification are identified. The failed samples constitute the generation failure dataset. The generation failure dataset refers to a set composed of the failed instructions identified by the code verification process and their structured error information, which contains two types of key information: Generation failure instructions: The original natural language instructions that cause code generation errors; Failure information: Structured records of the reasons for failure (such as: syntax errors, undefined variables, logical defects, etc.), extracted through Abstract Syntax Tree (AST) analysis and exception capture mechanisms, including error types, locations, and context code snippets.

[0021] Step 102: Use the preset instruction correction model to optimize each of the multiple generation failure instructions according to the failure information, obtaining an instruction optimization dataset. The instruction optimization dataset includes at least multiple generation failure instructions, the optimized instructions corresponding to each of the multiple generation failure instructions, and optimization process data. The preset instruction correction model is a model constructed based on the Markov decision process.

[0022] In an embodiment of the present application, the preset instruction correction model is a high-order large model based on the Markov decision process, used to generate an instruction optimization plan. The instruction optimization dataset is structured training data containing the original failure instructions (i.e., multiple generation failure instructions), optimized instructions, and optimization process records.

[0023] Use the preset instruction correction model (an agent constructed based on the Markov decision process) to optimize the generation failure dataset. The preset instruction correction model generates targeted modification suggestions (i.e., performs instruction optimization processing) according to the failure information corresponding to each failure instruction. The optimization process is iterative and progressive: State: The multiple generation failure instructions to be optimized currently; Action: Instruction rewriting strategies based on failure information analysis (e.g., streamlining descriptions, supplementing context, expressing by examples); Reward: The proportion of code passing the test driven by the new instruction (code passing rate) is used as a feedback signal for the optimization effect.

[0024] After multiple rounds of iteration (usually not exceeding five rounds), an instruction optimization dataset containing the following elements is generated: original generation failure instructions, optimized instructions (high-quality new instructions that have passed verification), and optimization process data (recording intermediate instructions and their verification results during iteration, such as: rejected invalid optimization instructions).

[0025] Step 103: Use the instruction optimization dataset to train the preset instruction optimization model, obtaining a trained instruction optimization model, and use the trained instruction optimization model to optimize the instruction to be optimized, obtaining a target instruction.

[0026] In an embodiment of the present application, the preset instruction optimization model is a base large model to be trained, and obtains instruction optimization capabilities through fine-tuning. The trained instruction optimization model is the model after fine-tuning, which can automatically optimize the instructions input by the user. The instruction to be optimized is the original coding task description provided by the user. The target instruction is a highly executable coding instruction optimized by the model.

[0027] Training can adopt the Odds Ratio Preference Optimization (ORPO) algorithm. By comparing the optimized instructions (preferred samples) with the intermediate instructions (inferior samples) and generating failed instructions, the model can learn the implicit rules for distinguishing the quality of instructions, thereby obtaining the instruction optimization ability. The trained instruction optimization model after training has the following core functions: Receive the instruction to be optimized input by the user (i.e., the coding task described in natural language); Automatically execute the instruction optimization process to generate a target instruction with clearer semantics and stronger executability.

[0028] By systematically mining the value of failed samples, constructing a high-quality instruction optimization dataset, and training a dedicated model using the preference optimization algorithm, the following effects can be achieved but are not limited to: Precisely locate instruction defects: Based on the analysis of the failure information verified by the code, identify the ambiguity, ambiguity, or logical deficiency of the instruction from the root cause; Closed-loop optimization ability: The Markov decision process drives the iterative upgrade of the instruction to ensure that the optimized instruction significantly improves the code generation pass rate; Automatic knowledge transfer: ORPO training enables the model to master the instruction expression paradigm preferred by humans and generate professional-level optimization results without manual intervention; Wide applicability: The trained model can immediately process any instruction to be optimized input by the user, quickly output high-quality target instructions, and significantly reduce the development and debugging costs.

[0029] The instruction optimization method of this application, through a model constructed based on the Markov decision process, generates a fine-tuning dataset for adjusting the instruction optimization model, that is, an instruction optimization dataset. Based on the instruction optimization dataset, the instruction optimization model is fine-tuned, so that the instruction optimization model can perform optimization processing on the instruction to be optimized, and then help the user generate code that meets the requirements, and can automatically perform instruction optimization on the instruction input by the user. Therefore, it can solve the technical problem of how to quickly determine the instruction that meets the requirements to improve the instruction optimization efficiency, and achieve the technical effect of quickly determining the instruction that meets the requirements and improving the instruction optimization efficiency.

[0030] In an implementable manner of the embodiment of this application, it is necessary to obtain the first training dataset in advance to complete the subsequent instruction optimization process. Regarding the acquisition of the first training dataset, the following methods can also be adopted but are not limited to: Perform data screening processing on the preset database to obtain the first dataset, where the preset database includes multiple datasets; Divide the first dataset according to the preset division method to obtain the first training dataset and the first test dataset.

[0031] In the embodiments of the present application, the preset database is a dedicated repository integrating multiple open-source code generation data sets. The multiple data sets refer to independent data collections stored in the preset database (such as MBPP, etc.), and each of the multiple data sets contains instructions, code, and test cases. The screening process refers to the process of evaluating and selecting the optimal data set according to predefined quality criteria (scale, semantic relevance, etc.). The first data set is the comprehensive optimal code generation data set obtained through screening (such as MBPP). The preset partitioning method is a custom-set partitioning method. For example, the standard strategy of splitting the data set according to a fixed ratio (80%-20%). The first test data set is the independent data part reserved for the final evaluation of the model after partitioning.

[0032] Through strict screening and partitioning, at least the following can be achieved: screening the first data set based on multi-dimensional criteria, fundamentally ensuring the input reliability of the subsequent optimization process; enabling the system to adapt to data sources of different scales through the preset partitioning method, supporting flexible expansion; providing an unbiased evaluation basis for the final model performance through the independent first test data set.

[0033] In a realizable manner of the embodiments of the present application, when performing data screening processing from the preset database, the following methods can also be adopted but are not limited to: obtaining the data set information corresponding to each of the multiple data sets in the preset database, where the data set information at least includes data scale, data relevance, data complexity, testability, programming language coverage, and referability; calculating the data set scores corresponding to each of the multiple data sets through the first preset weight according to the data scale, data relevance, data complexity, testability, programming language coverage, and referability; and determining the data set with the largest data set score among the multiple data sets as the first data set.

[0034] In the embodiments of the present application, the first preset weight is a set of importance coefficients of each scoring dimension set in advance. The data set score refers to the comprehensive quality quantization value of the data set obtained through weighted calculation.

[0035] In the data screening process, a quantitative scoring mechanism can be adopted but is not limited to selecting the first data set from the multiple data sets included in the preset database. The data screening process mainly comprehensively evaluates the candidate sets through multi-dimensional data set information. The data set information includes the attribute information of each data set (that is, data scale, data relevance, data complexity, testability, programming language coverage, and referability), and the attribute information constitutes the basic dimension of the score.

[0036] Among them, the data scale refers to the number of independent instruction-code pairs in the dataset, reflecting the richness of the samples. For example, the dataset scale of the first dataset needs to have more than 100 independent instruction-code pairs to ensure the richness of the training samples. The data relevance is the degree of consistency in functional semantics between the instruction and the corresponding code, used to measure the semantic matching degree between the natural language instruction and its corresponding true-value code. For example, there is a high semantic relevance between the instructions and codes in the first dataset, and the Bilingual Evaluation Understudy (BLEU) score ≥ 0.4 is used as the basic threshold. The data complexity refers to the logical difficulty and structural diversity of the programming problems included in the dataset, used to evaluate the programming logic diversity covered by the dataset (such as: function encapsulation, conditional branching, loop control, etc.). For example, the problem complexity of the first dataset needs to cover common programming logics such as function implementation, conditional judgment, loop, and string processing.

[0037] Testability refers to whether the dataset provides complete and automatically executable test cases. For example, the test cases of the first dataset are complete and accurate, and can support the automated verification of the correctness of the generated code. The programming language coverage refers to the range of mainstream programming languages supported by the dataset (such as: Python, JavaScript, etc.). For example, the first dataset covers mainstream programming languages, and task-driven languages such as Python and JavaScript are preferred. The citedness refers to the extent to which the dataset is widely cited by authoritative literature in academic research or industrial practice. For example, the quality of the first dataset is cited in mainstream large model papers and has a good reputation and a wide application foundation.

[0038] When calculating the dataset score, based on the attribute information of the dataset, a first preset weight (i.e., the importance coefficient of each dimension defined in advance) is used for weighted calculation. The allocation of weights can follow the following principles: higher weights are assigned to dimensions that are crucial for the code generation task (such as: data relevance, testability); medium weights are assigned to dimensions that have a significant impact on the model generalization ability (such as: data complexity, programming language coverage); basic guarantee dimensions (such as: data scale, citedness) are assigned basic weights.

[0039] By normalizing the scores of each dimension, the scores are converted into comparable values, and finally the weighted sum is used to generate the dataset score. The dataset score objectively reflects the comprehensive quality of the dataset in the code generation scenario. The dataset with the highest score is determined as the first dataset (for example: the MBPP dataset obtains the optimal score due to its high integrity in Python tasks). Ensure that the subsequent processes are based on the data with the best quality and the strongest representativeness.

[0040] Based on the structured scoring system, subjective experience can be converted into computable quantitative indicators by presetting weights, eliminating the random deviation of manual screening; the effectiveness of training data can be ensured from the source by covering data availability, task adaptability, and academic reliability through multi-dimensional dataset information; the weights can be flexibly adjusted through the scoring mechanism to meet different task requirements, providing a general screening paradigm for instruction optimization in other fields.

[0041] In an implementable manner of the embodiment of the present application, when obtaining the generation failure dataset, the following manner can also be adopted but is not limited to: inputting multiple first data groups in the first training dataset into a preset code generation model for code generation processing to obtain generated codes corresponding to each of the multiple first data groups, where each first data group includes a code generation instruction, and a true value code and a test case respectively corresponding to the code generation instruction; performing code verification processing on the generated codes corresponding to each according to the multiple true value codes and multiple test cases to obtain code verification results; determining multiple verification failure codes in the multiple generated codes and failure information respectively corresponding to the multiple verification failure codes according to the code verification results, and constructing a generation failure dataset through the first data groups and failure information respectively corresponding to the multiple verification failure codes.

[0042] In the embodiment of the present application, the first data group is a data unit in the first training dataset, and each first data group can be organized in the form of JavaScript Object Notation (Json), forming an associated combination of a code generation instruction (instruction), a true value code (solution), and a test case (test_cases), where the code generation instruction refers to the original natural language instruction describing the programming task; the true value code is the correct implementation code that exactly matches the instruction; the test case is an automated test script for verifying the correctness of the code function.

[0043] Code generation processing refers to the reasoning process in which a preset code generation model outputs code snippets according to natural language instructions; the generated code refers to the program code automatically generated by the preset code generation model based on the code generation instruction; code verification processing refers to a dual verification process for judging the correctness of the generated code through semantic comparison and test execution; the code verification result marks the verification conclusion of whether the generated code passes or fails; the verification failure code is an instance of the generated code that fails to pass the code verification processing; the failure information refers to the structured data describing the reason for the code failure (at least including: error type, location, and context); the generation failure dataset integrates the failed instructions and their corresponding failure information.

[0044] In the code verification processing stage, a dual verification mechanism can be adopted to ensure the reliability of the results: Semantic comparison: The generated code is compared character by character with the true value code. If they are exactly the same, it is directly determined that the verification passes; Dynamic test execution: When the semantic comparison is inconsistent, the generated code is placed in a sandbox environment to execute the corresponding test cases. The correctness of the function is judged by exception capture and assertion check (timeout, error reporting, or test failure are all regarded as verification failures). After that, the verification result of the generated code is generated, and the pass / fail status of each generated code is clearly marked.

[0045] For the code generation instructions that fail the verification, i.e., the failed instructions, two types of key information are extracted, namely the verification failed code (the instance of the generated code that fails the verification), and the failure information (the structured record of the failure reason, such as: the type of syntax error, the location where the variable is not defined, the code segment with logical defects, automatically generated through AST parsing and exception stack analysis). Finally, the original first data set (including the failed instructions) and their corresponding failure information are integrated to construct a complete generated failure data set, providing an accurate defect sample library for subsequent instruction optimization.

[0046] In the process of the dual verification mechanism and structured failure analysis, semantic comparison is used to avoid misjudgment of codes with correct functions but different formats, and dynamic testing deeply examines the code behavior logic. The combination of the two ensures high accuracy of failure determination; through the structured failure information, not only the type of error is located, but also the code defect location and context are accurately pointed to, providing an operable diagnostic basis for subsequent instruction optimization; since no manual intervention is required throughout the process from code generation, verification to failure information extraction, the construction efficiency and scalability of the generated failure data set are greatly improved.

[0047] In an implementable manner of the embodiment of the present application, when performing code verification processing on the generated code, the following method can also be adopted but is not limited to: performing semantic comparison processing on multiple generated codes with their respective corresponding true value codes to obtain the semantic comparison results corresponding to the multiple generated codes; determining multiple first codes and multiple second codes according to the semantic comparison results, and determining the multiple first codes as the verification successful codes, where the first code is the generated code that is semantically compared with the true value code in the multiple generated codes, and the second code is the generated code that is semantically compared with the true value code inconsistently in the multiple generated codes; performing code test processing on the multiple second codes through their respective corresponding test cases to obtain the code test results; determining multiple unpassed test codes and multiple passed test codes among the multiple second codes according to the code test results, and determining the multiple passed test codes as the verification successful codes, and determining the multiple unpassed test codes as the multiple verification failed codes, where the code test results include the failure information corresponding to each of the multiple unpassed test codes.

[0048] In an embodiment of the present application, semantic comparison processing refers to a process of precisely comparing each character of the generated code with the true value code, which is used to quickly identify completely matching samples; the semantic comparison result is a binary determination conclusion indicating whether the generated code and the true value code are exactly the same; the first code is an instance of the generated code that is confirmed to be completely correct through semantic comparison; the second code is an instance of the generated code that requires in-depth testing due to inconsistent semantic comparison; code testing processing refers to a dynamic detection process of executing test cases in an isolated environment to verify the code function; the code that fails the test refers to the generated code that has errors, timeouts, or assertion failures during the testing process; the code that passes the test refers to the generated code that completely passes all test cases during the testing process.

[0049] During code verification processing, semantic comparison processing is first performed. The content of each generated code (i.e., the code snippet output by the preset code generation model) is compared with its corresponding true value code (the standard correct answer provided in the dataset). Semantic comparison can adopt the principle of exact character-by-character matching. If the two are exactly the same, it is determined that the semantics are completely consistent. After semantic comparison, a semantic comparison result is generated as the preliminary verification basis.

[0050] Based on the semantic comparison result, the generated code is divided into the first code and the second code. Since the first code is the generated code that is exactly the same as the true value code, it is directly marked as the code that passes the verification. However, since the second code is the generated code that has differences from the true value code, it needs to enter the in-depth verification process.

[0051] The code testing process for the second code can be started in the following ways, but is not limited to: placing the second code in a sandbox execution environment and running the corresponding test cases (automated verification scripts provided by the dataset). The following situations are captured through the exception monitoring and assertion checking mechanisms during the testing process: running timeout (exceeding the preset safety threshold); throwing an unhandled exception (such as: syntax error, runtime error); failing the function assertion in the test case.

[0052] After the testing is completed, a code testing result is generated, which includes the code that passes the test and the code that fails the test. Since the code that passes the test is the generated code that completely passes all test cases, it can be additionally marked as the code that passes the verification. However, the code that fails the test is the generated code that fails the test, so it is determined as the code that fails the verification. The error details (such as: error type, stack trace, position of the failed assertion) structuredly recorded in the failure information are automatically generated through runtime diagnosis and log analysis.

[0053] Through semantic comparison in the hierarchical screening mechanism, false failure samples with format differences but equivalent functions can be quickly screened out, avoiding unnecessary test executions and significantly shortening the verification cycle; accept the second code with inconsistent semantics but correct functions (e.g., variable renaming, annotation addition and deletion), and verify its behavioral equivalence through dynamic testing to improve the practicality of the verification mechanism; generate multi-dimensional failure information for the code that fails the test, accurate to the defect location at the code line level, providing a targeted repair basis for subsequent instruction optimization.

[0054] In an implementable manner of the embodiment of the present application, when performing code test processing, the following manner can also be adopted but is not limited to: respectively perform code running processing on multiple second codes through their respective corresponding test cases to obtain code running information; determine multiple codes that meet the preset running conditions among the multiple second codes as multiple passed test codes according to the code running information, where the preset running conditions at least include running time, throw status, assertion pass status, and / or running status; determine multiple codes that do not meet the preset running conditions among the multiple second codes as multiple failed test codes according to the code running information.

[0055] In the embodiment of the present application, the code running processing is a dynamic detection process of executing the second code in an isolated environment and running the corresponding test cases; the code running information refers to four-dimensional monitoring data (running time / throw status / assertion pass status / running status) generated during the test execution process; the preset running conditions are custom-set conditions, at least including a set of technical standards for determining whether the code passes the test (e.g., it is required to meet the time, exception, assertion, and process requirements simultaneously).

[0056] The running time refers to the time consumed from the start to the end of the code execution, and timeout is regarded as failure; the throw status is a key indicator for identifying whether the code throws an uncaught exception; the assertion pass status refers to the satisfaction of the function verification assertions in the test case; the running status is a system-level flag reflecting whether the code execution process terminates normally; the passed test code is an instance of the second code that fully meets the preset running conditions; the failed test code is an instance of the second code that violates at least one preset running condition.

[0057] When performing code test processing, place the second code that needs to be deeply verified in an isolated sandbox environment, execute its corresponding test case (the automated verification script provided by the data set), and the code running processing process monitors and records the complete code running information in real time, that is, running time: the time consumed by the code execution, and exceeding the preset safety threshold (e.g., 3 seconds) is regarded as timeout; throw status: monitor whether an unhandled exception is thrown; assertion pass status: verify whether all function assertions in the test case are satisfied; running status: capture system errors such as abnormal termination of the process and memory overflow. Based on the above running information, make an automatic determination according to the preset running conditions (i.e., the predefined passing criteria): If the second code simultaneously meets the following conditions: it is executed within the safe time (the running time is compliant); no exceptions are thrown (the throwing status is normal); all function assertions are passed (the assertion passing status meets the standard); the process exits normally (the running status is stable); then the second code is classified as a code passing the test.

[0058] If any condition is violated (such as timeout, assertion failure, runtime error, etc.), it is determined that the code fails the test.

[0059] By quadruple status monitoring, both security and reliability are achieved. That is, the sandbox environment isolates the risk code, and combined with timeout control, it prevents malicious or infinite loop code from impacting the system; through exception monitoring, assertion verification, and system status detection, it covers the full spectrum of code problems from syntax errors to logical defects; by presetting the running conditions, the abstract correctness standard is transformed into quantifiable technical indicators, making the verification results have a clear attribution basis.

[0060] Furthermore, regarding the acquisition process of the failed generation dataset, this application is summarized as an example for illustration: The first dataset is divided for training and evaluating the model. Based on the large model, code generation is performed on the first training dataset to obtain data pairs with failed generation. Specifically, it is achieved through the following methods: The first dataset is divided according to the ratio of 80% training set (the first training dataset) and 20% test set (the first test dataset). Each sample (the first data group) in the first training dataset is organized in Json format, and the fields include: instruction (natural language instruction, i.e., code generation instruction), solution (true value code), and test_cases (test cases). At the same time, using the large language model as the benchmark model, code generation tasks are performed on each instruction in the training set; the output of the benchmark model is a code string. In the code generation task, a deterministic strategy with a preset temperature of 0 can be uniformly used to ensure the stability of the output of the benchmark model, and the generated code is saved in the specified path in a preset format (for example: py format), and the generated log is retained for subsequent analysis.

[0061] Semantically compare the generated code with the true value code. If the two codes are exactly the same (character-by-character comparison), it is considered a successful generation and no further testing is required; if they are inconsistent, the corresponding test cases are further executed to test whether the functionality of the generated code meets the standard. The test can automatically execute the test cases by combining functions in Python with the exception capture mechanism and record whether all tests pass. Specifically, each test sample is dynamically injected into the Python sandbox environment for execution, and the maximum running time is set not to exceed 3 seconds. Timeout, throwing an exception, or failing an assertion are all considered failed generations. Codes that fail to pass the test cases or encounter errors during execution will be marked as failed generation samples and used as the basic data for subsequent instruction optimization.

[0062] In an implementable manner of the embodiments of the present application, when performing instruction optimization processing on multiple generation failure instructions, the following manner can also be adopted but is not limited to: using a preset instruction correction model to perform instruction optimization processing on multiple generation failure instructions respectively according to the failure information, obtaining multiple first optimized instructions, and inputting the multiple first optimized instructions into a preset code generation model for code generation processing to obtain first optimized codes corresponding to the multiple first optimized instructions respectively; performing code test processing on the multiple first optimized codes respectively through their corresponding test cases to obtain a first code passing rate, where the first code passing rate is the probability of the first optimized codes that meet the preset running conditions among the multiple first optimized codes; in the case where the first code passing rate is less than a preset passing rate threshold, using the preset instruction correction model to perform instruction optimization processing on the multiple first optimized instructions respectively to obtain multiple second optimized instructions, and performing code test processing on the multiple second optimized codes generated by the multiple second optimized instructions respectively through their corresponding test cases to obtain a second code passing rate; until the code passing rate of the optimized instructions corresponding to the multiple generation failure instructions respectively is greater than or equal to the preset passing rate threshold, or the number of times of performing instruction optimization on the multiple generation failure instructions reaches a preset optimization times threshold, obtaining an instruction optimization data set.

[0063] In the embodiments of the present application, the first optimized instruction refers to a new instruction generated after the first optimization of the generation failure instruction; the first optimized code refers to a code segment generated by driving the first optimized instruction. The first code passing rate refers to the test passing ratio of the generated code after the first round of optimization. The preset passing rate threshold is a threshold set by the user and is used as the lowest passing rate standard for determining whether the optimization is qualified (e.g., 100%).

[0064] The second optimized instruction is a deep optimization instruction generated when the first round fails to meet the standard; the second code passing rate refers to the test passing ratio of the generated code after the second round of optimization; the preset optimization times threshold is a threshold set by the user and refers to the upper limit of the maximum optimization iteration times allowed (e.g., 5 times).

[0065] When constructing the instruction optimization data set, the preset instruction correction model combines the failure information (including the type, location, and context of the code defect) to perform the first optimization on the generation failure instruction to generate the first optimized instruction (i.e., the instruction after preliminary rewriting). The first optimized instruction is input into the preset code generation model to execute code generation to obtain the corresponding first optimized code.

[0066] Subsequently, code testing is performed on the first optimized code (running the original test cases in a sandbox environment), and the first code passing rate, that is, the proportion of the first optimized code passing the test, is statistically calculated (for example: passing rate = number of passing samples / total number of samples). If the first code passing rate is lower than the preset passing rate threshold, it indicates that the optimization is insufficient, and secondary optimization needs to be initiated: the instruction correction model generates a second optimized instruction (deep improved version instruction) based on the previous result; the second optimized code is generated and tested again, and the second code passing rate is calculated. The iteration continues until the termination condition is met: the code passing rate of the optimization instruction in the current round ≥ the preset passing rate threshold; or the cumulative number of optimization times reaches the preset optimization threshold (such as: an upper limit of 5 times). Finally, the optimization results of multiple rounds are integrated to form an instruction optimization dataset.

[0067] The optimization dataset should at least include: the originally generated failed instructions and the optimization instructions for each round; the generated code and test results corresponding to each round of optimization instructions; the final optimization instructions with the passing rate meeting the standard or reaching the iteration upper limit.

[0068] The determination process of the instruction optimization dataset can achieve but is not limited to the following effects: the passing rate threshold ensures that the instruction quality meets the fundamental standard and avoids shallow optimization; the upper limit of the iteration times prevents infinite consumption of resources and balances the effect and efficiency. The defects of complex instructions (such as logical ambiguity and context missing) are gradually corrected through multiple rounds of optimization; each iteration uses the previous failure information for targeted improvement. The passing rate of the finally generated optimized instruction set is significantly higher than that of the original instructions; the dataset covers the complete optimization path from failure to success, providing high-quality positive and negative samples for model training.

[0069] In an implementable manner of the embodiment of the present application, when performing instruction optimization processing on multiple generated failed instructions to determine multiple first optimized instructions, the following methods can also be adopted but are not limited to: inputting the failure information into a preset instruction correction model for information extraction processing to obtain the error information corresponding to each of the multiple generated failed instructions, where the error information at least includes the error type, error location, and failure code; based on the preset instruction correction model, performing optimization information generation processing according to the error information to obtain the instruction optimization information corresponding to each of the multiple generated failed instructions, where the instruction optimization information at least includes the modification actions corresponding to each of the multiple generated failed instructions; performing instruction modification processing on the multiple generated failed instructions according to their respective corresponding modification actions to obtain multiple first optimized instructions, where the modification action is an instruction optimization method generated based on the error type, error location, and failure code.

[0070] In the embodiments of the present application, information extraction processing refers to a structured analysis process of automatically refining error types, locations, and code snippets from failure information. The error information is the three elements of code defects described in a standardized manner (type / location / failure code). Optimization information generation processing refers to an intelligent decision-making process of deriving an instruction modification strategy based on the error information. The instruction optimization information is a set of optimization solutions containing specific modification actions. The modification action refers to a correction operation for an instruction defect (such as semantic supplementation, redundancy reduction, etc.). Instruction modification processing refers to a conversion process of applying the modification action to the original instruction (generating a failed instruction) to generate an optimized instruction.

[0071] In the process of generating the first optimized instruction, the failure information (including the original diagnostic data recorded in the code verification stage) is input into a preset instruction correction model. The preset instruction correction model performs information extraction processing, extracts standardized error information from the failure information, and the error information at least includes: error type: identifying the nature of the defect (such as syntax error, variable undefined, logical contradiction, etc.); error location: locating the specific line number or function block of the defect in the code; failure code: marking the original text of the code snippet with a defect.

[0072] Based on the error information, the preset instruction correction model starts the optimization information generation processing, analyzes the root cause of the error, and generates targeted instruction optimization information. The core of the instruction optimization information is the modification action, that is, the correction strategy for the original instruction defect, specifically including but not limited to: Semantic supplementation: adding clear context to fuzzy descriptions (such as supplementing input / output examples); redundancy reduction: deleting irrelevant descriptions that interfere with model understanding; term standardization: converting colloquial expressions into standard programming terms; logic explicitization: converting implicit conditions into explicit constraints (such as clarifying loop boundaries).

[0073] Apply the modification action to the corresponding generated failed instruction, and perform instruction modification processing to generate the first optimized instruction. The instruction modification processing process is not a simple replacement, but a semantic reconstruction combining the error type and the failure code: if the error type is variable undefined, explicitly declare the variable scope in the instruction; if the error location points to the loop logic, strengthen the description of the iteration condition; if the failure code exposes the lack of boundary processing, supplement the description of the exception scenario in the instruction.

[0074] Accurately map to the corresponding description paragraph of the instruction through the error location to achieve defect traceability; drive the design of the modification action through the failure code snippet to ensure that the optimization is targeted. Through the modification action, not only the surface errors are repaired, but also the underlying logical expression of the instruction is reconstructed; through the high-order model, a professional-level optimization solution is generated based on the programming knowledge base. Through each optimized instruction, it can be traced back to the specific error type and modification action; providing a transparent instruction optimization path for developers.

[0075] In an implementable manner of the embodiment of the present application, when performing code test processing on multiple first optimized codes to determine the first code pass rate, the following method can also be used but is not limited to: performing code test processing on multiple first optimized codes through their respective corresponding test cases to obtain first test results; determining first passed codes among the multiple first optimized codes according to the first test results, where the first passed codes are first optimized codes that meet the preset running conditions; obtaining the first quantity of the first optimized codes and the second quantity of the first passed codes, and performing division processing according to the second quantity and the first quantity to obtain the first code pass rate.

[0076] In the embodiment of the present application, the first passed code value is an instance of the first optimized code that completely meets the preset running conditions in the test processing; the first quantity is the total sample number of the first optimized codes participating in the test; the second quantity is the qualified sample number of the first optimized codes that pass the test (i.e., the quantity of the first passed codes); where the first code pass rate = second quantity / first quantity.

[0077] When calculating the first code pass rate, based on the first test results, code samples that meet the preset running conditions (including criteria such as compliance with running time, no exception thrown, and all assertions passed) are automatically screened out and classified as first passed codes (i.e., instances of optimized codes with completely correct functions), and then the pass rate calculation process is started: Statistical total quantity of the first optimized codes (first quantity); statistical quantity of the first passed codes (second quantity); calculating the first code pass rate through division processing (i.e., second quantity divided by first quantity), and the first code pass rate objectively reflects the overall success rate of the first-round instruction optimization.

[0078] The pass rate value provides real-time feedback on the effectiveness of the instruction optimization, avoiding subjective evaluation biases; providing an objective decision-making basis for whether to start deep iteration. The test results directly drive the pass rate calculation, forming a complete chain of generation-validation-measurement; the confirmation of each first passed code provides high-quality positive samples for subsequent model training. A low pass rate exposes batches of instructions with insufficient optimization, guiding resources to focus on re-optimization areas; high-pass-rate samples can terminate iteration in advance, improving the overall efficiency of the system.

[0079] In an implementable manner of the embodiment of the present application, when performing instruction optimization processing on multiple first optimization instructions, the following method can also be used but is not limited to: obtaining first test failure information, where the first test failure information at least includes test information of the first optimized code that does not meet the preset running conditions; marking the first optimization instructions corresponding to the first optimized codes that do not meet the preset running conditions as optimization failure instructions based on the first test failure information; performing instruction optimization processing on the optimization failure instructions through a preset instruction correction model according to the first test failure information to obtain multiple second optimization instructions.

[0080] In an embodiment of the present application, the first test failure information includes complete diagnostic data of the test code that fails in the first-round optimization (i.e., the first optimized code that does not meet the preset running conditions), specifically covering: the type of exception thrown during runtime and the stack trace; the content of the failed assertion and the comparison of expected-actual values; and the system logs of timeout or abnormal process termination.

[0081] Based on the first test failure information, the associated first optimization instruction (the instruction corresponding to the test code that fails) is automatically marked as an optimization failure instruction, and the marking process follows the principle of causal association: if the failure information reveals an error in the variable scope, the paragraph with ambiguous variable description in the instruction is marked; if a missing boundary condition is detected, the undefined constraint condition in the instruction is located; if a logical contradiction is exposed, the ambiguous task description in the instruction is traced back.

[0082] The preset instruction correction model receives the optimization failure instruction and its corresponding first test failure information, and performs in-depth instruction optimization processing: expanding the error context in combination with the first test failure information; adjusting the aggressiveness of the modification action (e.g., using semantic refactoring rather than local correction for stubborn defects); and generating a second optimization instruction to solve the first test failure information.

[0083] Precise allocation of optimization resources is achieved through failure focus, that is, only the stubborn instruction defects that are not resolved in the first round are initiated for in-depth optimization, avoiding global repeated calculations; the failure information locates the specific defective paragraphs, realizing instruction-level targeted repair. The first test failure information reveals deep problems not covered in the first-round optimization (such as implicit logical contradictions); the instructions generated by the secondary optimization significantly increase the probability of meeting the passing rate threshold of the code; and a final solution is provided for complex instruction defects.

[0084] In an implementable manner of the embodiment of the present application, when obtaining the instruction optimization data set, the following manner can also be adopted but is not limited to: when the code passing rate of the optimized instructions corresponding to each of the multiple generated failed instructions is greater than or equal to the preset passing rate threshold, according to the multiple generated failed instructions, the optimized instructions corresponding to each of the multiple generated failed instructions, and the optimization processes corresponding to each of the multiple generated failed instructions, perform data set construction processing in a preset data format to obtain the instruction optimization data set, where the optimized instructions are all optimized successful instructions, and the code generated by the optimized successful instructions meets the preset running conditions; when the code passing rate of the optimized instructions corresponding to each of the multiple generated failed instructions is less than the preset passing rate threshold, continue to perform instruction optimization processing on the multiple generated failed instructions, and determine the number of times of instruction optimization for the multiple generated failed instructions; when the number of times of instruction optimization for the multiple generated failed instructions reaches the preset optimization number threshold, according to the multiple generated failed instructions, the first instructions corresponding to each of the multiple generated failed instructions, and the optimization process data corresponding to each of the multiple generated failed instructions, perform data set construction processing in a preset data format to obtain the instruction optimization data set, where the first instructions include optimized failed instructions and optimized successful instructions, and the code generated by the optimized failed instructions does not meet the preset running conditions.

[0085] In the embodiment of the present application, an optimized successful instruction refers to an optimized instruction whose finally generated code completely passes the test (meets the preset running conditions); an optimized failed instruction refers to an instruction that still cannot generate compliant code after reaching the iteration upper limit; the first instruction is a set of intermediate instructions generated during the iteration process (including successful / failed samples); the preset data format is a custom - set data format for structuring the data set organization specification (such as: Alpaca format); the optimization process data is a historical log recording instruction modification actions, test results, and error feedback.

[0086] When the code passing rate (i.e., the test passing ratio) of the code generated by the corresponding optimized instructions reaches or exceeds the preset passing rate threshold after all the generated failed instructions have been iteratively optimized, it is determined that the optimization goal has been achieved. At this time, perform data set construction processing: the data elements include the original generated failed instructions, the finally passed optimized successful instructions (whose generated code completely meets the preset running conditions), and the complete optimization process data (including historical records such as modification actions and test results in each round). Organize the data in a preset data format (such as: Alpaca quadruple format) to generate a high - quality instruction optimization data set, where all the optimized instructions are verified effective optimization results.

[0087] If, after iterative optimization of all generated failure instructions, the code passing rate of the code generated by the corresponding optimized instructions does not reach the preset passing rate threshold, but the number of optimization times has reached the preset optimization times threshold, the iteration is forced to terminate and a dataset is constructed: the original generated failure instructions are retained; the first instructions generated in each round (including some successfully optimized instructions and still-failed optimized failure instructions) are summarized; the complete optimization process data is recorded (highlighting the stubborn defects of the optimized failure instructions). Similarly, an instruction optimization dataset is generated in the preset data format. At this time, the dataset contains the complete optimization trajectories of positive and negative samples mixed together.

[0088] The construction of the instruction optimization dataset can achieve but is not limited to the following effects: the dataset produced in the passing scenario contains pure successfully optimized instructions, providing high-quality positive samples for model training; the termination scenario retains the optimized failure samples, forming precious negative example teaching materials to enhance the model's defect recognition ability. The passing rate threshold ensures the timely output of high-quality instructions and avoids excessive iteration; the upper limit of the number of times forces the termination of inefficient optimization to ensure real-time response ability. The optimization process data completely records the instruction evolution path, providing a traceability basis for subsequent model diagnosis; the mixed dataset reveals the optimization bottlenecks of complex instruction defects, guiding the continuous improvement direction of the algorithm.

[0089] Furthermore, regarding the construction process of the instruction optimization dataset, this application summarizes it with an example for illustration: for the failure data pair, that is, the generated failure dataset, an instruction optimization dataset containing a large number of failure instructions and optimized instructions is constructed based on the Markov decision process (preset instruction correction model). The instruction optimization dataset can be composed of quadruples. Among them, the parameters of the preset instruction correction model are as follows: State: Each state corresponds to a failure instruction to be optimized, representing the original natural language encoding task input to the large language model; Action: Each action represents a modification suggestion for the instruction, and the modification direction comes from the error feedback in the model generation process; Reward: Each newly generated instruction will be used to drive the code generation task, and the one-time code passing rate (code passing rate) is used as the evaluation index. It is used as the reward signal in the Markov decision process, and its change is used to drive the convergence and iteration termination of the instruction optimization strategy.

[0090] The specific construction process of the instruction optimization dataset includes but is not limited to the following methods: Trigger code generation using the original failed instruction in the first training dataset and record the reasons for failure, such as syntax errors, undefined variables, missing logic, etc. After organizing the error information in a structured format (including error type, error location, and the model output code segment), input it into the preset instruction correction model and request the preset instruction correction model to generate rewrite suggestions. The error type information is uniformly generated by combining AST syntax tree analysis with an exception capture mechanism, including multiple standardized error classifications such as syntax error (SyntaxError), indentation error (IndentationError), name error (NameError), type error (TypeError), assertion error (AssertionError), etc., and extract the deepest function and variable names in the stack as the context.

[0091] The preset instruction correction model optimizes the original instruction by performing modification actions. The modification methods include but are not limited to adjusting verb wording, streamlining redundant descriptions, supplementing context semantics, and instantiating expressions, etc. The generated new instruction will be input into the preset code generation model again as a new state for code generation and testing. If the preset instruction correction model gives multiple candidate solutions when generating a new instruction, the first one will be selected by default as the result of the current action.

[0092] The preset code generation model uses the new instruction to generate code and repeats the verification process. If all the code passes the test, that is, the code pass rate is 1, a positive reward is obtained and recorded in the instruction optimization dataset; if it still fails, iterate and optimize again. The entire optimization process is up to the preset optimization times threshold at most. Each newly generated instruction will be recorded, and finally an instruction optimization dataset is generated.

[0093] Finally, the construction of the instruction optimization dataset is completed. The instruction optimization dataset can be a quadruple of four items. Among them, it can include request information, the input instruction to be optimized, that is, the generated failed instruction, the optimized failed instruction and / or the optimized successful instruction, and the optimization process data.

[0094] In an implementable manner of the embodiment of the present application, when performing model training processing on the preset instruction optimization model, it can also be implemented by but not limited to the following methods: perform model training processing on the preset instruction optimization model according to the instruction optimization dataset and the preset model optimization strategy to obtain a trained instruction optimization model, where the preset model optimization strategy at least includes a preset learning rate adjustment strategy, a preset batch size, a preset optimizer, a preset number of iterations, a preset loss function, and a preset weight allocation strategy.

[0095] In the embodiments of the present application, the preset model optimization strategy is an optimization strategy set by the user, which at least covers the configuration schemes of training hyperparameters such as learning rate, batch size, and optimizer. The preset learning rate adjustment strategy is an adjustment strategy set by the user, which at least includes the learning rate dynamic scheduling mechanisms of learning rate warm-up and cosine decay. The preset batch size is the number of samples for a single forward / backward propagation (e.g., 32). The preset optimizer refers to the parameter update algorithm used in training, such as the AdamW optimizer (Adaptive Moment Estimation with Weight Decay, AdamW).

[0096] The preset number of iterations refers to the maximum training round threshold (e.g., 10 rounds). The preset loss function is the objective function for model training optimization (e.g., the Optimizing Rationales via Policy Optimization (ORPO) algorithm). The preset weight allocation strategy refers to the rule for dynamically adjusting the loss weights according to the sample difficulty.

[0097] When training the preset instruction optimization model, based on the instruction optimization dataset as the input, multiple strategies in the preset model optimization strategy are used to jointly control the training process, which at least includes: the preset learning rate adjustment strategy adopts a phased dynamic scheduling mechanism. In the initial stage, linear warm-up is performed to increase the learning rate from zero to the initial value (e.g., 3e-5). The warm-up period accounts for 10% of the total number of training steps. Subsequently, the cosine decay strategy is adopted to make the learning rate smoothly decline with the number of training rounds, effectively balancing the model convergence speed and stability; the preset batch size is set to a fixed number (e.g., 32), and combined with the gradient accumulation technique (the accumulation step is set to 4) to simulate the training effect of a larger batch and improve the utilization rate of hardware resources; the preset optimizer selects the AdamW algorithm to enhance the regularization effect by decoupling the weight decay mechanism; the preset number of iterations is set to a fixed number of rounds (e.g., 10 rounds), and an early stopping mechanism is embedded, that is, when the performance of the model on the validation set does not improve for two consecutive rounds, the training is immediately terminated to avoid ineffective calculations; the preset loss function adopts the odds ratio preference optimization algorithm (ORPO algorithm), and by comparing the differences between the optimized successful instructions and the optimized failed instructions, it drives the model to learn preference features; the preset weight allocation strategy dynamically adjusts the loss weights according to the sample difficulty: the weights of the difficult samples that caused the model to make wrong judgments in the previous round of evaluation are automatically increased, while the weights of the simple samples are correspondingly decreased, forcing the model to focus on the weak links and strengthen learning.

[0098] During the training execution process, multiple rounds of iteration are performed on the preset instruction optimization model according to the preset model optimization strategy. After each round of training, the model performance is evaluated using an independent validation set. If the early stopping condition is not triggered, the next round of training is entered. Through the synergistic effect of the preference alignment ability of the ORPO loss function and dynamic weight allocation, the model gradually masters the optimization mode of natural language instructions. For example, it learns key skills such as converting fuzzy verbs into precise programming terms and supplementing missing boundary condition declarations. The finally generated trained instruction optimization model has the ability of automatic instruction reconstruction, which can significantly improve the accuracy and executability of the user's original instructions.

[0099] Through the multi-dimensional collaboration of the preset model optimization strategy, the synchronous improvement of training efficiency and model performance is achieved. The cosine decay learning rate strategy ensures the stable convergence of the training process and avoids oscillations caused by sudden changes in the learning rate. The dynamic weight allocation mechanism significantly improves the generalization ability of the model to handle complex instruction defects by strengthening the learning weights of difficult samples. The early stopping mechanism and gradient accumulation technology minimize the computing power consumption while ensuring the accuracy. In particular, the ORPO algorithm, as the core loss function, deeply embeds human preference knowledge into the model parameters, making the generated optimized instructions more in line with the programmer's thinking mode. The overall strategy system forms a closed-loop optimization link from data to model, laying a high-performance foundation for subsequent tooling deployment.

[0100] In an implementable manner of the embodiment of the present application, when performing model parameter adjustment processing on the preset instruction optimization model, the following methods can also be used but are not limited to: performing model parameter adjustment processing on the preset instruction optimization model through an instruction optimization data set to obtain a first instruction optimization model, and performing model test processing on the first instruction optimization model according to a first test data set to obtain a first model test result; performing model parameter adjustment processing on the first instruction optimization model according to the first model test result to obtain a second instruction optimization model, and performing model test processing on the second instruction optimization model according to the first test data set to obtain a second model test result; when the first model test result and the second model test result meet the preset stopping condition, determining the second instruction optimization model as the trained instruction optimization model; when the first model test result and the second model test result do not meet the preset stopping condition, performing model parameter adjustment processing on the second instruction optimization model according to the second model test result until the number of times of model parameter adjustment reaches the preset iteration number to obtain the trained instruction optimization model.

[0101] In the embodiments of the present application, the model parameter adjustment process refers to the training process of updating the model weights according to a preset model optimization strategy (e.g., gradient backpropagation). The first instruction optimization model is the intermediate model version generated after the first round of parameter adjustment. The model testing process refers to the process of evaluating the model optimization instruction ability using the first test dataset. The first model test result at least includes the performance quantification metrics of the first instruction optimization model on the first test dataset. The second instruction optimization model is an improved model with parameters re-optimized based on the first model test result. The preset stop condition is a threshold criterion custom-set for determining performance convergence (e.g., the lower limit of the improvement range of the validation set accuracy). The preset number of iterations is the maximum allowed number of parameter adjustment rounds defined and set (e.g., 10 rounds). The trained instruction optimization model refers to the final output model that meets the stop condition or reaches the iteration upper limit.

[0102] Perform the first model parameter adjustment process on the preset instruction optimization model based on the instruction optimization dataset. The parameter adjustment process can adopt optimization strategies such as a preset learning rate adjustment strategy, batch size, and ORPO loss function to generate the initially optimized first instruction optimization model. Subsequently, use the independently reserved first test dataset (i.e., 20% of the test dataset in the first dataset partition) to perform the model testing process on this first instruction optimization model.

[0103] The model testing process at least includes: inputting the original failed instruction (generating a failed instruction) to the first instruction optimization model, evaluating the passing rate of the generated optimized instruction to drive code generation, and recording it as the first model test result (e.g., the code passing rate of the optimized instruction is 72%).

[0104] If the first model test result does not meet the expectation, start the feedback-driven re-optimization, that is, according to the weak links in the first model test result (e.g., poor optimization effect on loop logic instructions), targetedly adjust the training parameters (e.g., increase the weight of difficult samples), and perform the second round of model parameter adjustment process to generate the second instruction optimization model. Verify again through the same first test dataset to generate the second model test result. At this time, judge whether the first model test result and the second model test result meet the preset stop condition (for example: the improvement range of the validation set performance in two consecutive rounds is less than 5% (i.e., the improvement range of the second model test result compared to the first model test result), or the passing rate of the optimized instruction reaches 100%). If the condition is met, immediately terminate the training process and output the second instruction optimization model as the finally trained instruction optimization model; if not, continue to iterate until the cumulative number of model parameter adjustments reaches the preset number of iterations (e.g., 10-round upper limit), and forcefully output the current optimal model as the training result.

[0105] Through the closed-loop feedback of training and testing, the optimization of model parameters is dynamically adaptable. Each round of parameter adjustment is based on the defects exposed in the previous test for targeted improvement. For example, for a model with weak data type processing, the training weight of corresponding samples is enhanced. The intelligent determination of the preset stop condition effectively avoids the risk of overfitting, automatically terminates the training when the model performance tends to be stable, and saves computing resources; while the hard constraint on the number of iterations ensures the output of a usable model under limited resources. The loop verification strategy makes the final model have both performance superiority and training efficiency, providing a highly reliable kernel for the automated instruction optimization tool.

[0106] In an implementable manner of the embodiment of the present application, when performing model testing on the first instruction optimization model, the following manner can also be adopted but is not limited to: extracting data from the first test dataset through a preset few-shot prompting strategy to obtain the first dataset, and dividing the other datasets into a second dataset and a third dataset, where the other datasets are the datasets in the first test dataset except the first dataset; inputting the third dataset into the first instruction optimization model for instruction optimization processing to obtain an optimized third dataset; inputting the first dataset, the second dataset, and the optimized third dataset into a preset code generation model for code generation processing respectively, and performing code testing through test cases to obtain the first test passing rate corresponding to the first dataset, the second test passing rate corresponding to the second dataset, and the third test passing rate corresponding to the optimized third dataset; if the third test passing rate is greater than the first test passing rate and the second test passing rate, it is determined that the first model test result is a positive result, and if the third test passing rate is not greater than the first test passing rate and / or the second test passing rate, it is determined that the first model test result is a non-positive result.

[0107] In the embodiment of the present application, the preset few-shot prompting strategy is a custom-set strategy, which refers to the methodology of selecting high-quality instruction samples to construct a benchmark control group. The first dataset is a set of high-quality instruction samples extracted through the few-shot strategy. The other datasets are the remaining samples in the first test dataset except the first dataset. The second dataset refers to the subset of the original unoptimized instructions divided from the other datasets. The third dataset refers to the experimental subset composed of the instructions to be optimized in the other datasets. The optimized third dataset refers to the set of instructions obtained by optimizing the third dataset through the model.

[0108] The first test passing rate is the code test passing rate of the few-shot prompting group (the first dataset). The second test passing rate is the code test passing rate of the original instruction group (the second dataset). The third test passing rate is the code test passing rate of the optimized instruction group (the optimized third dataset). The positive result represents the evaluation conclusion that the optimized group simultaneously surpasses the few-shot group and the original group. The non-positive result represents the determination of the model performance that does not meet the double-advantage standard.

[0109] By presetting a few-shot prompting strategy, high-quality instruction samples are extracted from the independently reserved first test dataset as the first dataset (e.g., select 10 sets of instruction-code pairs with complete functions and clear expressions), and a reference group for code generation ability is constructed. The remaining test data (i.e., other datasets) are evenly divided into the second dataset (original unoptimized instructions) and the third dataset (instructions to be optimized), forming three groups of control samples.

[0110] The third dataset is input into the first instruction optimization model for instruction optimization processing to generate an optimized third dataset with semantic reconstruction; the three datasets (the first dataset, the second dataset, and the optimized third dataset) are respectively input into the preset code generation model to execute code generation; the generated code is automatically verified through a unified test case, and the following are recorded: the first test pass rate (the baseline pass rate of the few-shot prompting group); the second test pass rate (the comparative pass rate of the original instruction group); the third test pass rate (the performance index of the optimized instruction group).

[0111] The determination link can adopt the principle of relative advantage: if the third test pass rate is higher than both the first test pass rate and the second test pass rate at the same time, it is confirmed that the optimization model significantly improves the code generation quality, and the first test result is determined as a positive result; otherwise, if the optimized instructions do not exceed the baseline level of the few-shot prompting group or are not significantly better than the original instruction group, the determination result is a non-positive result, indicating that the model needs further optimization.

[0112] Break through the limitations of traditional single-index comparison through a three-level evaluation mechanism. By introducing a few-shot prompting strategy to construct the industry's best practice baseline (the first dataset), and at the same time retaining the original instruction control group (the second dataset), the ability verification of the optimization model has a three-dimensional reference system. The optimization group needs to exceed the dual standards of selected prompts and original inputs at the same time, eliminating the contingency of evaluation results. When the pass rate of the optimized instruction group is higher than both the best example of natural language expression and the unoptimized instructions at the same time, the effectiveness and universality of the model optimization strategy can be strictly proved, providing a reliable basis for the model iteration direction.

[0113] In an implementable manner of the embodiment of the present application, when adjusting the model parameters of the first instruction optimization model, the following methods may also be used but are not limited to: determining multiple optimization abnormal data in the third dataset for optimization according to the first model test result, where the code generated by the optimization abnormal data does not meet the preset running conditions; based on the preset weight allocation strategy, performing weight allocation processing on the multiple optimization abnormal data in the preset loss function to obtain an updated loss function; when it is determined that the first model test result is a positive result, adjusting the model parameters of the first instruction optimization model according to the updated loss function and the preset model optimization strategy to obtain a second instruction optimization model; when it is determined that the first model test result is a non-positive result, in response to the received update information, performing strategy update processing on the preset model optimization strategy to obtain an updated preset model optimization strategy, and adjusting the model parameters of the first instruction optimization model according to the updated loss function and the updated preset model optimization strategy to obtain a second instruction optimization model.

[0114] In the embodiment of the present application, the optimization abnormal data refers to instruction samples whose generated code still does not meet the preset running conditions after model optimization. The preset weight allocation strategy is a rule system for dynamically adjusting the loss weight according to the sample defect type. The updated loss function refers to the ORPO loss function corrected by abnormal data weighting. The model parameter adjustment process is a training process for updating the model weights based on the reverse propagation of the loss function. The update information refers to optimization strategy adjustment suggestions (such as: hyperparameter change, algorithm replacement). The strategy update process refers to the in-depth correction process of the preset model optimization strategy. The updated preset model optimization strategy is a training configuration plan integrating new rules.

[0115] After completing the performance test of the first instruction optimization model, implement a differential parameter adjustment strategy according to the first test result. First, locate the optimization abnormal data in the third dataset for optimization through the first test result, that is, instruction samples whose generated code still does not meet the preset running conditions after model optimization. The root cause is that the instruction semantics have not been fully corrected or new defects have been introduced.

[0116] The preset weight allocation strategy then intervenes in the process, and dynamically increases its weight coefficient in the preset loss function (ORPO algorithm) according to the distribution characteristics of the optimization abnormal data in the training set. For example: for the frequently occurring boundary condition missing errors, the loss weight of the corresponding samples is increased by 50%, forming a more targeted updated loss function. The dynamic weighting enables the model to focus on learning the weak links in the next round of training.

[0117] If the first test result is a positive result (i.e., the optimized instruction set (optimizing the third data set) outperforms both the few-shot baseline group (the first data set) and the original instruction set (the second data set)), it proves that the current model has optimization effectiveness. Directly adopt the updated loss function combined with the existing preset model optimization strategy to perform model parameter adjustment processing on the first instruction optimization model, and generate an enhanced second instruction optimization model.

[0118] If the test result is not a positive result, then trigger deep tuning, receive update information input externally or generated by an algorithm (such as: change in the learning rate decay scheme, optimizer switching suggestion), and perform strategy update processing on the preset model optimization strategy according to the update information. For example: replace the AdamW optimizer with the Lion optimizer (Evolving the Optimization for Deep Learning, LION), or adjust the learning rate warm-up ratio from 10% to 15%, and generate an updated preset model optimization strategy. Subsequently, perform parameter adjustment by integrating the updated loss function and the new strategy to form a second instruction optimization model with upgraded capabilities.

[0119] Through the precise capture and weight reallocation of optimization abnormal data, the model can quickly focus on its own defects; the lossless optimization under positive results ensures continuous performance improvement, while the strategy update triggered by non-positive results provides a systematic correction ability. This hierarchical response mechanism can not only exert the efficiency advantage of automated optimization but also break through local performance bottlenecks through dynamic strategy adjustment, significantly improving the model's ability to correct complex instruction defects and endowing the training process with the vitality of self-diagnosis and continuous evolution.

[0120] Furthermore, regarding the training process of the preset instruction optimization model, this application is summarized in an example for illustration: In the model training stage, the present invention uses the Odds Ratio Preference Optimization algorithm (ORPO algorithm) and the Low-Rank Adaptation (LoRa) method for large model fine-tuning. The training process uses a structured data set in the format of a quadruple, namely the instruction optimization data set, for training. The instruction optimization data set contains at least an instruction, an input, an optimized instruction, and a rejected instruction, so as to accurately guide the model on how to generate an output that meets user requirements when facing similar code generation tasks.

[0121] The fine-tuning training process is carried out through multiple rounds of iteration. After each round of fine-tuning, the first test dataset is input into the fine-tuned model to evaluate the model performance. During the testing process, 20% of the first dataset is used as the test set, and the ability of the model in the automatic optimization instruction task is verified through a large number of test instances, including improving the accuracy of code generation and the ability to align with user requirements. When evaluating the effect, a comparative analysis will be carried out: First, record the one-pass rate of the code generated by directly inputting the initial instruction without any optimization into the benchmark large model; Second, we will adopt the few-shot prompting strategy, that is, select a small number of typical and high-quality instructions and their corresponding codes as examples for the preset code generation model to refer to, and then input the original instruction, and record the one-pass rate of code generation at this time; Finally, input the instructions optimized by the trained instruction optimization model into the preset code generation model, and record the one-pass rate of its code generation. By comparing the pass rate indicators of these three (initial instruction, few-shot prompting instruction, optimized instruction) in the code generation task, the performance of the trained instruction optimization model in instruction optimization can be clearly demonstrated.

[0122] If the code pass rate of the code generated by the optimized instruction is significantly higher than that of the initial instruction and the few-shot prompting instruction, it proves that the fine-tuning effect is good. Adjust the fine-tuning parameters according to the test results and perform the next round of fine-tuning. The specific fine-tuning strategies include the following aspects: Learning rate adjustment, the initial learning rate is set to 3e−5. The learning rate warm-up and cosine decay strategies are adopted. At the beginning of training, the learning rate linearly increases from 0 to the preset initial learning rate, and this warm-up process accounts for 10% of the total training steps. After that, the learning rate adopts the cosine decay strategy until the training ends. In terms of sample weight allocation, the weights of samples are dynamically adjusted according to their performance in the previous round of evaluation. For difficult samples that caused the model to make incorrect judgments or poor optimization effects in the previous round of testing, increase their weights in the calculation of the loss function, so that the model pays more attention to these difficult-to-learn instances in subsequent training. For simple samples that can already be well processed, reduce their weights. The batch size is selected as 32. The optimizer is selected as AdamW, the number of iteration rounds is set to 10 rounds, and the early stopping strategy is combined. After each round of training ends, evaluate the model performance on the validation set. If the performance of the model on the validation set does not improve for 2 consecutive rounds, terminate the training in advance and select the model with the best performance on the validation set.

[0123] To effectively utilize hardware resources, gradient accumulation technology can also be adopted, with the accumulation step set to 4 to achieve the effect equivalent to training with a larger batch size. At the same time, to prevent overfitting, a dropout rate parameter is used during the training process, which is set to 0.1. Through the iterative optimization process, the model can gradually improve its ability to optimize instructions. After the fine-tuning process is completed, the generated model shows a significant enhancement in instruction optimization performance in the code generation task and can provide more accurate optimization suggestions.

[0124] In an implementable manner of the embodiment of the present application, when performing instruction optimization processing on the instruction to be optimized through the trained instruction optimization model, the following methods can also be adopted but are not limited to: deploying the trained instruction optimization model to a preset instruction optimization tool, where the preset instruction optimization tool at least includes an interface tool and a visualization tool; receiving the instruction to be optimized based on the interface tool, and in response to the triggered instruction optimization signal, performing instruction optimization processing on the instruction to be optimized through the trained instruction optimization model to obtain the target instruction; and performing visualization processing on the instruction to be optimized and the target instruction through the visualization tool.

[0125] In the embodiment of the present application, the interface tool provides an Application Programming Interface (API) service, supporting direct calls from development environments such as code editors and automation scripts; the visualization tool is a graphical interaction interface that allows users to perform visualization operations through a browser. The two tools share the same model kernel to ensure the consistency of the optimization logic. In specific applications, first, the trained instruction optimization model is embedded in the tool backend through model merging and quantization techniques. For example, based on the Large Language Model Training&Fine-tuning Factory (LLaMA Factory), model weight fusion and lightweight compression are achieved, significantly reducing the deployment resource requirements.

[0126] After the tool deployment is completed, users can trigger the optimization process through different channels: when using the interface tool, the original instruction to be optimized (e.g., processing file data for a fuzzy code generation requirement) is sent to the server as an API request parameter. The tool automatically generates an instruction optimization signal to start model processing. The trained instruction optimization model analyzes the semantic defects of the instruction and generates the reconstructed target instruction (e.g., supplement it to read the file and calculate the average value of the second column), which is returned to the caller through the API response; when using the visualization tool, the user enters the instruction to be optimized in the web form and clicks the optimization button to trigger the same signal. The target instruction output by the model will be displayed on the interactive interface in real time. To ensure the transparency of the optimization process, the visualization tool additionally performs a visualization processing function: displaying the text comparison of the original instruction to be optimized and the target instruction side by side, and at the same time using semantic highlighting technology to mark the key optimization points (e.g., newly added input format descriptions, corrected action verbs, etc.) to help users intuitively understand the optimization logic.

[0127] The tool-based deployment mechanism significantly reduces the technical threshold for users to use the optimization model. The interface tool is deeply integrated with the development environment through a standardized API, enabling developers to obtain optimization suggestions without interrupting the workflow; the visualization tool provides a zero-code interaction experience, helping non-technical users quickly master the instruction optimization method. The semantic highlighting and comparison function establishes a visual understanding of the model's optimization logic for users, enhancing the interpretability and credibility of the optimization results. The entire system forms a complete closed-loop from model training to industrial implementation while ensuring the optimization effect.

[0128] In summary, the embodiments of the present application can achieve the following technical effects: 1. By constructing a model based on the Markov decision process, a fine-tuning dataset for adjusting the instruction optimization model, namely the instruction optimization dataset, is generated. Based on the instruction optimization dataset, the instruction optimization model is fine-tuned, enabling the instruction optimization model to optimize the instruction to be optimized, and thus helping users generate code that meets the requirements and automatically optimizing the instructions input by users. Therefore, it can solve the technical problem of how to quickly determine instructions that meet the requirements to improve the optimization efficiency of instructions, and achieve the technical effect of quickly determining instructions that meet the requirements and improving the optimization efficiency of instructions.

[0129] 2. Improve the automation and intelligence level of coding instruction optimization: Traditionally, manually generating or optimizing coding instructions is not only time-consuming and laborious but also highly dependent on the experience and professional knowledge of users. Especially in code generation tasks, the accuracy requirements for coding instructions are extremely high. By introducing the Markov decision process, an optimization dataset is automatically generated and fine-tuned based on a high-order large model, thus significantly improving the automation and intelligence of the optimization process. The system continuously analyzes error feedback and adjusts the content of the input instructions, reducing the time for manually optimizing coding instructions.

[0130] 3. Improve the quality of instructions in code generation tasks: For code generation tasks, the quality of the coding instructions directly determines the accuracy and practicality of the model's output code. By using the ORPO algorithm to fine-tune the model and through multiple rounds of generation and testing, it is ensured that more accurate and effective instructions can be provided for code generation tasks. The optimized instructions effectively improve the performance of code generation tasks.

[0131] 4. Help beginners quickly get started with code generation tasks: For beginners, writing appropriate instructions is a challenging task, especially for the specific requirements of code generation. Through the automatic optimization tool, simple and efficient coding instruction optimization support is provided for beginners. Users only need to input the initial instructions, and the system will automatically generate optimization suggestions to help novice users gradually master how to write efficient code generation instructions, reducing the usage threshold.

[0132] 5. Improve development efficiency: By using the ORPO algorithm to fine-tune the model, the large language model can gradually align preferences and output coding instruction results that better meet user needs. Through systematic instruction optimization, developers can quickly obtain accurate code snippets in complex code generation tasks, reducing the time and labor costs of repeated debugging.

[0133] Through the description of the above implementation manners, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases, the former is a better implementation manner.

[0134] The embodiments of the present application also provide a device for instruction optimization, Figure 3 which is a schematic structural diagram of a device for instruction optimization provided by the present application, as Figure 3 shown, including: A generating unit 31, configured to input the obtained first training data set into a preset code generation model for code generation processing to obtain a generation failure data set in the first training data set, where the generation failure data set includes multiple generation failure instructions and failure information corresponding to each of the multiple generation failure instructions; A first optimization unit 32, configured to perform instruction optimization processing on the multiple generation failure instructions respectively according to the failure information through a preset instruction correction model to obtain an instruction optimization data set, where the instruction optimization data set at least includes multiple generation failure instructions, optimized instructions corresponding to each of the multiple generation failure instructions, and optimization process data, and the preset instruction correction model is a model constructed based on a Markov decision process; A training unit 33, configured to perform model training processing on a preset instruction optimization model according to the instruction optimization data set to obtain a trained instruction optimization model; A second optimization unit 34, configured to perform instruction optimization processing on the instruction to be optimized through a trained instruction optimization model to obtain a target instruction.

[0135] In an embodiment of the present application, as Figure 4 shown, the instruction optimization device further includes: A screening unit 35, configured to perform data screening processing on a preset database to obtain a first data set, where the preset database includes multiple data sets; A partitioning unit 36, configured to perform data set partitioning processing on the first data set according to a preset partitioning method to obtain a first training data set and a first test data set.

[0136] In an embodiment of the present application, the screening unit 35 is further configured to: Obtain the data set information corresponding to each of the multiple data sets in the preset database, where the data set information at least includes data scale, data relevance, data complexity, testability, programming language coverage, and referability; According to the data scale, data relevance, data complexity, testability, programming language coverage, and referability, calculate the data set scores of each of the multiple data sets through a first preset weight to obtain the data set scores corresponding to each of the multiple data sets; Determine the data set with the largest data set score among the multiple data sets as the first data set.

[0137] In an embodiment of the present application, the generating unit 31 is further configured to: Input multiple first data groups in the first training data set into a preset code generation model for code generation processing to obtain generated codes corresponding to each of the multiple first data groups, where each first data group includes a code generation instruction, as well as a true value code and a test case corresponding to the code generation instruction; According to the multiple true value codes and multiple test cases, perform code verification processing on the corresponding generated codes respectively to obtain code verification results; Determine the multiple verification failure codes and the failure information corresponding to each of the multiple verification failure codes in the multiple generated codes, and construct a generation failure data set through the first data group corresponding to each of the multiple verification failure codes and the failure information.

[0138] In an embodiment of the present application, the generating unit 31 is further configured to: Perform semantic comparison processing on the multiple generated codes with their corresponding true value codes respectively to obtain semantic comparison results corresponding to each of the multiple generated codes; Determine a plurality of first codes and a plurality of second codes according to the semantic comparison results, and determine the plurality of first codes as the successfully verified codes, where the first codes are the generated codes that are semantically consistent with the true value code among the plurality of generated codes, and the second codes are the generated codes that are semantically inconsistent with the true value code among the plurality of generated codes; Perform code testing processing on the plurality of second codes through their respective corresponding test cases to obtain code test results; Determine a plurality of unpassed test codes and a plurality of passed test codes among the plurality of second codes according to the code test results, and determine the plurality of passed test codes as the successfully verified codes, and determine the plurality of unpassed test codes as the plurality of failed verification codes, where the code test results include the failure information corresponding to each of the plurality of unpassed test codes.

[0139] In an embodiment of the present application, the generation unit 31 is further configured to: Perform code running processing on the plurality of second codes through their respective corresponding test cases to obtain code running information; Determine a plurality of codes that meet the preset running conditions among the plurality of second codes as the plurality of passed test codes according to the code running information, where the preset running conditions at least include running time, throwing status, assertion passing status, and / or running status; Determine a plurality of codes that do not meet the preset running conditions among the plurality of second codes as the plurality of unpassed test codes according to the code running information.

[0140] In an embodiment of the present application, the first optimization unit 32 is further configured to: Perform instruction optimization processing on the plurality of generated failure instructions respectively by the preset instruction correction model according to the failure information to obtain a plurality of first optimized instructions, and input the plurality of first optimized instructions into the preset code generation model for code generation processing to obtain the first optimized codes corresponding to the plurality of first optimized instructions; Perform code testing processing on the plurality of first optimized codes through their respective corresponding test cases to obtain the first code passing rate, where the first code passing rate is the probability of the first optimized codes that meet the preset running conditions among the plurality of first optimized codes; In the case where the first code passing rate is less than the preset passing rate threshold, perform instruction optimization processing on the plurality of first optimized instructions respectively by the preset instruction correction model to obtain a plurality of second optimized instructions, and perform code testing processing on the plurality of second optimized codes generated by the plurality of second optimized instructions through their respective corresponding test cases to obtain the second code passing rate, and obtain the second code passing rate; Until the code passing rate of the optimized instructions corresponding to each of the multiple generation failure instructions is greater than or equal to a preset passing rate threshold, or the number of times of optimizing the instructions for the multiple generation failure instructions reaches a preset optimization times threshold, an instruction optimization data set is obtained.

[0141] In an embodiment of the present application, the first optimization unit 32 is further configured to: Input the failure information into a preset instruction correction model for information extraction processing to obtain error information corresponding to each of the multiple generation failure instructions, where the error information at least includes an error type, an error location, and a failure code; Based on the preset instruction correction model, perform optimization information generation processing according to the error information to obtain instruction optimization information corresponding to each of the multiple generation failure instructions, where the instruction optimization information at least includes modification actions corresponding to each of the multiple generation failure instructions; Perform instruction modification processing on the multiple generation failure instructions according to the corresponding modification actions to obtain multiple first optimized instructions, where the modification action is an instruction optimization method generated based on the error type, the error location, and the failure code.

[0142] In an embodiment of the present application, the first optimization unit 32 is further configured to: Perform code testing processing on the multiple first optimized codes through their respective corresponding test cases to obtain a first test result; Determine first passing codes among the multiple first optimized codes according to the first test result, where the first passing codes are first optimized codes that meet the preset running conditions; Obtain a first quantity of the first optimized codes and a second quantity of the first passing codes, and perform division processing according to the second quantity and the first quantity to obtain a first code passing rate.

[0143] In an embodiment of the present application, the first optimization unit 32 is further configured to: Obtain first test failure information, where the first test failure information at least includes test information of the first optimized codes that do not meet the preset running conditions; Based on the first test failure information, mark the first optimized instructions corresponding to the first optimized codes that do not meet the preset running conditions as optimization failure instructions; Perform instruction optimization processing on the optimization failure instructions through the preset instruction correction model according to the first test failure information to obtain multiple second optimized instructions.

[0144] In an embodiment of the present application, the first optimization unit 32 is further configured to: When the code passing rate of the optimized instructions corresponding to each of the multiple generation failure instructions is greater than or equal to the preset passing rate threshold, a dataset construction process is performed according to the multiple generation failure instructions, the optimized instructions corresponding to each of the multiple generation failure instructions, and the optimization processes corresponding to each of the multiple generation failure instructions in a preset data format to obtain an instruction optimization dataset, where the optimized instructions are all optimized successful instructions, and the code generated by the optimized successful instructions meets the preset running conditions; When the code passing rate of the optimized instructions corresponding to each of the multiple generation failure instructions is less than the preset passing rate threshold, the instruction optimization process for the multiple generation failure instructions is continued, and the number of times of instruction optimization for the multiple generation failure instructions is determined; When the number of times of instruction optimization for the multiple generation failure instructions reaches the preset optimization times threshold, a dataset construction process is performed according to the multiple generation failure instructions, the first instructions corresponding to each of the multiple generation failure instructions, and the optimization process data corresponding to each of the multiple generation failure instructions in a preset data format to obtain an instruction optimization dataset, where the first instructions include optimized failure instructions and optimized successful instructions, and the code generated by the optimized failure instructions does not meet the preset running conditions.

[0145] In an embodiment of the present application, the training unit 33 is further configured to perform model training on a preset instruction optimization model according to the instruction optimization dataset and a preset model optimization strategy to obtain a trained instruction optimization model, where the preset model optimization strategy includes at least a preset learning rate adjustment strategy, a preset batch size, a preset optimizer, a preset number of iterations, a preset loss function, and a preset weight allocation strategy.

[0146] In an embodiment of the present application, the training unit 33 is further configured to: Perform model parameter adjustment on the preset instruction optimization model through the instruction optimization dataset to obtain a first instruction optimization model, and perform model testing on the first instruction optimization model according to the first test dataset to obtain a first model test result; Perform model parameter adjustment on the first instruction optimization model according to the first model test result to obtain a second instruction optimization model, and perform model testing on the second instruction optimization model according to the first test dataset to obtain a second model test result; When the first model test result and the second model test result meet the preset stop condition, determine the second instruction optimization model as the trained instruction optimization model; When the first model test result and the second model test result do not meet the preset stop condition, perform model parameter adjustment on the second instruction optimization model according to the second model test result until the number of times of model parameter adjustment reaches the preset number of iterations to obtain a trained instruction optimization model.

[0147] In one embodiment of the present application, the training unit 33 is further configured to: Extract data from the first test data set through a preset few-shot prompting strategy to obtain a first data set, and divide the other data sets into a second data set and a third data set, where the other data sets are the data sets in the first test data set except the first data set; Input the third data set into the first instruction optimization model for instruction optimization processing to obtain an optimized third data set; Input the first data set, the second data set, and the optimized third data set into a preset code generation model for code generation processing respectively, and perform code testing through test cases to obtain a first test pass rate corresponding to the first data set, a second test pass rate corresponding to the second data set, and a third test pass rate corresponding to the optimized third data set; If the third test pass rate is greater than the first test pass rate and the second test pass rate, determine that the first model test result is a positive result. If the third test pass rate is not greater than the first test pass rate and / or the second test pass rate, determine that the first model test result is a non-positive result.

[0148] In one embodiment of the present application, the training unit 33 is further configured to: Determine multiple optimized abnormal data in the optimized third data set according to the first model test result, where the code generated by the optimized abnormal data does not meet the preset running conditions; Based on a preset weight allocation strategy, perform weight allocation processing on the multiple optimized abnormal data in a preset loss function to obtain an updated loss function; When it is determined that the first model test result is a positive result, perform model parameter adjustment processing on the first instruction optimization model according to the updated loss function and a preset model optimization strategy to obtain a second instruction optimization model; When it is determined that the first model test result is a non-positive result, respond to the received update information to perform strategy update processing on the preset model optimization strategy to obtain an updated preset model optimization strategy, and perform model parameter adjustment processing on the first instruction optimization model according to the updated loss function and the updated preset model optimization strategy to obtain a second instruction optimization model.

[0149] In one embodiment of the present application, the second optimization unit 34 is further configured to: Deploy the trained instruction optimization model to a preset instruction optimization tool, where the preset instruction optimization tool at least includes an interface tool and a visualization tool; Receive the instruction to be optimized based on the interface tool, and in response to the triggered instruction optimization signal, perform instruction optimization processing on the instruction to be optimized through the trained instruction optimization model to obtain a target instruction; Visualize the instructions to be optimized and the target instructions through a visualization tool.

[0150] For the descriptions of the features in the corresponding embodiments of the apparatus for instruction optimization, reference can be made to the relevant descriptions in the corresponding embodiments of the method for instruction optimization, which will not be elaborated here one by one.

[0151] An embodiment of the present application further provides an electronic device, including a memory and a processor. A computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any of the above method embodiments for instruction optimization.

[0152] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps in any of the above method embodiments for instruction optimization when running.

[0153] In an exemplary embodiment, the above computer-readable storage medium may include, but is not limited to: USB flash drives, read-only memories (ROM for short), random access memories (RAM for short), mobile hard disks, magnetic disks, or optical discs and other various media that can store computer programs.

[0154] An embodiment of the present application further provides a computer program product. The above computer program product includes a computer program, and when the computer program is executed by a processor, it implements the steps in any of the above method embodiments for instruction optimization.

[0155] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium. The non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements the steps in any of the above method embodiments for instruction optimization.

[0156] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.

[0157] The above has introduced in detail a method and apparatus for instruction optimization, an electronic device, and a storage medium provided by the present application. Specific examples are used in this article to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application. It should be noted that for those of ordinary skill in the art in this technical field, without departing from the principle of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the protection scope of the claims of the present application.

Claims

1. A method for instruction optimization, characterized in that, Including: Inputting the obtained first training data set into a preset code generation model for code generation processing to obtain a generation failure data set in the first training data set, where the generation failure data set includes a plurality of generation failure instructions and failure information corresponding to each of the plurality of generation failure instructions; Optimizing the instructions of the plurality of generation failure instructions respectively through a preset instruction correction model according to the failure information to obtain an instruction optimization data set, where the instruction optimization data set at least includes the plurality of generation failure instructions, optimized instructions corresponding to each of the plurality of generation failure instructions, and optimization process data, and the preset instruction correction model is a model constructed based on a Markov decision process; Performing model training processing on a preset instruction optimization model according to the instruction optimization data set to obtain a trained instruction optimization model, and performing instruction optimization processing on an instruction to be optimized through the trained instruction optimization model to obtain a target instruction.

2. The method for optimizing instructions according to claim 1, wherein Before inputting the obtained first training data set into a preset code generation model for code generation processing to obtain a generation failure data set in the first training data set, the method further includes: Performing data screening processing on a preset database to obtain a first data set, where the preset database includes a plurality of data sets; Performing data set partitioning processing on the first data set according to a preset partitioning method to obtain the first training data set and a first test data set.

3. The method for optimizing instructions according to claim 2, wherein The performing data screening processing on a preset database to obtain a first data set includes: Obtaining data set information corresponding to each of the plurality of data sets in the preset database, where the data set information at least includes data scale, data relevance, data complexity, testability, programming language coverage, and referability; Calculating data set scores corresponding to each of the plurality of data sets through a first preset weight according to the data scale, the data relevance, the data complexity, the testability, the programming language coverage, and the referability to obtain data set scores corresponding to each of the plurality of data sets; Determining the data set with the largest data set score among the plurality of data sets as the first data set.

4. The method for optimizing instructions according to claim 2, wherein The inputting the obtained first training data set into a preset code generation model for code generation processing to obtain a generation failure data set in the first training data set includes: Inputting a plurality of first data groups in the first training data set into the preset code generation model for code generation processing to obtain generated codes corresponding to each of the plurality of first data groups, where each first data group includes a code generation instruction, and a true value code and a test case corresponding to the code generation instruction; Performing code verification processing on the generated codes corresponding to each of them respectively according to a plurality of the true value codes and a plurality of the test cases to obtain code verification results; Determine multiple verification failure codes among the multiple generated codes and the corresponding failure information for each of the multiple verification failure codes according to the code verification result, and construct a generation failure data set through the first data group corresponding to each of the multiple verification failure codes and the failure information.

5. The method for optimizing instructions according to claim 4, wherein The code verification process of respectively performing code verification on the corresponding generated codes according to multiple true value codes and multiple test cases, and obtaining the code verification result includes: Perform semantic comparison processing on the multiple generated codes with their corresponding true value codes respectively to obtain semantic comparison results corresponding to the multiple generated codes; Determine multiple first codes and multiple second codes according to the semantic comparison results, and determine the multiple first codes as verification success codes, where the first codes are the generated codes among the multiple generated codes that are semantically compared and consistent with the true value codes, and the second codes are the generated codes among the multiple generated codes that are semantically compared and inconsistent with the true value codes; Perform code testing processing on the multiple second codes through their corresponding test cases respectively to obtain code testing results; Determine multiple unpassed test codes and multiple passed test codes among the multiple second codes according to the code testing results, determine the multiple passed test codes as the verification success codes, and determine the multiple unpassed test codes as the multiple verification failure codes, where the code testing results include the failure information corresponding to each of the multiple unpassed test codes.

6. The method for optimizing instructions according to claim 5, wherein The process of performing code testing processing on the multiple second codes through their corresponding test cases respectively to obtain code testing results includes: Perform code running processing on the multiple second codes through their corresponding test cases respectively to obtain code running information; Determine the multiple second codes that meet the preset running conditions among the multiple second codes as the multiple passed test codes according to the code running information, where the preset running conditions at least include running time, throw status, assertion pass status, and / or running status; Determine the multiple second codes that do not meet the preset running conditions among the multiple second codes as the multiple unpassed test codes according to the code running information.

7. The method for optimizing instructions according to claim 4, characterized in that, The process of optimizing the instructions of the multiple generation failure instructions respectively by the preset instruction correction model according to the failure information to obtain an instruction optimization data set includes: Optimize the instructions of the multiple generation failure instructions respectively by the preset instruction correction model according to the failure information to obtain multiple first optimized instructions, and input the multiple first optimized instructions into the preset code generation model for code generation processing to obtain first optimized codes corresponding to the multiple first optimized instructions; Perform code testing processing on the multiple first optimized codes through their corresponding test cases respectively to obtain a first code passing rate, where the first code passing rate is the probability of the first optimized codes that meet the preset running conditions among the multiple first optimized codes. When the first code passing rate is less than the preset passing rate threshold, the preset instruction correction model is used to optimize the multiple first optimization instructions respectively to obtain multiple second optimization instructions, and the multiple second optimization codes generated by the multiple second optimization instructions are respectively tested through their corresponding test cases to obtain the second code passing rate; Until the code passing rate of the optimized instructions corresponding to the multiple generation failure instructions is greater than or equal to the preset passing rate threshold, or the number of times of optimizing the multiple generation failure instructions reaches the preset optimization number threshold, the instruction optimization data set is obtained.

8. The method for optimizing instructions according to claim 7, characterized in that, The preset instruction correction model respectively optimizes the multiple generation failure instructions according to the failure information to obtain multiple first optimization instructions, including: Inputting the failure information into the preset instruction correction model for information extraction processing to obtain the error information corresponding to each of the multiple generation failure instructions, where the error information at least includes the error type, the error position, and the failure code; Based on the preset instruction correction model, optimizing information generation processing is performed according to the error information to obtain the instruction optimization information corresponding to each of the multiple generation failure instructions, where the instruction optimization information at least includes the modification actions corresponding to each of the multiple generation failure instructions; The multiple generation failure instructions are modified according to their corresponding modification actions to obtain the multiple first optimization instructions, where the modification action is an instruction optimization method generated based on the error type, the error position, and the failure code.

9. The method for optimizing instructions according to claim 7, characterized in that The step of respectively testing the multiple first optimization codes through their corresponding test cases to obtain the first code passing rate includes: The multiple first optimization codes are respectively tested through their corresponding test cases to obtain the first test result; Determining the first passing codes among the multiple first optimization codes according to the first test result, where the first passing codes are the first optimization codes that meet the preset running conditions; Obtaining the first quantity of the first optimization codes and the second quantity of the first passing codes, and performing division processing according to the second quantity and the first quantity to obtain the first code passing rate.

10. The method for optimizing instructions according to claim 7, wherein The preset instruction correction model respectively optimizes the multiple first optimization instructions to obtain multiple second optimization instructions, including: Obtaining the first test failure information, where the first test failure information at least includes the test information of the first optimization codes that do not meet the preset running conditions; Based on the first test failure information, marking the first optimization instructions corresponding to the first optimization codes that do not meet the preset running conditions as optimization failure instructions; The preset instruction correction model optimizes the optimization failure instructions according to the first test failure information to obtain the multiple second optimization instructions.

11. The method for optimizing instructions according to claim 7, wherein The code passing rate of the optimized instructions corresponding to each of the multiple generation failure instructions is greater than or equal to the preset passing rate threshold, or the number of times of optimizing the multiple generation failure instructions reaches the preset optimization times threshold, and obtaining the instruction optimization data set includes: When the code passing rate of the optimized instructions corresponding to each of the multiple generation failure instructions is greater than or equal to the preset passing rate threshold, according to the multiple generation failure instructions, the optimized instructions corresponding to each of the multiple generation failure instructions, and the optimization processes corresponding to each of the multiple generation failure instructions, perform data set construction processing through a preset data format to obtain the instruction optimization data set, where the optimized instructions are all optimized successful instructions, and the code generated by the optimized successful instructions meets the preset running conditions; When the code passing rate of the optimized instructions corresponding to each of the multiple generation failure instructions is less than the preset passing rate threshold, continue to perform instruction optimization processing on the multiple generation failure instructions, and determine the number of times of optimizing the multiple generation failure instructions; When the number of times of optimizing the multiple generation failure instructions reaches the preset optimization times threshold, according to the multiple generation failure instructions, the first instructions corresponding to each of the multiple generation failure instructions, and the optimization process data corresponding to each of the multiple generation failure instructions, perform data set construction processing through a preset data format to obtain the instruction optimization data set, where the first instructions include optimization failure instructions and the optimization successful instructions, and the code generated by the optimization failure instructions does not meet the preset running conditions.

12. The method for optimizing instructions according to claim 4, characterized in that, The training of the preset instruction optimization model according to the instruction optimization data set to obtain the trained instruction optimization model includes: According to the instruction optimization data set and the preset model optimization strategy, perform model training processing on the preset instruction optimization model to obtain the trained instruction optimization model, where the preset model optimization strategy at least includes a preset learning rate adjustment strategy, a preset batch size, a preset optimizer, a preset number of iterations, a preset loss function, and a preset weight allocation strategy.

13. The method for optimizing instructions according to claim 12, characterized in that, The adjustment of the model parameters of the preset instruction optimization model according to the instruction optimization data set and the preset model optimization strategy to obtain the trained instruction optimization model includes: Perform model parameter adjustment processing on the preset instruction optimization model through the instruction optimization data set to obtain the first instruction optimization model, and perform model test processing on the first instruction optimization model according to the first test data set to obtain the first model test result; Perform model parameter adjustment processing on the first instruction optimization model according to the first model test result to obtain the second instruction optimization model, and perform model test processing on the second instruction optimization model according to the first test data set to obtain the second model test result; When the first model test result and the second model test result meet the preset stop condition, determine the second instruction optimization model as the trained instruction optimization model; In the case that the first model test result and the second model test result do not meet the preset stop condition, perform model parameter adjustment processing on the second instruction optimization model according to the second model test result until the number of times of model parameter adjustment reaches the preset iteration number, and obtain the trained instruction optimization model.

14. The method for optimizing instructions according to claim 13, wherein The performing model test processing on the first instruction optimization model according to the first test data set to obtain the first model test result includes: Perform data extraction processing from the first test data set through a preset few-shot prompting strategy to obtain a first data set, and divide the other data sets into a second data set and a third data set, where the other data sets are the data sets in the first test data set except the first data set; Input the third data set into the first instruction optimization model for instruction optimization processing to obtain an optimized third data set; Input the first data set, the second data set, and the optimized third data set into the preset code generation model for code generation processing respectively, and perform code testing through the test cases to obtain the first test pass rate corresponding to the first data set, the second test pass rate corresponding to the second data set, and the third test pass rate corresponding to the optimized third data set; If the third test pass rate is greater than the first test pass rate and the second test pass rate, determine that the first model test result is a positive result. If the third test pass rate is not greater than the first test pass rate and / or the second test pass rate, determine that the first model test result is a non-positive result.

15. The method for instruction optimization according to claim 14, characterized in that, The performing model parameter adjustment processing on the first instruction optimization model according to the first model test result to obtain the second instruction optimization model includes: Determine multiple optimized abnormal data in the optimized third data set according to the first model test result, where the code generated by the optimized abnormal data does not meet the preset running condition; Based on the preset weight allocation strategy, perform weight allocation processing on the multiple optimized abnormal data in the preset loss function to obtain an updated loss function; In the case that it is determined that the first model test result is a positive result, perform model parameter adjustment processing on the first instruction optimization model according to the updated loss function and the preset model optimization strategy to obtain the second instruction optimization model; In the case that it is determined that the first model test result is a non-positive result, perform strategy update processing on the preset model optimization strategy in response to the received update information to obtain an updated preset model optimization strategy, and perform model parameter adjustment processing on the first instruction optimization model according to the updated loss function and the updated preset model optimization strategy to obtain the second instruction optimization model.

16. The method for optimizing instructions according to claim 1, wherein The performing instruction optimization processing on the instruction to be optimized through the trained instruction optimization model to obtain the target instruction includes: Deploy the trained instruction optimization model to a preset instruction optimization tool, where the preset instruction optimization tool at least includes an interface tool and a visualization tool; Receiving the instruction to be optimized based on the interface tool, and in response to the triggered instruction optimization signal, performing instruction optimization processing on the instruction to be optimized through the trained instruction optimization model to obtain a target instruction; Performing visualization processing on the instruction to be optimized and the target instruction through the visualization tool.

17. An apparatus for optimizing instructions, characterized in that, Including: A generation unit, configured to input the obtained first training data set into a preset code generation model for code generation processing to obtain a generation failure data set in the first training data set, where the generation failure data set includes a plurality of generation failure instructions and failure information corresponding to each of the plurality of generation failure instructions; A first optimization unit, configured to perform instruction optimization processing on the plurality of generation failure instructions respectively according to the failure information through a preset instruction correction model to obtain an instruction optimization data set, where the instruction optimization data set at least includes the plurality of generation failure instructions, optimized instructions corresponding to each of the plurality of generation failure instructions, and optimization process data, and the preset instruction correction model is a model constructed based on a Markov decision process; A training unit, configured to perform model training processing on a preset instruction optimization model according to the instruction optimization data set to obtain a trained instruction optimization model; A second optimization unit, configured to perform instruction optimization processing on an instruction to be optimized through the trained instruction optimization model to obtain a target instruction.

18. An electronic device, characterized in that, Including: A memory, configured to store a computer program; A processor, configured to implement the steps of the instruction optimization method according to any one of claims 1 to 16 when executing the computer program.

19. A computer-readable storage medium, characterized in that, A computer program is stored in the computer-readable storage medium, where the computer program implements the steps of the instruction optimization method according to any one of claims 1 to 16 when executed by a processor.

20. A computer program product comprising a computer program, characterized in that, The computer program implements the steps of the instruction optimization method according to any one of claims 1 to 16 when executed by a processor.

Citation Information

Patent Citations

  • Method for automatically generating instruction data set based on LLM

    CN117667202A

  • Code generation optimization method and device for large language model, equipment and medium

    CN117724695A

  • Automatic testing method and system, electronic equipment and readable storage medium

    CN118467402A

  • Intelligent action instruction generation method

    CN119204223A

  • Integrated circuit design method and device based on large proxy iteration training model

    CN119312758A