A method and electronic device for generating collaborative training data for optimization problems

By constructing multi-type, hierarchical controllable problem data and a shared encoder collaborative training mechanism, the problem of insufficient adaptability of code generation models to abnormal inputs is solved, and the stability and robustness of the model under complex input conditions are improved.

CN121682286BActive Publication Date: 2026-05-26MOLAR INTELLIGENCE INFORMATION TECHNOLOGY (HANGZHOU) CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
MOLAR INTELLIGENCE INFORMATION TECHNOLOGY (HANGZHOU) CO LTD
Filing Date
2026-02-12
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

Existing code generation models suffer from insufficient adaptability to abnormal inputs, ambiguous descriptions, or erroneous code contexts due to a lack of targeted training data. This affects their stability and robustness under complex input conditions.

Method used

By constructing controllable problem data of multiple types and levels, and adopting a shared encoder and multi-capability collaborative training mechanism, normal data and problem data are collaboratively processed in a unified feature space to generate high-quality training data. This includes filtering, injecting problem data, calculating gradient information and perturbation amplitude, designing a shared encoder for feature processing and separation, and finally judging the generation of training data through evaluation metrics.

Benefits of technology

It significantly improves the generalization ability and robustness of the code generation model under complex input conditions, and can effectively identify and enhance the ability to handle abnormal features.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121682286B_ABST
    Figure CN121682286B_ABST
Patent Text Reader

Abstract

This application discloses a collaborative training data generation method and electronic device for tuning problems, comprising the following steps: filtering the input code description text to obtain input data; injecting problem data into the input data to generate first adversarial sample data containing the problem data; calculating its gradient information and perturbation magnitude, and obtaining second adversarial sample data through tuning; designing a shared encoder based on the second adversarial sample data to obtain the features of the problem data and normal code data; separating the two in the feature space; prompting the shared encoder to learn based on the separated features through feature comparison, and finally obtaining the model generated from the code training data; designing an evaluation index to judge whether the model's generation results are correct and stable in the problem data injection scenario, thereby completing the model training for the code training data generation. This method improves the generalization and robustness of large language models when dealing with practical problems.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of large model code data optimization, and in particular to a collaborative training data generation method and electronic device for optimization problems. Background Technology

[0002] With the widespread application of large language models in code generation and automated programming systems, they have been used in practical engineering scenarios such as code completion, function generation, defect repair, and programming assistance. Supported by standardized, high-quality training data, these systems can effectively complete predetermined programming tasks. However, in real-world applications, the input data received by code generation models is often not ideal, but rather contains various non-standardized perturbations.

[0003] In practical use, user-input code descriptions may contain incomplete syntax, ambiguous semantics, or logical inconsistencies; erroneous code snippets, redundant comments, or formatting noise may be mixed into the historical code context; and data annotation biases introduced during training or transfer may also cause deviations in the model's understanding of code semantics. These abnormal inputs can easily cause the code generation model to output erroneous code, uncompileable code, or logically flawed code, thereby affecting the stability and reliability of the automatic programming system.

[0004] To address the aforementioned issues, existing robustness enhancement schemes often employ rule-based perturbation methods, such as synonym replacement, random deletion, or text truncation, to generate interference samples. These methods generate data perturbations in a limited way, failing to accurately reflect the complex, diverse, and targeted abnormal input features of real-world programming scenarios. This results in limited training enhancement effectiveness and makes it difficult to significantly improve the stable performance of code generation models under complex input conditions. In some cases, excessive or uncontrolled noise data can even interfere with the model's normal learning process, inducing the model to focus on irrelevant features and thus weakening its generalization ability.

[0005] Therefore, there is an urgent need for a data generation method for the actual use of code generation models. This method should be able to proactively construct multi-type, hierarchical, and controllable problem data while ensuring the semantic consistency and parsability of the code. It should realistically simulate the abnormal input situations that the automatic programming system may encounter during actual operation and collaboratively process normal data and problem data in a unified feature space, thereby effectively improving the robustness and stability of the code generation model under complex input conditions. Summary of the Invention

[0006] The purpose of this invention is to provide a collaborative training data generation method and electronic device for tuning problems, so as to solve the problems that existing code generation models lack targeted training data and have insufficient adaptability to abnormal inputs when facing abnormal inputs, ambiguous descriptions or erroneous code contexts.

[0007] According to a first aspect of the embodiments of this application, a method for generating collaborative training data for tuning problems is provided, comprising:

[0008] S1: In the data input stage of the code generation model, the input code description text is filtered to obtain the input data;

[0009] S2: In response to abnormal programming scenarios that occur in the code generation model, problematic data is actively injected into the input data to generate first adversarial sample data containing problematic data;

[0010] S3: Calculate the gradient information and perturbation amplitude of the first adversarial sample data, and obtain the second adversarial sample data through optimization;

[0011] S4: Based on the second adversarial sample data, design a novel shared encoder. Use the shared encoder to perform multiple feature processing on the problem data to obtain the features of the problem data and normal code data.

[0012] S5: Separate the features of the problem data and normal code data in the feature space to obtain the separated task features and shared features;

[0013] S6: Based on the separated task features and shared features, feature comparison is used to prompt the shared encoder to learn and obtain the model generated from the code training data;

[0014] S7: Based on the model generated from the code training data, design an evaluation index for the correctness and stability of the model's generated results in the scenario of problem data injection. Determine whether the training data generation for the model generated from the code training data has been completed. If it meets the requirements, obtain the final training data. If it does not meet the requirements, re-execute S3-S7.

[0015] According to a second aspect of the embodiments of this application, an electronic device is provided, comprising:

[0016] One or more processors;

[0017] Memory, used to store one or more programs;

[0018] When the one or more programs are executed by the one or more processors, the one or more processors perform the method as described in the first aspect.

[0019] According to a third aspect of the embodiments of this application, a computer-readable storage medium is provided that stores computer instructions thereon, which, when executed by a processor, implement the steps of the method as described in the first aspect.

[0020] Compared with the prior art, the embodiments of the present invention have at least the following beneficial effects:

[0021] By constructing multi-type, hierarchical controllable problem data, the abnormal input scenarios that may occur in the actual use of the code generation model are realistically simulated. A shared encoder and multi-capability collaborative training mechanism are adopted to collaboratively process normal data and problem data in a unified feature space, so as to effectively identify and enhance abnormal features. After iterative training and screening, high-quality problem data that can be directly used for model training are generated, thereby significantly improving the generalization ability and robustness of the code generation model under complex input conditions. Attached Figure Description

[0022] Figure 1 This is a flowchart illustrating a collaborative training data generation method for tuning problems according to an exemplary embodiment.

[0023] Figure 2 This is a schematic diagram illustrating the operation of a shared encoder according to an exemplary embodiment.

[0024] Figure 3 This is a block diagram illustrating an electronic device according to an exemplary embodiment. Detailed Implementation

[0025] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application.

[0026] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used herein are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.

[0027] It should be understood that although the terms first, second, third, etc., may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."

[0028] Figure 1 This is a flowchart illustrating a collaborative training data generation method for tuning problems, according to an exemplary embodiment. (Reference) Figure 1 This invention provides a method for generating collaborative training data for tuning problems, used to generate training data for data processing code models, such as descriptive text in Python, C++, and C#, which may include:

[0029] S1: In the data input stage of the code generation model, the input code description text is filtered to obtain the input data; this step includes the following sub-steps:

[0030] S11: Filter out illegal or sensitive content from the input code description text based on rule matching or pre-trained model detection;

[0031] Specifically, the input text is detected using a predefined set of rules or a pre-trained model (such as BERT or GPT). The rules can include matching specific keywords, malicious code, content that violates privacy requirements, etc., and identifying illegal or sensitive text through regular expressions, keyword filtering, sentiment analysis, etc., and then removing or replacing it.

[0032] S12: The filtered code description text is deduplicated using hash matching and semantic similarity calculation;

[0033] Specifically, the text is first hashed to calculate its hash value, and hash matching algorithms (such as MD5 and SHA) are used to detect duplicate text content. If the hash value is duplicated, it means that the text already exists. Second, similar texts are matched based on semantic similarity calculation methods (such as cosine similarity and BERT similarity), and content that is semantically duplicated with existing text is deleted to ensure the diversity and validity of the data.

[0034] S13: After deduplication, the text encoding format is unified, and data that does not meet the preset conditions is removed based on multi-dimensional quality verification rules to obtain the input data;

[0035] Specifically, the input text is uniformly encoded in UTF-8 and undergoes text cleaning, such as removing irrelevant symbols, spaces, and line breaks. Next, the text is validated according to preset quality control rules (such as text length, content completeness, and grammatical correctness), eliminating data that does not meet the criteria to ensure that the quality of the input data meets the model training requirements.

[0036] S2: To address abnormal programming scenarios that occur in the code generation model, problematic data is proactively injected into the input data, thereby generating first adversarial sample data containing the problematic data; this step includes the following sub-steps:

[0037] S21: Determine that the scenario in which the generated code cannot run and the user reports an error is an abnormal programming scenario, and process the input data in this scenario;

[0038] Specifically, the system first runs the input code description in a simulated programming environment to detect any abnormal situations such as code execution failures or user error reports. If errors are found during the simulation, the error information is recorded and marked as an abnormal programming scenario. Furthermore, by combining user error feedback data, common problems encountered by users in actual use are identified and these issues are considered abnormal programming scenarios.

[0039] S22: Based on the code generation model, inject sensitive information into the input data to determine the input position that has the greatest impact on the output of the code generation model;

[0040] Specifically, based on the model's training data, potential sensitive information in the input text is identified and injected into the input data. By simulating different types of sensitive information (such as sensitive variable names, specific function calls, etc.), the impact on the code generation model's output is evaluated. Through gradient analysis or model interpretability tools, the input locations of sensitive information are identified, and the input locations with the greatest impact on the model's output are recorded.

[0041] S23: While maintaining the overall structure of the original text, the input position is subjected to controlled perturbation to generate first adversarial sample data containing the problem data;

[0042] Specifically, controlled perturbations are applied to the input positions that have the greatest impact on the model output, as determined in S22. These perturbations can be implemented by changing variable names, modifying parameter values, or replacing function calls, without altering the grammatical structure and logical relationships of the original text.

[0043] These perturbations generate first adversarial examples containing problematic data, ensuring that the problematic data does not break the basic structure of the original code, but is sufficient to cause the model to output errors or unreasonable results, thereby promoting the robustness of the model in the face of abnormal programming scenarios.

[0044] Assuming the input location with the greatest impact on the model output has been determined, p In the original text middle p Location given perturbation At this point, the first adversarial sample data is generated. x It can then be expressed as:

[0045]

[0046] S3: Calculate the gradient information and perturbation magnitude of the first adversarial sample data, and obtain the second adversarial sample data through optimization; this step includes the following sub-steps:

[0047] S31: Evaluate the degree of influence of the input feature changes of the first adversarial sample on the output result during the model inference process, and calculate the corresponding gradient information and perturbation amplitude accordingly.

[0048] Specifically, gradient calculation is performed on the input first adversarial sample data:

[0049] Given the first adversarial sample data Input it into the code generation model to obtain the predicted output code. ,in This is represented as the output of the model.

[0050] Now calculate the gradient of the input text:

[0051]

[0052] in This represents the loss function, used to measure the model output. With real labels The gap between them. This represents the model gradient, reflecting the contribution of each input text to the loss function.

[0053] The text perturbation is calculated using the gradient sign method to obtain the perturbation amplitude during the adversarial example generation process. :

[0054]

[0055] in This indicates the perturbation step size, which can be used to control the intensity of the perturbation. This indicates the direction of perturbation for each text, ensuring that the perturbation of the injected problematic data does not affect the overall structure of the original text.

[0056] S32: Based on the gradient information and perturbation amplitude, perform perturbation calculation on the input code description text data, and generate second adversarial sample data to enhance the robustness of the model while maintaining the semantic consistency and structural integrity of the original text.

[0057] Specifically, for injected problematic data, the impact of the replaced text on the model is calculated, and the word replacement with the greatest impact on the model is selected, or the text with similar semantics but which can effectively change the model output is selected.

[0058] The perturbation step size is finely adjusted through multiple iterations of optimization. This makes the text increasingly more effective at misleading the model, as expressed by the formula:

[0059]

[0060] in t Represented as iteration rounds, This indicates the current state. t The first adversarial sample data of the iteration round.

[0061] By calculating and optimizing the gradient information and perturbation magnitude of the input code description text data, in this case, after 10 iterations, the optimization condition is met, and the final output is the second adversarial sample data represented as follows: .

[0062] S33: Determine whether the second adversarial sample data is close to the original input code description text. If the difference percentage is greater than a set threshold, then regenerate the first adversarial sample data containing the problem data in reverse according to the difference percentage.

[0063] Specifically, it is determined whether the second adversarial sample data is close to the original input code description text. If the difference percentage is greater than a set threshold (in this case, the threshold is set to 20%), then based on the difference percentage, the first adversarial sample data containing the problematic data is regenerated in reverse. Through multiple iterations of optimization, the perturbation step size is finely adjusted by readjusting the data. This makes the text increasingly more effective at misleading the model.

[0064] S34: During the regeneration process based on the first adversarial sample data, the perturbation intensity is gradually adjusted through multiple rounds of iteration, so that the problem data gradually approaches the input code description text while maintaining semantic consistency. Finally, it is determined that the percentage difference is less than the set threshold, and usable adversarial second sample data is output.

[0065] Specifically, it is determined whether the second adversarial sample data is close to the original input code description text. If the difference percentage is less than a set threshold, in this case the threshold is set to 20%, and usable second adversarial sample data can be output.

[0066] S4: Based on the second adversarial sample data, design a novel shared encoder. Use the shared encoder to perform multiple feature processing on the problem data to obtain the features of the problem data and normal code data. Figure 2 This is a schematic diagram of a shared encoder operation according to an exemplary embodiment, with reference to... Figure 2 The present invention provides a collaborative training data sharing encoder for tuning problems, used for feature processing of second adversarial example data, including all steps S41-S42:

[0067] S41: Construct a shared encoder consisting of a Transformer network and a multilayer perceptron structure, wherein the Transformer network is used to model the contextual features of the input text, and the multilayer perceptron structure is used to map and compress high-dimensional semantic features.

[0068] During training for each task, the shared encoder optimizes a specific loss function and eliminates unwanted interference between independent features and shared features in the input data through adversarial training. After adding perturbations, adversarial learning is used to separate the shared representation space from the task-specific representation space.

[0069] S42: Set a shared feature extraction layer and task-independent representation constraints in the shared encoder. Input the problem data and normal code data into the shared encoder for feature processing to obtain the features of the problem data and normal code data.

[0070] Specifically, given input description codes, the second adversarial sample data generates text. The code generation model is described as follows: , m This indicates different code language types. (Shared encoder) Input Mapped to shared space .

[0071]

[0072] Through a specific encoder Decoding reveals the characteristics of problematic and normal code data. :

[0073]

[0074] S5: Separate the features of the problem data and normal code data in the feature space to obtain the separated task features and shared features; this step includes the following sub-steps:

[0075] S51: Input the problem data and normal code data features into the feature space, and output the corresponding task result based on the task decoder;

[0076] Specifically, the characteristics of the decoded problematic data and normal code data will be compared. Input feature space;

[0077] The adversarial discriminator is used in the pre-feature splitting layer and connected to the shared encoder. It can be a lightweight fully connected layer with LeakyReLU activation function. A BatchNorm layer is added for stable training to form the task decoder.

[0078] We use a design that gradually reduces the dimension of fully connected layers to compress the feature dimensions.

[0079] Use a single-output node and a sigmoid activation function to output the discriminant probability. Get the corresponding task results:

[0080]

[0081] To represent the discriminator Characteristics of Problem Data and Normal Code Data The output on It is a discriminator.

[0082] S52: Based on the task results, suppress the task information carried in the shared features by the adversarial discriminator to ensure that the shared feature space contains only cross-task general feature information;

[0083] Specifically, to ensure that independent features of different tasks do not interfere with shared features, labels are calculated. The probability function is used to introduce adversarial loss for discrimination, ensuring that the shared feature space contains only cross-task common feature information:

[0084]

[0085] in Indicated as a way to combat losses, m Representing different code language types, Represented as language type m Time tags optimize the current time discriminator Unable to predict the label This ensures that the shared space does not carry private information related to specific tasks.

[0086] S53: Based on the cross-task general feature information, the model is jointly optimized by combining task loss and adversarial loss to obtain shared features and task features after feature separation of problem data and normal code data.

[0087] Specifically, by combining task loss and adversarial loss during training, the final loss function is obtained as follows:

[0088]

[0089] in Represented as m The ultimate loss of type code language types, This represents the standard task loss function. The weight hyperparameters representing the adversarial loss control the balance between task and adversarial loss, helping the model converge quickly and achieving effective separation between the shared representation space and the task-specific representation space.

[0090] Finally, determine if the function converges. If it does not converge, return to S3 to reset the perturbation step size and perform feature separation. After optimizing the feature analysis using an adversarial discriminator, recalculate the loss. Finally, compare the features of the problematic data with those of the normal code data. Separate the problematic data and the normal code data to obtain their respective task characteristics. With shared features This can be used for subsequent training.

[0091] S6: Based on the separated task features and shared features, feature comparison is used to prompt the shared encoder to learn, resulting in a model generated from the code training data; this step includes the following sub-steps:

[0092] S61: Set up task sub-modules for different task types, and each task sub-module shares the shared encoder. The task sub-modules represent different task type modules.

[0093] Specifically, a multi-task learning framework is adopted to collaboratively optimize each sub-task module. Each task, such as syntax analysis, common sense reasoning, and anomaly detection, has a sub-model, but all sub-models share a common encoder.

[0094] S62: Based on the task sub-modules, during the training process, based on the different feature information of problem data features and normal code, different task sub-modules are processed to obtain label results;

[0095] Specifically, based on the task characteristics of the separated problem data and normal code data. With shared features The label results under the task type are obtained by performing task processing through the decoder. :

[0096]

[0097] S63: By training with the combined loss of each task, the code generation model can automatically activate the task sub-module that best matches the current input with the task features and shared features. The value performance of the task features and shared features is obtained by performing a preliminary evaluation through the probability distribution under the label results.

[0098] Specifically, this is achieved by designing a loss function for each independent task:

[0099]

[0100] in, Indicated in the second adversarial sample data Its label is Independent task loss at that time.

[0101] The value of the loss function is used to represent the value of task features and shared features.

[0102] S64: Based on the value performance, dynamically adjust the weights to adjust the training difficulty of the task, and obtain the model generated from the final code training data;

[0103] Specifically, further collaborative optimization is performed, and the total loss function is expressed as a weighted sum of the losses of each task. :

[0104]

[0105] Where T represents the total number of tasks. This indicates the weight of each task.

[0106] The final model can be automatically activated based on the features of the input data to obtain the model generated from the final code training data.

[0107] S7: Based on the model generated from the code training data, design evaluation metrics for the correctness and stability of the model's generated results in problematic data injection scenarios. Determine whether the training data generation for the model using the code training data has been completed. If it meets the requirements, obtain the final training data; otherwise, re-execute S3-S7. This step includes the following sub-steps:

[0108] S71: Evaluate the consistency of the output of the model generated from the code training data under similar problem data inputs, and obtain the evaluation results to measure the stability of the model generated from the code training data;

[0109] Specifically, the weights are dynamically adjusted based on the model's performance on normal data, adversarial data, and bug data. This allows for adjusting the training difficulty of tasks, enhancing the model's generalization ability on specific data. It also measures the overall stability of the data, ensuring data consistency or stable output even with similar perturbations. A stability evaluation formula is defined as follows:

[0110] For two similar inputs and Consistency of computational model output S :

[0111]

[0112] For the input text The code generation model at that time is described as follows The input text is The code generation model at that time is described as follows .

[0113] By repeatedly injecting the same type of bugs or adversarial perturbations, the model's output changes in each test, thus measuring the model's consistency under similar inputs.

[0114] S72: Based on the evaluation results, design evaluation indicators;

[0115] Specifically, the evaluation metric is set at 90%. If the consistency rate is greater than the metric, it means the model has passed training and can be directly used as data for training large language models to achieve better results. If it fails, the process returns to S64, where the weights are dynamically adjusted. This allows for adjustments to the training difficulty of tasks, enhancing the model's generalization ability on specific data.

[0116] S73: Based on the evaluation metrics, perform statistical analysis on the output changes of multiple tests with the same type of problem data, and determine whether the training data generation for the model used for code training data generation has been completed. If the result is not met, S3-S7 are executed again. If the result is met, complete the data generation by selecting high-quality problem data for training.

[0117] Accordingly, this application also provides an electronic device, comprising: one or more processors; a memory for storing one or more programs; and, when the one or more programs are executed by the one or more processors, causing the one or more processors to implement a collaborative training data generation method for tuning problems as described above. Figure 3 The diagram shown is a hardware structure diagram of any device with data processing capabilities, used in an embodiment of the present invention to provide a collaborative training data generation method for tuning problems. (Except for...) Figure 3 In addition to the processor and memory shown, any data processing device in the embodiment may also include other hardware depending on the actual function of the data processing device, which will not be described in detail here.

[0118] Accordingly, this application also provides a computer-readable storage medium storing computer instructions that, when executed by a processor, implement the aforementioned method for generating collaborative training data for tuning problems. The computer-readable storage medium can be an internal storage unit of any data-processing device as described in any of the foregoing embodiments, such as a hard disk or memory. The computer-readable storage medium can also be an external storage device of a wind turbine, such as a plug-in hard disk, smart media card (SMC), SD card, flash card, etc., mounted on the device. Furthermore, the computer-readable storage medium can include both internal storage units of any data-processing device and external storage devices. The computer-readable storage medium is used to store the computer program and other programs and data required by the data-processing device, and can also be used to temporarily store data that has been output or will be output.

[0119] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the disclosure herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and embodiments are to be considered exemplary only.

[0120] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope.

Claims

1. A co-training data generation method for tuning a problem, characterized in that, include: S1: In the data input stage of the code generation model, the input code description text is filtered to obtain the input data; S2: In response to abnormal programming scenarios that occur in the code generation model, problematic data is actively injected into the input data to generate first adversarial sample data containing problematic data; S3: Calculate the gradient information and perturbation amplitude of the first adversarial sample data, and obtain the second adversarial sample data through optimization; S4: Based on the second adversarial sample data, design a novel shared encoder. Use the shared encoder to perform multiple feature processing on the problem data to obtain the features of the problem data and normal code data. In the shared encoder, a shared feature extraction layer and task-independent representation constraints are set. The problem data and normal code data are input into the shared encoder for feature processing to obtain the features of the problem data and normal code data. S5: Separate the features of the problem data and normal code data in the feature space to obtain the separated task features and shared features; Specifically, this includes: inputting the problem data and normal code data features into the feature space, and outputting the corresponding task results based on the task decoder; based on the task results, suppressing the task information carried in the shared features through an adversarial discriminator to ensure that the shared feature space only contains cross-task general feature information; based on the cross-task general feature information, jointly optimizing the model by combining task loss and adversarial loss to obtain the shared features and task features after the problem data and normal code data features are separated. S6: Based on the separated task features and shared features, feature comparison is used to prompt the shared encoder to learn and obtain the model generated from the code training data; S7: Based on the model generated from the code training data, design evaluation metrics for the correctness and stability of the model's output under problem data injection scenarios. Determine whether the training data generation for the model generated from the code training data is complete. If it meets the requirements, obtain the final training data; otherwise, re-execute S3-S7. Specifically, this includes: S71: Evaluate the consistency of the output of the model generated from the code training data under similar problem data inputs, and obtain evaluation results to measure the stability of the model generated from the code training data; S72: Based on the evaluation results, design evaluation metrics; S73: According to the evaluation metrics, perform statistical analysis on the output changes of multiple tests with the same type of problem data injection, and determine whether the training data generation for the model generated from the code training data is complete. If it does not meet the requirements, re-execute S3-S7; if it does meet the requirements, complete the data generation by selecting high-quality problem data for training.

2. The method according to claim 1, characterized in that, The input code description text is filtered to obtain the input data, including: Filter out illegal or sensitive content from the input code description text based on rule matching or pre-trained model detection; The filtered code description text is deduplicated using hash matching and semantic similarity calculation; After deduplication, the text encoding format is unified, and data that does not meet the preset conditions is removed based on multi-dimensional quality verification rules to obtain the input data.

3. The method according to claim 1, characterized in that, To address anomalous programming scenarios in the code generation model, problematic data is proactively injected into the input data, thereby generating first adversarial sample data containing this problematic data, including: The scenario where the generated code cannot run and the user reports an error is identified as an abnormal programming scenario. In this scenario, the input data is processed. Based on the code generation model, sensitive information is injected into the input data to determine the input location that has the greatest impact on the output of the code generation model. While maintaining the overall structure of the original text, the input position is subjected to controlled perturbation to generate first adversarial sample data containing the problem data.

4. The method according to claim 1, characterized in that, Calculate the gradient information and perturbation magnitude of the first adversarial sample data, and obtain the second adversarial sample data through optimization, including: The influence of the input feature changes of the first adversarial example on the output result during the model inference process is evaluated, and the corresponding gradient information and perturbation amplitude are calculated accordingly. Based on the gradient information and perturbation magnitude, perturbation calculation is performed on the input code description text data to generate second adversarial sample data to enhance the robustness of the model while maintaining the semantic consistency and structural integrity of the original text. Determine whether the second adversarial sample data is close to the original input code description text. If the difference percentage is greater than a set threshold, then regenerate the first adversarial sample data containing the problem data based on the difference percentage. During the regeneration process based on the first adversarial sample data, the perturbation intensity is gradually adjusted through multiple rounds of iteration, so that the problem data gradually approaches the input code description text while maintaining semantic consistency. Finally, if the percentage difference is less than a set threshold, usable adversarial second sample data is output.

5. The method according to claim 1, characterized in that, A novel shared encoder is designed based on the second adversarial sample data. This shared encoder performs multiple feature processing steps on the problematic data to obtain features of both the problematic and normal code data, including: A shared encoder consisting of a Transformer network and a multilayer perceptron structure is constructed, wherein the Transformer network is used to model the contextual features of the input text, and the multilayer perceptron structure is used to map and compress high-dimensional semantic features; In the shared encoder, a shared feature extraction layer and task-independent representation constraints are set. The problem data and normal code data are input into the shared encoder for feature processing to obtain the features of the problem data and normal code data.

6. The method according to claim 1, characterized in that, Based on the separated task features and shared features, feature comparison is used to prompt the shared encoder to learn, resulting in a model generated from the code training data, including: Different task sub-modules are set up for different task types, and each task sub-module shares the shared encoder. The task sub-modules represent different task type modules. Based on the task sub-modules, during the training process, different task sub-modules are processed to obtain label results based on the different feature information of problem data features and normal code features; By training with the combined losses of each task, the code generation model can automatically activate the task sub-module that best matches the current input based on the task features and shared features. The value performance of the task features and shared features is obtained through the probability distribution under the label results. Based on the value performance, the weights are dynamically adjusted to adjust the difficulty of task training, resulting in the model generated from the final code training data.

7. An electronic device, characterized in that, include: One or more processors; Memory, used to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-6.

8. A computer-readable storage medium storing computer instructions thereon, characterized in that, When executed by the processor, this instruction implements the steps of the method as described in any one of claims 1-6.