Code generation method and device, model training method and device, equipment and medium

By training a code generation model, using a base prediction head and an additional prediction head to predict syntactically complete tokens in each iteration, and ignoring syntactically incomplete tokens during training, the problem of poor syntactic integrity in LLM-generated code is solved, achieving higher-quality code generation.

CN123177784APending Publication Date: 2026-11-27NATIONAL CENTER OF TECHNOLOGY INNOVATION FOR EDA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510687913.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-26
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing Large Language Models (LLMs) have poor syntactic integrity when generating code, resulting in low-quality generated code.

Method used

By training a code generation model, using a base prediction head and an additional prediction head to predict grammatically complete tokens in each iteration, and ignoring grammatically incomplete tokens during training, the model is optimized using special identifiers and loss functions to improve the grammatical completeness of generated code.

Benefits of technology

It improves the syntactic integrity and quality of the generated code, and enhances the efficiency and accuracy of the code generation model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123177784A_ABST
    Figure CN123177784A_ABST
Patent Text Reader

Abstract

The application provides a code generation method and device, a model training method and device, equipment and a medium. The code generation requirement of a user is obtained. Based on the code generation requirement, a code generation model is used to generate a code corresponding to the code generation requirement. The code is obtained by using N predicted token sequences generated by an N iteration process. In the i-th iteration process, a plurality of tokens are predicted based on input information, and a predicted token sequence is constructed based on tokens with complete syntax in the plurality of tokens. When i is equal to 1, the input information is the code generation requirement, and when i is greater than 1, the input information includes the code generation requirement and the predicted token sequence of the previous i-1 rounds. In this way, the grammatical integrity of the code generated by the model can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of model technology, and in particular to a code generation method, a model training method, an apparatus, a device, and a medium. Background Technology

[0002] Large Language Model (LLM) can quickly generate corresponding code based on user needs, helping developers save time and effort in writing code and providing convenience for developers.

[0003] Currently, methods for generating code using LLM can include: inputting a user's request to generate code into the LLM; the LLM then combines the input request with its learned knowledge to perform contextual understanding of the request; and generating code incrementally, one lexical at a time, until a complete code snippet is generated or a specific termination condition is met.

[0004] However, the LLM method described above has a weak ability to capture syntax. Therefore, when using LLM to generate code, there may be issues with the poor syntactic integrity of the generated code. Summary of the Invention

[0005] This application provides a code generation method, model training method, apparatus, device, and medium to solve the problem of poor syntactic integrity in code generated by a model.

[0006] Firstly, this application provides a code generation method, the method comprising:

[0007] Obtain the user's code generation requirements;

[0008] Based on the code generation requirement, a code generation model is used to generate the code corresponding to the code generation requirement; wherein, the code is obtained by generating N predicted tag sequences using N iterations; wherein, in the i-th iteration, multiple tags are predicted based on input information, and a predicted tag sequence is constructed based on the grammatically complete tags among the multiple tags; when i equals 1, the input information is the code generation requirement, and when i is greater than 1, the input information includes the code generation requirement and the predicted tag sequence of the previous i-1 rounds.

[0009] In one possible implementation, the code generation model includes a base prediction head and at least one additional prediction head;

[0010] In the i-th iteration, multiple labels are predicted based on the input information, including:

[0011] During the i-th iteration, the marker at position t+1 is predicted using the basic prediction head, and the j-th additional prediction head is used to predict the marker at position t+j+1; where t is an integer greater than or equal to 0, and t is the last position predicted during the (i-1)-th iteration.

[0012] In one possible implementation, during the i-th iteration, predicting multiple labels based on input information further includes:

[0013] During the i-th iteration, for the prediction of the tag at the m-th position, when the m-th position is determined to be a syntax boundary, a tag containing a special identifier is generated.

[0014] In one possible implementation, constructing the predicted tag sequence based on grammatically complete tags among the plurality of tags includes:

[0015] The multiple tags are combined to construct multiple candidate tag sequences;

[0016] For any tag in any candidate tag sequence, a pre-defined acceptance strategy is used to detect whether the predicted probability corresponding to the tag is greater than an acceptable threshold. The acceptable threshold is related to pre-defined parameters and an entropy function, which is determined based on information about tags preceding the tag.

[0017] Tags larger than the acceptable threshold are retained to obtain multiple processed candidate tag sequences;

[0018] For any candidate token sequence, construct a target candidate token sequence based on the grammatically complete tokens in the candidate token sequence to obtain multiple target candidate token sequences;

[0019] The longest of multiple target candidate label sequences is determined as the predicted label sequence.

[0020] In one possible implementation, constructing the target candidate tag sequence based on grammatically complete tags in the candidate tag sequence includes:

[0021] Remove the tokens after the last special identifier in the candidate token sequence to obtain the grammatically complete target candidate token sequence.

[0022] Secondly, this application provides a model training method, the method comprising:

[0023] Obtain the code generation requirements set and target code set;

[0024] The model to be trained is trained for M rounds based on the code generation requirement set and the target code set to obtain the code generation model. In the Xth round of training, the model to be trained is trained based on the syntactically complete code in the code generation requirement set and the target code set. M is an integer greater than 0. The code generation model is used to generate corresponding code based on the user's code generation requirements.

[0025] In one possible implementation, obtaining the target code set includes:

[0026] Obtain the initial code set;

[0027] The code in the initial code set is parsed to obtain the abstract syntax tree corresponding to the code;

[0028] Extract the syntax identifiers from the abstract syntax tree, and segment the code based on the syntax identifiers. Add special identifiers before and after the segmentation points to obtain the target code.

[0029] Multiple target codes are combined into a target code set.

[0030] In one possible implementation, the model to be trained includes a base prediction head and at least one additional prediction head. The target code in the target code set is in the form of a combined label. The combined label includes a first label corresponding to the base prediction head and a second label corresponding to the additional prediction head. The second label of the j-th additional prediction head is generated by shifting the first label j positions to the left and filling it with a first identifier. The first label and the second label are codes with the special identifier added.

[0031] In one possible implementation, the step of training the model to be trained for M rounds based on the code generation requirement set and the target code set to obtain the code generation model includes:

[0032] During the Yth round of training, for the markers in the predicted marker sequence that are after the last special marker, the second marker is used to replace them to obtain the target marker sequence, so that the markers after the last special marker are not included in the calculation of the loss function; where the markers after the last special marker are grammatically incomplete markers.

[0033] In one possible implementation, the method further includes:

[0034] During the Yth training round, a loss function is calculated based on the target label sequence and the corresponding combined label, wherein the second identifier in the target label sequence is not included in the calculation of the loss function.

[0035] Thirdly, this application provides a code generation apparatus, comprising:

[0036] The acquisition module is used to acquire the user's code generation requirements;

[0037] A generation module is used to generate code corresponding to the code generation requirement based on the code generation requirement and using a code generation model; wherein the code is obtained by generating N predicted tag sequences using N iterations; wherein, in the i-th iteration, multiple tags are predicted based on input information, and a predicted tag sequence is constructed based on grammatically complete tags among the multiple tags; when i equals 1, the input information is the code generation requirement, and when i is greater than 1, the input information includes the code generation requirement and the predicted tag sequence of the previous i-1 iterations.

[0038] In one possible implementation, the code generation model includes a base prediction head and at least one additional prediction head; the generation module is specifically used to predict the marker at position t+1 using the base prediction head during the i-th iteration, and the j-th additional prediction head is used to predict the marker at position t+j+1; where t is an integer greater than or equal to 0, and t is the last position predicted during the (i-1)-th iteration.

[0039] In one possible implementation, the generation module is specifically used to predict the tag at the m-th position during the i-th iteration, and when the m-th position is determined to be a syntax boundary, to generate a tag containing a special identifier.

[0040] In one possible implementation, the generation module is specifically used to combine the plurality of tags to construct a plurality of candidate tag sequences; for any tag in any candidate tag sequence, a pre-set acceptance strategy is used to detect whether the predicted probability corresponding to the tag is greater than an acceptable threshold, the acceptable threshold being related to pre-set parameters and an entropy function, the entropy function being determined based on information of tags preceding the tag; tags greater than the acceptable threshold are retained to obtain a plurality of processed candidate tag sequences; for any candidate tag sequence, a target candidate tag sequence is constructed based on grammatically complete tags in the candidate tag sequence to obtain a plurality of target candidate tag sequences;

[0041] The longest of multiple target candidate label sequences is determined as the predicted label sequence.

[0042] In one possible implementation, the generation module is specifically used to remove the markers after the last special identifier in the candidate marker sequence to obtain a grammatically complete target candidate marker sequence.

[0043] Fourthly, this application provides a model training apparatus, the apparatus comprising:

[0044] The acquisition module is used to obtain the code generation requirement set and the target code set;

[0045] The training module is used to train the model to be trained for M rounds based on the code generation requirement set and the target code set to obtain the code generation model. In the Xth round of training, the model to be trained is trained based on the syntactically complete code in the code generation requirement set and the target code set. M is an integer greater than 0. The code generation model is used to generate corresponding code based on the user's code generation requirements.

[0046] In one possible implementation, the obtaining module is specifically used to obtain an initial code set; parse the code in the initial code set to obtain an abstract syntax tree corresponding to the code; extract syntax identifiers from the abstract syntax tree, and segment the code based on the syntax identifiers, adding special identifiers before and after the segmentation points to obtain target code; and construct a target code set from multiple target codes.

[0047] In one possible implementation, the model to be trained includes a base prediction head and at least one additional prediction head. The target code in the target code set is in the form of a combined label. The combined label includes a first label corresponding to the base prediction head and a second label corresponding to the additional prediction head. The second label of the j-th additional prediction head is generated by shifting the first label j positions to the left and filling it with a first identifier. The first label and the second label are codes with the special identifier added.

[0048] In one possible implementation, the training module is specifically used during the Yth round of training to replace the markers in the predicted marker sequence that are after the last special identifier with a second identifier to obtain the target marker sequence, so that the markers after the last special identifier do not participate in the calculation of the loss function; wherein, the markers after the last special identifier are grammatically incomplete markers.

[0049] In one possible implementation, the training module is specifically used to calculate a loss function based on the target label sequence and the corresponding combined label during the Yth round of training, wherein the second identifier in the target label sequence does not participate in the calculation of the loss function.

[0050] Fifthly, embodiments of this application provide an electronic device, including: a memory and a processor;

[0051] The memory stores computer-executed instructions;

[0052] The processor executes computer execution instructions stored in the memory, causing the processor to perform the first aspect and / or various possible implementations of the first aspect as described above.

[0053] In a sixth aspect, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the first aspect and / or various possible implementations of the first aspect.

[0054] In a seventh aspect, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the first aspect and / or various possible implementations of the first aspect.

[0055] The code generation method, model training method, apparatus, device, and medium provided in this application obtain the user's code generation requirements; based on these requirements, a code generation model is used to generate code corresponding to the requirements; the code is obtained from N predicted tag sequences generated through N iterations; in the i-th iteration, multiple tags are predicted based on input information, and a predicted tag sequence is constructed based on grammatically complete tags among these tags; when i equals 1, the input information is the code generation requirements; when i is greater than 1, the input information includes the code generation requirements and the predicted tag sequences from the previous i-1 iterations. This improves the grammatical integrity of the code generated by the model. Attached Figure Description

[0056] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0057] Figure 1 This is a schematic diagram illustrating an application scenario of a code generation method provided in an embodiment of this application;

[0058] Figure 2 A schematic flowchart illustrating a model training method provided in an embodiment of this application;

[0059] Figure 3 This application provides a schematic diagram of a code preprocessing process.

[0060] Figure 4 A schematic diagram of an abstract syntax tree for code provided in an embodiment of this application;

[0061] Figure 5 This application provides a schematic flowchart for processing an initial code set.

[0062] Figure 6 A flowchart illustrating a code generation method provided in an embodiment of this application;

[0063] Figure 7This is a schematic diagram illustrating the iterative process of a code generation model provided in an embodiment of this application;

[0064] Figure 8 A schematic diagram illustrating the generation of code using a different code generation method provided in an embodiment of this application;

[0065] Figure 9 This is a schematic diagram of the structure of a code generation device provided in an embodiment of this application;

[0066] Figure 10 This is a schematic diagram of the structure of a model training device provided in an embodiment of this application;

[0067] Figure 11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.

[0068] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation

[0069] 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 as detailed in the appended claims.

[0070] Large language models, trained on extensive data, are capable of generating code based on user needs. They typically generate code that conforms to certain standards and styles.

[0071] In some implementations, the LLM is primarily trained using the traditional Next Token Prediction (NTP) method. Specifically, the user's request is input into the LLM, which then uses a traditional tokenizer to break the code into sub-word units. These sub-words are then output one by one according to the tokens using NTP to train the LLM. Based on this trained LLM, the user's request can be input into it. The trained LLM combines the input request with its learned knowledge to perform contextual understanding of the request. Code is generated incrementally, one token at a time, until a complete code snippet is generated or a specific termination condition is met.

[0072] However, the above methods result in fragmented code structures learned by the LLM during training, which weakens the ability of the trained LLM to capture syntax. Therefore, when using the trained LLM to generate code, the generated code may have poor syntactic integrity.

[0073] Based on this, this application provides a code generation method. In the process of generating corresponding code based on the user's code generation requirements using a code generation model, a syntactically complete tag sequence is obtained for each iteration, so that the code generated based on the multi-round iteration process is syntactically complete, which can improve the integrity of the generated code.

[0074] It should be noted that the code generation model can be a large language model.

[0075] Figure 1 This is a schematic diagram illustrating an application scenario of a code generation method provided in an embodiment of this application.

[0076] like Figure 1 As shown, when a user wants to generate code through the code generation model, they can input their code generation requirements into the code generation model. These requirements can be input into the code generation model in the form of natural language.

[0077] The code generation model generates syntactically complete code based on the user's input code generation requirements.

[0078] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.

[0079] In this application, the model to be trained can be pre-trained to obtain a trained code generation model, which enables the trained code generation model to recognize whether the syntax of the code is complete. The following sections describe the process from two aspects: training the model to be trained to generate the code generation model, and using the code generation model to generate code.

[0080] First, the method for model training will be explained. Figure 2 This is a flowchart illustrating a model training method provided in an embodiment of this application.

[0081] like Figure 2 As shown, the model training method includes the following steps:

[0082] S201. Obtain the code generation requirement set and target code set.

[0083] The code generation requirement set includes different code generation needs from users, which can be in natural language.

[0084] The code in the target code set includes one or more of various code types such as Verilog code, Verilog-A code, VHDL code, and SystemVerilog code. This application does not specifically limit the code.

[0085] Verilog is a hardware description language used to design and describe digital circuit systems.

[0086] For example, the code in the code set can be the processed version of the initial code. The process of processing the initial code can be as follows:

[0087] Obtain the initial code set; parse the code in the initial code to obtain the corresponding Abstract Syntax Tree (AST); extract the syntax tags in the AST, and segment the code based on the syntax tags, adding special tags before and after the segmentation points to obtain the target code; construct the target code set from multiple target code sets.

[0088] For example, the initial code in the initial code set may be collected from platforms such as Github, Bitbucket, and Gitee. This application embodiment does not specifically limit the platform for collecting the code.

[0089] Furthermore, the collected code is deduplicated based on similarity. For example, MinHash and Jaccard can be used to deduplicat the collected code based on similarity. Of course, similarity deduplication can also be performed through methods such as string matching. This application does not specifically limit the method used for similarity deduplication.

[0090] MinHash is a fast algorithm for estimating set similarity by generating hash signatures to reduce computation.

[0091] The Jaccard similarity metric calculates the overlap between two code snippets by comparing their MinHash signatures. If the similarity exceeds a threshold, the code is considered duplicated, and one of the snippets is deleted.

[0092] Deduplication of the collected code can reduce the presence of a large amount of duplicate or highly similar code in the dataset and improve the diversity of the code in the initial code set.

[0093] Furthermore, the deduplicated code can be filtered out for incomplete modules or files that consist mainly of comments.

[0094] Further, optionally, when the trained model is used to generate Verilog code, it can be supplemented with open-source data from MG-Verilog and RTLCoder to obtain an initial code set.

[0095] The MG-Verilog open-source dataset contains Verilog code samples of varying complexity. By supplementing the initial code set with the MG-Verilog open-source dataset, the trainable model's ability to understand and process Verilog code can be improved.

[0096] RTLCoder's open-source data can be used as high-quality samples to supplement the code set, allowing the model to be trained to learn RTL code and draw on RTLCoder's ability to generate RTL code.

[0097] Therefore, by supplementing with open-source data from MG-Verilog and RTLCoder, the quality of code generated by a well-trained code generation model can be improved.

[0098] For example, a parser (such as Stagraa Verilog, which is not limited to this embodiment) can be used to perform syntax checking, retain only the syntactically correct code, and extract the syntax identifiers in its Abstract Syntax Tree (AST). The syntax identifiers in the Abstract Syntax Tree can be keywords such as module, endmodule, input, and always.

[0099] For example, when adding special identifiers, regular expressions can be used to split the code based on syntax identifiers, and special identifiers can be inserted at the split points to indicate that the split points are the boundaries of the code's syntax structure.

[0100] Optionally, the special identifier can be represented by [FRAG] or other formats. This application does not specifically limit the format of the special identifier.

[0101] In this way, by adding special identifiers to the initial code to identify its syntactic structure, the model to be trained can learn to distinguish the syntactic structure of the code when it is trained on the code with the added identifiers. This results in the code generated by the trained code generation model having higher syntactic integrity.

[0102] S202. Based on the code generation requirement set and the target code set, train the model to be trained for M rounds to obtain the code generation model. In the Xth round of training, train the model to be trained based on the syntactically complete code in the code generation requirement set and the target code set.

[0103] Where M is an integer greater than 0, the code generation model is used to generate corresponding code based on the user's code generation requirements.

[0104] For example, the model to be trained may include CodeT5p or CodeLlama, but this application embodiment does not limit the model to be trained.

[0105] In this application, the model to be trained may include a base prediction head and at least one additional prediction head. The base prediction head is the prediction head inherent in the model itself, and the additional prediction head is added on top of the base prediction head.

[0106] Since the model to be trained includes multiple prediction heads, the target codes in the target code set can be in the form of combined labels. The combined labels include a first label corresponding to the base prediction head and a second label corresponding to the additional prediction head. The second label of the j-th additional prediction head is generated by shifting the first label j positions to the left and filling it with the first identifier. The first label and the second label are codes with special identifiers added.

[0107] For the second label of the j-th additional prediction header, the length of each label can be made consistent by padding with the first identifier.

[0108] In this way, by combining labels, different prediction heads can learn predictions at different time steps, thereby improving the efficiency of model training.

[0109] In this application, during the training of the model to be trained, in the Yth training round, for the markers in the predicted marker sequence that are after the last special marker, the second marker is used to replace them to obtain the target marker sequence, so that the markers after the last special marker do not participate in the calculation of the loss function; wherein, the markers after the last special marker are grammatically incomplete markers.

[0110] For example, the second identifier can be represented by [IGNORE] or other formats. This application embodiment does not limit the format of the second identifier.

[0111] It should be noted that the above markers can be generated code.

[0112] Since the code corresponding to the last special identifier is an incomplete grammatical fragment, if the model is trained directly, it may learn an incomplete grammatical structure. This application uses a second identifier to replace the incomplete grammatical structure, so that the model ignores the incomplete grammatical parts of the code during training, and the code learned by the model is grammatically complete, making the code generated by the subsequently trained code generation model more grammatically complete.

[0113] During training, the proportion of the second identifier in the code set can be gradually increased. Initially, a code set containing a low proportion of the second identifier is used, and this proportion is gradually increased. This reduces the difficulty of prediction and improves training efficiency.

[0114] During model training, the loss function needs to be calculated once in each training round. In the Yth training round, the loss function is calculated based on the target label sequence and the corresponding combined label, where the second identifier in the target label sequence is not included in the loss function calculation.

[0115] The loss function is calculated using the following formula:

[0116]

[0117] Where Loss is the loss function, Loss base The loss function for the basic prediction head, The loss function for attaching the prediction head.

[0118] λ is a pre-defined first hyperparameter. The larger λ is, the greater the weight of the loss function of the additional prediction head.

[0119] γ is a pre-defined second hyperparameter; as i increases, γ... i The smaller the value, the smaller the weight of the corresponding additional prediction head's loss function.

[0120] The base prediction head generates a demand set and a target code set based on the input user code and attempts to predict the next label. The prediction result of the model to be trained is compared with the first label corresponding to the base prediction head, and the difference between the two is calculated using the cross-entropy loss function, thus obtaining the loss. base .

[0121] Each additional prediction head in the model to be trained is responsible for predicting the label at a specific subsequent position; for example, the i-th additional prediction head predicts the label at position t+i+1. The prediction result of each additional prediction head is compared with the corresponding second label, and the loss is calculated using the cross-entropy loss function.

[0122] When the calculated loss function meets the requirements, the training process stops, and the trained code generation model is obtained.

[0123] In this way, the second identifier is not included in the calculation of the loss function, which makes the model training process focus more on syntactically complete code and ignore syntactically incomplete code, thus improving the efficiency of model training.

[0124] In this way, a code generation model is obtained by training the model to be trained using syntactically complete code from the code generation requirement set and the target code set. That is, syntactically incomplete code is ignored during training, so that the code learned by the model to be trained is syntactically complete, thereby improving the syntactic completeness of the code generated subsequently by the trained code generation model.

[0125] The specific process of model training will be explained below.

[0126] Using Verilog code as an example, the preprocessing process of the initial code is explained. (See also...) Figure 3 As shown, Figure 3 This is a schematic diagram of a code preprocessing process provided in an embodiment of this application.

[0127] like Figure 3 The preprocessing of the initial code shown includes:

[0128] Step 1: Obtain the initial code.

[0129] Collect Verilog code files (.v files) from Github and use MinHash and Jaccard similarity metrics to remove duplicates from the Verilog code.

[0130] Filter out incomplete modules or files that consist mainly of comments, and supplement with open-source data from MG-Verilog and RTLCoder.

[0131] Step 2: Extract important grammatical markers.

[0132] The grammatical importance markers are the grammatical identifiers described in the above embodiments.

[0133] The Verilog code is parsed using the Stagira Verilog parser to generate an AST, from which important syntactic markers (such as keywords like module and endmodule) are extracted.

[0134] Step 3: Generate code with special identifiers.

[0135] Code splitting is performed using regular expressions based on important tags, and special identifiers [FRAG] are inserted at the split points to identify the syntactic structure.

[0136] The initial code is shown below as an example:

[0137]

[0138] The AST corresponding to data_register in the above code can be found here. Figure 4 As shown, Figure 4 This is a schematic diagram of an abstract syntax tree for code provided in an embodiment of this application.

[0139] In the code above, the important keywords are: data_register, reg, clk, 3, data_in, and data_out. Less important keywords include: module, endmodule, and reg.

[0140] After adding the special identifier [FRAG], it becomes:

[0141] [FRAG]module[FRAG][FRAG]data_register[FRAG][FRAG]([FRAG]

[0142] [FRAG]input[FRAG][FRAG]clk[FRAG],

[0143] [FRAG]input[FRAG][[FRAG]3[FRAG]:0][FRAG]data_in[FRAG],

[0144] [FRAG]output[FRAG][FRAG]reg[FRAG][[FRAG]3[FRAG]:0][FRAG]data_out[FRAG]

[0145] [FRAG])[FRAG][FRAG];[FRAG]

[0146] [FRAG]always[FRAG]@([FRAG]posedge[FRAG][FRAG]clk[FRAG])[FRAG]begin[FRAG]

[0147] [FRAG]data_out[FRAG][FRAG]<=[FRAG][FRAG]data_in[FRAG];

[0148] [FRAG]end[FRAG]

[0149] [FRAG]endmodule[FRAG]

[0150] Based on the above, the process for processing the initial code set in this application embodiment can also be found in [reference needed]. Figure 5 As shown, Figure 5 This is a schematic diagram illustrating a process for processing an initial code set, provided as an embodiment of this application.

[0151] based on Figure 5As shown, the obtained Verilog file is segmented into multiple code units. Deduplication and filtering are then performed on these code units and the existing dataset to obtain the initial code. The code is then parsed using the Statagira parser, and syntax checking is performed. Incomplete code is further removed to obtain the cleaned code.

[0152] The cleaned code is parsed using the Statagira parser to obtain an abstract syntax tree (AST). Based on the AST, syntactic importance tags are extracted and special identifiers [FRAG] are added to obtain code containing syntactic structure information.

[0153] The existing datasets are supplemented by open-source data from MG-Verilog and RTLCoder.

[0154] Furthermore, in Figure 3 After performing the above preprocessing on the initial code, the following steps can be performed:

[0155] Step 1: Generate combined tags.

[0156] The label L0 of the model to be trained is a tokenized code containing [FRAG]. The label Li of the i-th head is generated by shifting L0 left by i bits and filling it with the first identifier [PAD], thus forming a combined label.

[0157] Step 2: During model training, use the second identifier [IGNORE] to exclude incomplete syntax information, ensuring that the model captures the complete syntax structure of Verilog code.

[0158] The method of using [IGNORE] to exclude incomplete syntax information can be found in the above embodiments, and will not be repeated here.

[0159] The proportion of [IGNORE] in the labels of subsequent prediction heads is increased to reduce the difficulty of prediction and improve training efficiency.

[0160] For example, Table 1 below shows the correspondence between prediction heads and positions without using [IGNORE] to exclude incomplete grammatical information.

[0161]

[0162]

[0163] Table 2 below shows the correspondence between the prediction head and position after using [IGNORE] to exclude incomplete grammatical information.

[0164]

[0165] Step 3: Calculate the loss function.

[0166] The method for calculating the loss function can be found in the above embodiments, and will not be repeated here.

[0167] The code generation model generated based on the above training method can generate corresponding code according to the user's code generation needs. The following describes the process of generating code using the trained code generation model.

[0168] Figure 6 This is a flowchart illustrating a code generation method provided in an embodiment of this application.

[0169] like Figure 6 As shown, the code generation method includes the following steps:

[0170] S601. Obtain the user's code generation requirements.

[0171] For example, a user's code generation requirement can be in natural language or other forms, and this application embodiment does not limit this.

[0172] S602. Based on the code generation requirements, use the code generation model to generate the code corresponding to the code generation requirements; wherein, the code is obtained by generating N predicted tag sequences using N iterations; wherein, in the i-th iteration, multiple tags are predicted based on the input information, and a predicted tag sequence is constructed based on the grammatically complete tags among the multiple tags; when i equals 1, the input information is the code generation requirements, and when i is greater than 1, the input information includes the code generation requirements and the predicted tag sequences of the previous i-1 rounds.

[0173] The code generation model performs code prediction in each iteration. In this application, the code generation model includes a base prediction head and at least one additional prediction head.

[0174] In the i-th iteration, the code generation model can predict multiple tags based on the input information, which may include: predicting the tag at position t+1 using the basic prediction head, and using the j-th additional prediction head to predict the tag at position t+j+1; t is an integer greater than or equal to 0, and t is the last position predicted in the (i-1)-th iteration.

[0175] In this way, multiple positions can be predicted in each iteration. Compared with existing models that only predict one position in each iteration, the method of this application can reduce the number of iterations, thereby improving the efficiency of code generation model in generating code.

[0176] Based on the model training process described above, the trained code generation model has the ability to add special identifiers. Therefore, during any iteration of the code generation model, when making predictions using the basic prediction head or the additional prediction head, special identifiers can be added simultaneously, so that the predicted labels contain the special identifiers.

[0177] Specifically, in the i-th iteration, the code generation model predicts multiple tags based on the input information. This can be achieved by predicting the tag at the m-th position in the i-th iteration. When the m-th position is determined to be a syntax boundary, a tag containing a special identifier is generated.

[0178] For example, when adding a special identifier, you can add a special identifier both before and after the mark.

[0179] In this way, by adding special markers, grammatical boundaries can be marked so that incomplete grammatical markers can be deleted later.

[0180] In this application, the triggering condition for the end of the iteration may include the following possible implementations:

[0181] In one possible implementation, iteration stops when the end symbol is predicted.

[0182] The terminator can be, for example, [EOS] or `<, etc., and this application does not limit it in this embodiment.

[0183] In another possible implementation, the generation of tags stops when the number of generated tags exceeds a preset threshold to prevent infinite generation.

[0184] This application does not impose specific limitations on the preset threshold.

[0185] Of course, other iteration termination triggering conditions can also be used, but these will not be illustrated in the embodiments of this application.

[0186] The code generation method provided in this application embodiment can construct a predicted tag sequence from the syntactically complete tags among the predicted tags in any round of iteration, thereby obtaining code corresponding to user needs based on the predicted tag sequence of multiple rounds, resulting in a high degree of completeness of the final code.

[0187] In this application, the code generation model constructing a predicted tag sequence based on syntactically complete tags among multiple tags may include: combining multiple tags to construct multiple candidate tag sequences; for any tag in any candidate tag sequence, using a pre-defined acceptance strategy to detect whether the predicted probability corresponding to the tag is greater than an acceptable threshold, the acceptable threshold being related to pre-defined parameters and an entropy function, the entropy function being determined based on information from tags preceding the tag; retaining tags greater than the acceptable threshold to obtain multiple processed candidate tag sequences; for any candidate tag sequence, constructing a target candidate tag sequence based on syntactically complete tags in the candidate tag sequence to obtain multiple target candidate tag sequences; and determining the longest of the multiple target candidate tag sequences as the predicted tag sequence.

[0188] For example, multiple predicted tags can be arbitrarily combined to construct multiple candidate tag sequences.

[0189] Furthermore, the acceptability of predicted labels can be detected using Medusa's acceptance strategy. The formula corresponding to the acceptance strategy is:

[0190] P base (x t+i+1 |x1,x2,……,x t+i )>min(ε,δ*exp{-H(P base (·|x1,x2,……,x t+i ))})

[0191] Among them, P base( x t+i+1| x1,x2,……,x t+i) The code generation model is based on previously predicted labels x1, x2, ..., x t+i The predicted probability of the label at position t+i+1.

[0192] H(P base (·|x1,x2,……,x t+i The labels x1, x2, ..., x are obtained based on prediction. t+i The entropy function value is calculated for the predicted distribution under the given conditions, where ε and δ are pre-defined hyperparameters.

[0193] Taking the negative sign of the entropy function value and then performing an exponential operation converts the entropy function value into a coefficient related to the uncertainty of prediction. The higher the uncertainty (the larger the entropy value), the smaller this coefficient.

[0194] min(ε,δ*exp{-H(P base (·|x1,x2,……,x t+iThe threshold is defined as the acceptable threshold. This threshold, determined based on previously predicted tags, is compared with the probability of the code generation model predicting the next tag to determine if the predicted tag is acceptable. If the probability of the code generation model predicting the next tag is greater than the acceptable threshold, then the current tag and its predecessor tags are considered acceptable.

[0195] By performing an acceptable test on the markers, markers that do not meet the requirements in each candidate marker sequence can be removed.

[0196] Considering that the longest candidate label sequence is more likely to be a label sequence with a more suitable arrangement, the longest one among multiple target candidate label sequences with good integrity is determined as the predicted label sequence, so that the accuracy of the determined predicted label sequence is higher.

[0197] In this way, by performing acceptable detection on the tokens using an acceptable strategy, the resulting candidate token sequences are more complete, which can improve the accuracy of subsequently constructing grammatically complete predicted token sequences. Furthermore, by first identifying multiple target candidate token sequences with good completeness, and then selecting the longest one from these multiple target candidate token sequences as the predicted token sequence, the accuracy of the determined predicted token sequence can be improved.

[0198] In this application, constructing a target candidate tag sequence based on grammatically complete tags in the candidate tag sequence may include: removing tags after the last special identifier in the candidate tag sequence to obtain a grammatically complete target candidate tag sequence.

[0199] Based on the model training method described above, the markers following the last special identifier are more likely to be grammatically incomplete. Therefore, when constructing the target candidate marker sequence, the markers following the last special identifier are removed to improve the grammatical integrity of the constructed target candidate marker sequence.

[0200] Since the tokens following the last special identifier are more likely to be grammatically incomplete, removing the tokens following the last special identifier can remove grammatically incomplete tokens from the sequence, so that the resulting second candidate token sequence consists entirely of grammatically complete tokens.

[0201] Figure 7 This is a schematic diagram illustrating the iterative process of a code generation model provided in an embodiment of this application.

[0202] like Figure 7 As shown, processing based on user code generation requirements can include the following two possible implementations:

[0203] One possible implementation is that the code generation model inputs the user's code generation requirements into the encoder for encoding, and then inputs the encoded code generation requirements into the decoder for prediction.

[0204] Another possible implementation is that the code generation model directly inputs the user's code generation requirements into the decoder, which then makes predictions.

[0205] Therefore, the code generation method provided in this application is applicable to code generation models that include decoders, and also applicable to code generation models that do not include decoders.

[0206] Furthermore, the code generation model uses a base prediction head and an additional prediction head to make predictions, resulting in n prediction tags.

[0207] For example, prediction-based labeling can be obtained Figure 7 Three candidate marker sequences were identified. The candidate marker sequences are:

[0208] ①[FRAG]module[FRAG][FRAG]mux-mux[FRAG][FRAG](

[0209] ②module module{FRAG]mux2to! [FRAG][FRAG](

[0210] ③[FRAG]module[FRAG][FRAG]mux2to1[FRAG](\n

[0211] Acceptable strategy detection and integrity checks were performed on the three candidate marker sequences. Figure 7 The underlined part is the part removed after acceptable strategy detection and integrity check, finally resulting in the final labeled sequence [FRAG]module[FRAG][FRAG]mux2to1[FRAG].

[0212] In conjunction with the above embodiments, the code generation method provided in this application, as well as existing code generation methods, can be used to generate code based on user input code generation requirements. For details on code generation, please refer to... Figure 8 As shown, Figure 8 This is a schematic diagram illustrating the generation of code using a different code generation method provided in an embodiment of this application.

[0213] like Figure 8 As shown, the user-input code generation requirement is:

[0214] Please act as a professional Verilog designer.

[0215] Create a simple Verilog module named"data_register"that takes a 4-bitinput'data_in'and assigns it to a 4-bitoutput`data out`using a non-blockingassignment on the positive edge of the clock.

[0216] Generating code using the code generation method of this application requires 14 steps to meet the above code generation requirements. Generating code using the existing Medusa method requires 24 steps. Generating code using the existing NTP method requires 77 steps.

[0217] Therefore, the code generation method of this application can generate the code required by the user in a smaller number of steps, which can effectively improve the efficiency of code generation.

[0218] Figure 9 This is a schematic diagram of the structure of a code generation device provided in an embodiment of this application, as shown below. Figure 9 As shown, the code generation device 90 provided in this embodiment includes:

[0219] Module 901 is used to obtain the user's code generation requirements.

[0220] The generation module 902 is used to generate code corresponding to the code generation requirements based on the code generation requirements and using the code generation model. The code is obtained by generating N predicted tag sequences using N iterations. In the i-th iteration, multiple tags are predicted based on the input information, and a predicted tag sequence is constructed based on the grammatically complete tags among the multiple tags. When i equals 1, the input information is the code generation requirements. When i is greater than 1, the input information includes the code generation requirements and the predicted tag sequences of the previous i-1 rounds.

[0221] In one possible implementation, the code generation model includes a base prediction head and at least one additional prediction head; the generation module 902 is specifically used to predict the marker at position t+1 using the base prediction head during the i-th iteration, and the j-th additional prediction head is used to predict the marker at position t+j+1; t is an integer greater than or equal to 0, and t is the last position predicted during the (i-1)-th iteration.

[0222] In one possible implementation, the generation module 902 is specifically used to predict the tag at the m-th position during the i-th iteration, and when the m-th position is determined to be a syntax boundary, generate a tag containing a special identifier.

[0223] In one possible implementation, the generation module 902 is specifically used to combine multiple tags to construct multiple candidate tag sequences; for any tag in any candidate tag sequence, a pre-set acceptance strategy is used to detect whether the predicted probability corresponding to the tag is greater than an acceptable threshold, the acceptable threshold is related to pre-set parameters and an entropy function, the entropy function is determined based on the information of the tags before the tag is labeled; tags with a probability greater than the acceptable threshold are retained to obtain multiple processed candidate tag sequences; for any candidate tag sequence, a target candidate tag sequence is constructed based on the grammatically complete tags in the candidate tag sequence to obtain multiple target candidate tag sequences; the longest of the multiple target candidate tag sequences is determined as the predicted tag sequence.

[0224] In one possible implementation, the generation module 902 is specifically used to remove the markers after the last special identifier in the candidate marker sequence to obtain a grammatically complete target candidate marker sequence.

[0225] The code generation device provided in this embodiment can execute the method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described in detail here.

[0226] Figure 10 This is a schematic diagram of the structure of a model training device provided in an embodiment of this application, as shown below. Figure 10 As shown, the model training device 100 provided in this embodiment includes:

[0227] Obtain module 1001, which is used to obtain the code generation requirement set and the target code set.

[0228] Training module 1002 is used to train the model to be trained for M rounds based on the code generation requirement set and the target code set to obtain the code generation model. In the Xth round of training, the model to be trained is trained based on syntactically complete code in the code generation requirement set and the target code set. M is an integer greater than 0. The code generation model is used to generate corresponding code based on the user's code generation requirements.

[0229] In one possible implementation, module 1001 is specifically used to obtain an initial code set; parse the code in the initial code set to obtain the abstract syntax tree corresponding to the code; extract the syntax identifiers in the abstract syntax tree, and segment the code based on the syntax identifiers, adding special identifiers before and after the segmentation points to obtain target code; and construct a target code set from multiple target codes.

[0230] In one possible implementation, the model to be trained includes a base prediction head and at least one additional prediction head. The target codes in the target code set are in the form of combined labels. The combined labels include a first label corresponding to the base prediction head and a second label corresponding to the additional prediction head. The second label of the j-th additional prediction head is generated by shifting the first label j positions to the left and filling it with a first identifier. The first label and the second label are codes with special identifiers added.

[0231] In one possible implementation, the training module 1002 is specifically used in the Yth round of training to replace the markers in the predicted marker sequence that are after the last special identifier with a second identifier to obtain the target marker sequence, so that the markers after the last special identifier do not participate in the calculation of the loss function; wherein, the markers after the last special identifier are grammatically incomplete markers.

[0232] In one possible implementation, the training module 1002 is specifically used to calculate a loss function based on the target label sequence and the corresponding combined label during the Yth round of training, wherein the second identifier in the target label sequence does not participate in the calculation of the loss function.

[0233] The model training device provided in this embodiment can execute the method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described in detail here.

[0234] Figure 11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 11 As shown, the electronic device 110 provided in this embodiment includes at least one processor 1101 and a memory 1102. Optionally, the device 110 further includes a communication component 1103. The processor 1101, the memory 1102, and the communication component 1103 are connected via a bus 1104.

[0235] In a specific implementation, at least one processor 1101 executes computer execution instructions stored in memory 1102, causing at least one processor 1101 to perform the above-described method.

[0236] The specific implementation process of processor 1101 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.

[0237] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.

[0238] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.

[0239] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.

[0240] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.

[0241] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-described method.

[0242] The aforementioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.

[0243] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.

[0244] The division of units is merely a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.

[0245] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0246] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0247] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0248] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.

[0249] Finally, it should be noted that other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein, and is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.

Claims

1. A code generation method, characterized in that, The method includes: Obtain the user's code generation requirements; Based on the code generation requirement, a code generation model is used to generate the code corresponding to the code generation requirement; wherein, the code is obtained by generating N predicted tag sequences using N iterations; wherein, in the i-th iteration, multiple tags are predicted based on input information, and a predicted tag sequence is constructed based on the grammatically complete tags among the multiple tags; when i equals 1, the input information is the code generation requirement, and when i is greater than 1, the input information includes the code generation requirement and the predicted tag sequence of the previous i-1 rounds.

2. The method according to claim 1, characterized in that, The code generation model includes a base prediction head and at least one additional prediction head; In the i-th iteration, multiple labels are predicted based on the input information, including: During the i-th iteration, the marker at position t+1 is predicted using the basic prediction head, and the j-th additional prediction head is used to predict the marker at position t+j+1; where t is an integer greater than or equal to 0, and t is the last position predicted during the (i-1)-th iteration.

3. The method according to claim 2, characterized in that, In the i-th iteration, multiple labels are predicted based on the input information, including: During the i-th iteration, for the prediction of the tag at the m-th position, when the m-th position is determined to be a syntax boundary, a tag containing a special identifier is generated.

4. The method according to any one of claims 1-3, characterized in that, The construction of the predicted tag sequence based on the grammatically complete tags among the plurality of tags includes: The multiple tags are combined to construct multiple candidate tag sequences; For any tag in any candidate tag sequence, a pre-defined acceptance strategy is used to detect whether the predicted probability corresponding to the tag is greater than an acceptable threshold. The acceptable threshold is related to pre-defined parameters and an entropy function, which is determined based on information about tags preceding the tag. Tags larger than the acceptable threshold are retained to obtain multiple processed candidate tag sequences; For any processed candidate tag sequence, construct a target candidate tag sequence based on the grammatically complete tags in the processed candidate tag sequence to obtain multiple target candidate tag sequences; The longest of multiple target candidate label sequences is determined as the predicted label sequence.

5. The method according to claim 4, characterized in that, The step of constructing a target candidate tag sequence based on grammatically complete tags in the candidate tag sequence includes: Remove the markers after the last special identifier in the candidate marker sequence to obtain the grammatically complete target candidate marker sequence.

6. A model training method, characterized in that, The method includes: Obtain the code generation requirements set and target code set; The model to be trained is trained for M rounds based on the code generation requirement set and the target code set to obtain the code generation model. In the Xth round of training, the model to be trained is trained based on the syntactically complete code in the code generation requirement set and the target code set. M is an integer greater than 0. The code generation model is used to generate corresponding code based on the user's code generation requirements.

7. The method according to claim 6, characterized in that, The acquisition of the target code set includes: Obtain the initial code set; The code in the initial code set is parsed to obtain the abstract syntax tree corresponding to the code; Extract the syntax identifiers from the abstract syntax tree, and segment the code based on the syntax identifiers. Add special identifiers before and after the segmentation points to obtain the target code. Multiple target codes are combined into a target code set.

8. The method according to claim 7, characterized in that, The model to be trained includes a base prediction head and at least one additional prediction head. The target code in the target code set is in the form of a combined label. The combined label includes a first label corresponding to the base prediction head and a second label corresponding to the additional prediction head. The second label of the j-th additional prediction head is generated by shifting the first label j positions to the left and filling it with a first identifier. The first label and the second label are codes with the special identifier added.

9. The method according to any one of claims 6-8, characterized in that, The process of training the model to be trained for M rounds based on the code generation requirement set and the target code set to obtain the code generation model includes: During the Yth round of training, for the markers in the predicted marker sequence that are after the last special marker, the second marker is used to replace them to obtain the target marker sequence, so that the markers after the last special marker are not included in the calculation of the loss function; where the markers after the last special marker are grammatically incomplete markers.

10. The method according to claim 9, characterized in that, The method further includes: During the Yth training round, a loss function is calculated based on the target label sequence and the corresponding combined label, wherein the second identifier in the target label sequence is not included in the calculation of the loss function.

11. A code generation device, characterized in that, include: The acquisition module is used to acquire the user's code generation requirements; A generation module is used to generate code corresponding to the code generation requirement based on the code generation requirement and using a code generation model; wherein the code is obtained by generating N predicted tag sequences using N iterations; wherein, in the i-th iteration, multiple tags are predicted based on input information, and a predicted tag sequence is constructed based on grammatically complete tags among the multiple tags; when i equals 1, the input information is the code generation requirement, and when i is greater than 1, the input information includes the code generation requirement and the predicted tag sequence of the previous i-1 iterations.

12. A model training device, characterized in that, include: The acquisition module is used to obtain the code generation requirement set and the target code set; The training module is used to train the model to be trained for M rounds based on the code generation requirement set and the target code set to obtain the code generation model. In the Xth round of training, the model to be trained is trained based on the syntactically complete code in the code generation requirement set and the target code set. M is an integer greater than 0. The code generation model is used to generate corresponding code based on the user's code generation requirements.

13. An electronic device, comprising: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1-10.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-10.