Method and device for training code generation model, and storage medium
By screening high-quality code snippets and generating programming problem texts to form a mixed training sample set, the problem of code generation model learning difficulties in existing technologies is solved, and more efficient and reliable code generation capabilities are achieved.
Patent Information
- Application Number
- CN202510809270.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-17
- Publication Date
- 2025-09-23
AI Technical Summary
In the existing code generation model training methods, the code resources provided by the Internet and open source communities contain a large number of low-quality, repetitive or non-standard code snippets, which makes model learning difficult. In addition, the syntax and structure of code data are very different from those of natural language, making it difficult to improve capabilities.
Through screening conditions, code snippets that meet the preset standards are selected from the original code snippets to form a pure code dataset. The large model is used to generate programming question text and answer code to form a text code dataset. After mixing, a training sample set is generated to train the code generation model.
The generation capability of the code generation model has been improved, making it more reliable and practical. It can generate complete code snippets based on code snippets or programming problem text, improving the training efficiency and performance of the model.
Smart Images

Figure CN120687072A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a method, device, and storage medium for training a code generation model. Background Art
[0002] With the development of artificial intelligence, it's possible to generate code using trained code generation models, assisting developers. For example, large language models (LLMs) such as CodeLlama and CodegeeX can be trained for code generation to enable assisted programming. These models not only help developers automatically complete code but also generate complex code snippets, fix errors, optimize code performance, and even write code based on natural language descriptions.
[0003] Currently, the typical method for training code generation models is to obtain code resources from the internet and open source communities, and then train an LLM based on these resources to generate a code generation model. However, the code resources provided by the internet and open source communities contain many low-quality, repetitive, or non-standard code snippets. This code data cannot effectively help the model learn and generalize. In addition, code data differs significantly from traditional text data. For example, code data has stricter grammar and structure requirements than natural language and often contains a large number of repeated and invalid characters. This makes it more difficult for the model to learn from code data, and improving the model's ability to learn code is more difficult than improving its ability to learn natural language. Summary of the Invention
[0004] In view of this, the present disclosure proposes a method, device, and storage medium for training a code generation model, so as to use more optimized training data to train the code generation model, improve the code generation capability of the code generation model, and make the code generation model more reliable and practical.
[0005] According to one aspect of the present disclosure, a method for training a code generation model is provided, the method comprising:
[0006] According to a preset screening condition, a plurality of code snippets that meet the preset screening condition are screened out from the plurality of original code snippets, and each of the plurality of code snippets is used as each piece of pure code data to form a pure code data set;
[0007] Generate multiple programming question texts and corresponding answer codes of various preset question types using the large model, and use each programming question text and corresponding answer code in the multiple programming question texts as each text code data to form a text code data set;
[0008] Mixing the pure code dataset with the text code dataset to form a mixed dataset including pure code data and text code data, and generating a training sample set based on the mixed dataset;
[0009] The code generation model is trained using the training sample set so that the code generation model can generate a complete code snippet based on a portion of the code snippet or the programming problem text.
[0010] The screening condition specifies at least one of an average length of all lines of the code snippet, the number of lines of the code snippet, the recognition degree of the code snippet, and the ratio of valid characters in the code snippet.
[0011] In a possible implementation, in the training sample set, the proportion of samples based on pure code data to the total number of samples is not less than a preset code proportion threshold, and / or
[0012] The number of times the code generation model is trained using the training sample set is not less than a preset training number threshold.
[0013] In one possible implementation, the method of using the large model to generate multiple programming question texts of various preset question types and corresponding answer codes includes:
[0014] Select one or more seed questions of each question type from the programming question bank to form a seed question set;
[0015] The large model generates multiple programming question texts and corresponding answer codes of the multiple question types according to the seed question set.
[0016] The seed questions are the questions with the highest frequency of collection or the most answers of each question type.
[0017] In a possible implementation, causing the large model to generate multiple programming question texts of the various question types and corresponding answer codes based on the seed question set includes:
[0018] Inputting the seed question set into the large model, so that the large model generates a first plurality of programming question texts and corresponding answer codes for each question type of the plurality of question types;
[0019] Inputting a first plurality of programming question texts of each question type in the plurality of question types into the large model, so that the large model generates a second plurality of programming question texts and corresponding answer codes for each question type in the plurality of question types;
[0020] The first plurality of programming question texts and the second plurality of programming question texts are filtered using a preset filtering algorithm, and the filtered programming question texts are used as the plurality of programming question texts of the plurality of question types.
[0021] In a possible implementation, generating a training sample set based on the mixed data set includes:
[0022] Converting the plurality of pure code data and the plurality of text code data in the mixed data set into corresponding plurality of pure code word unit sequences and plurality of text code word unit sequences respectively;
[0023] Compacting the plurality of pure code word sequences according to a preset sample length to obtain a plurality of pure code data-based samples each having the sample length;
[0024] According to the sample length, the plurality of text code word sequences are compacted and filled with words to obtain a plurality of samples based on the text code data, each having the sample length;
[0025] The training sample set is constructed using the plurality of samples based on pure code data and the plurality of samples based on text code data.
[0026] In a possible implementation, the screening condition includes at least one of the following conditions:
[0027] The average length of all lines of the code snippet is within a preset length range, the number of lines in the code snippet does not exceed a preset line number threshold, the recognition of the code snippet is not lower than a preset recognition threshold, and the ratio of valid characters in the code snippet is not lower than a preset valid character ratio threshold.
[0028] The recognition degree of the code snippet is indicated by the frequency of the code snippet being marked by multiple users, and the valid characters in the code snippet do not include blank characters and any characters in comments.
[0029] In a possible implementation, the screening condition further includes that a readability score of the code snippet evaluated according to a preset scoring standard does not exceed a preset readability score threshold, and the readability score is evaluated according to a preset readability scoring rule.
[0030] According to another aspect of the present disclosure, an apparatus for training a code generation model is provided, comprising a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the above method.
[0031] According to another aspect of the present disclosure, a non-volatile computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method are implemented.
[0032] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, or a non-volatile computer-readable storage medium carrying the computer program, wherein the computer program implements the steps of the above method when executed by a processor.
[0033] By screening out multiple code snippets that meet the preset screening conditions from multiple original code snippets according to preset screening conditions, and taking each of the multiple code snippets as each pure code data to form a pure code dataset; using a large model to generate multiple programming question texts of multiple preset question types and corresponding answer codes, and taking each programming question text and the corresponding answer code in the multiple programming question texts as each text code data to form a text code dataset; mixing the pure code dataset with the text code dataset to form a mixed dataset including pure code data and text code data, and generating a training sample set based on the mixed dataset; using the training sample set to train the code generation model so that the code generation model can generate a complete code snippet based on a part of the code snippet or the programming question text. On the one hand, a high-quality pure code dataset can be screened out through the screening conditions, and on the other hand, a text code dataset can be generated through the large model; in this way, using the training sample set composed of the mixture of the pure code dataset and the text code dataset to train the code generation model can ensure that the model can be trained with high-quality and diverse training samples, thereby improving the code generation capability of the code generation model and making the code generation model more reliable and practical.
[0034] Other features and aspects of the present disclosure will become apparent from the following detailed description of exemplary embodiments with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate exemplary embodiments, features, and aspects of the disclosure and, together with the description, serve to explain the principles of the disclosure.
[0036] Figure 1 A flowchart showing a method for training a code generation model according to an embodiment of the present disclosure is shown;
[0037] Figure 2 A schematic diagram illustrating a process of generating multiple programming question texts of various question types and corresponding answer codes according to an embodiment of the present disclosure;
[0038] Figure 3A schematic diagram showing a sample based on pure code data and a sample based on text code data according to an embodiment of the present disclosure;
[0039] Figure 4 A block diagram illustrating an apparatus for training a code generation model according to an embodiment of the present disclosure is shown;
[0040] Figure 5 A block diagram of an apparatus for training a code generation model according to another embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0041] Various exemplary embodiments, features, and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise indicated.
[0042] As used herein, the terms "comprises," "comprising," "having," or variations thereof are open ended and include one or more stated features, integers, elements, steps, parts, or functions, but do not preclude the presence or addition of one or more other features, integers, elements, steps, parts, functions, or groups thereof.
[0043] When an element is referred to as being "connected," "coupled," "responsive" or variations thereof to another element, it can be directly connected, coupled or responsive to the other element or intervening elements may be present.
[0044] Although the terms first, second, third, etc. may be used herein to describe various elements / operations, these elements / operations should not be limited by these terms. These terms are only used to distinguish one element / operation from another element / operation. Therefore, without departing from the teachings of the present invention, the first element / operation in some embodiments may be referred to as the second element / operation in other embodiments.
[0045] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.
[0046] In addition, numerous specific details are provided in the following detailed description to better illustrate the present disclosure. Those skilled in the art will appreciate that the present disclosure can be practiced without certain specific details. In some instances, methods, means, components, and circuits well known to those skilled in the art are not described in detail in order to highlight the main points of the present disclosure.
[0047] Figure 1A flowchart of a method for training a code generation model according to an embodiment of the present disclosure is shown. This embodiment takes the method used in an electronic device as an example for explanation. The electronic device includes but is not limited to: a user terminal or a server and other devices with processing capabilities. The user terminal can be a mobile phone, a computer, a tablet computer, a wearable device, etc. This embodiment does not limit the implementation of the electronic device. Figure 1 As shown, the method includes:
[0048] In step 101 , according to a preset screening condition, a plurality of code snippets meeting the screening condition are screened out from a plurality of original code snippets, and each of the plurality of code snippets is used as each piece of pure code data to form a pure code data set.
[0049] The original code snippets can be obtained from open source code and / or code repositories (code hosting platforms, such as GitHub, Gitee, etc.), or can also be obtained from the Internet through crawler technology. This embodiment does not limit the method of obtaining the original code snippets. Since the original code snippets may include content that is not helpful for training the code generation model, in this embodiment, multiple original code snippets are screened by setting preset screening conditions, and multiple code snippets that meet the screening conditions are screened. Each code snippet is used as each pure code data to form a pure code data set. Invalid or low-quality code snippets can be filtered out, thereby improving the quality of the training samples of the code generation model, thereby improving the training efficiency of the code generation model and saving computing resources.
[0050] The screening condition may, for example, specify at least one of the average length of all lines of the code snippet, the number of lines of the code snippet, the recognition degree of the code snippet, and the ratio of valid characters in the code snippet.
[0051] Accordingly, the screening conditions include at least one of the following conditions:
[0052] 1. The average length of all lines in the code snippet is within the preset length range.
[0053] The average length of all lines of a code snippet refers to the average length of each line of code in the code snippet, where the length of each line of code in the code snippet refers to the total number of characters in the line of code.
[0054] If the average length of all lines of an original code snippet is too short, it indicates that the original code snippet lacks contextual information, which is not conducive to model understanding and model building. If the average length of all lines of an original code snippet is too long, it indicates that the original code snippet may include information that is not helpful for model training (such as configuration information) and does not have a typical code logic structure. In this embodiment, by setting a filtering condition to specify the average length of all lines of a code snippet, and the average length of all lines of a code snippet that meets the filtering condition is within a preset length range, meaningless or low-quality original code snippets can be filtered out.
[0055] Preferably, the preset length range can be [5, 100], i.e., code snippets whose average length across all lines is between 5 and 100 characters are screened. This ensures the diversity of the code snippets while maintaining an appropriate level of complexity. In other implementations, the length range for the average length of all lines of the code snippets can also be set in other ways, and this embodiment does not limit the implementation of the length range.
[0056] 2. The number of lines of the code snippet does not exceed the predetermined line threshold.
[0057] Since original code snippets with a large number of lines require a longer training time and may include a lot of redundant content, in this embodiment, by setting filtering conditions to specify the number of lines of the code snippet, the number of lines of the code snippet that meets the filtering conditions does not exceed the predetermined line number threshold, and the original code snippets with longer lengths can be filtered out, thereby improving the quality of training samples and thus improving the efficiency of model training.
[0058] Preferably, the predetermined line number threshold can be 1000 lines, that is, code snippets with no more than 1000 lines are filtered. This ensures the diversity of code snippets while maintaining an appropriate level of complexity. In other implementations, the line number threshold can also be set in other ways, and this embodiment does not limit the implementation method of the line number threshold.
[0059] 3. The recognition level of the code snippet is not lower than the preset recognition threshold.
[0060] Exemplarily, the recognition of a code snippet is indicated by the frequency with which the code snippet is marked by multiple users. "Marked" means being paid attention to by users, for example, it can be collected, liked, shared, downloaded, etc. The higher the frequency with which a code snippet is marked by multiple users, the more recognized the code snippet is, and generally, the higher the recognition, the higher the quality and the more complete the function of the code snippet. In this embodiment, by setting the recognition of the code snippet by setting the filtering conditions, the recognition of the code snippet that meets the filtering conditions is not lower than the preset recognition threshold, low-quality original code snippets can be filtered out, and the quality of the code snippets used to train the code generation model can be improved, thereby improving the model performance of the trained code generation model.
[0061] Exemplarily, the frequency with which a code snippet is marked by multiple users can be indicated by the number of stars of the code snippet, for example. For example, for open source code or in a code repository, a user can collect the corresponding code snippet by setting stars on the code snippet. Therefore, the number of stars can indicate the frequency with which a code snippet is marked by multiple users, reflecting the recognition and influence of the code snippet. The number of stars can be obtained, for example, from the data provider of the code snippet. For example, if the code snippet originates from GitHub, when the code snippet is obtained from GitHub, the number of stars of the code snippet can be obtained from GitHub. In other implementations, the frequency of user marking can also be indicated by other information, such as the number of likes, the number of collections, or the number of downloads, and this embodiment does not limit the representation method of the frequency of user marking.
[0062] In addition, the original code snippet may include original code snippets of multiple code types (code languages), and the application extent of different code types is different. The more widely used the code snippet of the code type is, the larger the user base is, and the more times the code snippet of the corresponding code type is marked by users. For example, the original code snippet may include code snippets of multiple code types such as Python type, C language type, C++ type, Java type, etc., among which Python type is the most widely used and has the largest user base. Even if the number of times the Python type code snippet is marked (such as the number of stars, the number of likes, etc.) is the same as that of code snippets of other code types, since there are more Python type users and fewer other code type users, it cannot be definitely assumed that the recognition of the Python type code snippet is the same as that of code snippets of other code types that have been marked the same number of times. In this case, if the absolute value of the number of times marked is used as the recognition indicator and a recognition threshold is set, code snippets of code types whose code quality meets the requirements but has a small user base may be inappropriately filtered out. Therefore, in one possible implementation method, the frequency of code snippets marked by multiple users used to indicate the recognition of a code snippet can be a relative value rather than an absolute value. For example, the absolute value of the number of times a code snippet has been marked (e.g., number of stars, likes, favorites, downloads, etc.) can be divided by the number of times the code snippet has been read as the frequency of the code snippet being marked by multiple users, i.e., the recognition indicator, and a corresponding recognition threshold can be set. The number of times a code snippet has been read can also be obtained from the data provider of the code snippet, along with the number of times the code snippet has been marked.
[0063] 4. The ratio of valid characters in the code snippet is not less than the preset valid character ratio threshold.
[0064] The effective character ratio is the ratio of the number of effective characters in a code snippet to the total number of characters in the code snippet. Effective characters in a code snippet do not include whitespace characters or any characters in comments. For example, effective characters include non-comment letters and numbers, but do not include whitespace characters or comments (e.g., characters following a comment symbol).
[0065] If the ratio of valid characters in the original code snippet is low, it indicates that the original code snippet contains a large number of comments and whitespace characters, and thus has a low information density and low effectiveness. In this embodiment, by setting a threshold for the ratio of valid characters to filter out original code snippets with a low ratio of valid characters, the data effectiveness of the training samples used to train the code generation model can be increased, thereby improving the model performance of the trained code generation model.
[0066] Specifically, the effective character ratio threshold may be, for example, 40% or other values. This embodiment does not limit the specific value of the effective character ratio threshold.
[0067] Optionally, the screening condition may further include that the readability score of the code snippet does not exceed a preset readability score threshold. In one example, the readability score may be assessed according to a preset readability score rule. Exemplarily, the readability score rule includes at least one problem item affecting the readability of the code snippet and a score assigned to the code snippet when the code snippet has the problem item.
[0068] For example, readability scoring rules can be set for each type of code snippet based on the different characteristics of different code types. For example, the readability scoring rules for Python type code snippets can be shown in Table 1 below. In Table 1, the problem items that affect the readability of the code snippet include the 10 problem items shown in the first column, and the score assigned when each problem item has it can be the score shown in the second column. At this time, the more problem items that affect readability the original code snippet has, the higher the readability score of the original code snippet, and the worse the readability. For such a readability scoring rule, for example, the readability score threshold can be set to 25 points, that is, code snippets with a readability score greater than 25 points are filtered out, and code snippets with a readability score less than or equal to 25 points are retained.
[0069] Table 1:
[0070] Question item Score Function line count > 100 1.5 Function nesting level > 4 3 The number of function parameters is > 10 3 Variable name length < 2 1 No exception handling 1 Unspecified numbers 1 No comments 1 Duplicate lines of code 2 The number of rows in the class is > 500 0.5 Dependencies > 20 1.5
[0071] It should be understood that the readability scoring rules and corresponding readability scoring thresholds shown in Table 1 are merely examples. In actual implementation, the readability scoring rules for Python-type code snippets may also include more or fewer problem items, and the scores corresponding to each problem item may also be other numerical values. In addition, the readability scoring rules for other code types may adaptively configure problem items based on the structural features and / or grammatical features of the code type. Accordingly, the readability scoring thresholds may also be set to other numerical values based on the screening requirements. This embodiment does not limit the specific implementation of the readability scoring rules and readability scoring thresholds.
[0072] In other embodiments, for example, the structural features and / or grammatical features of the original code snippet may be extracted, and the structural features and / or grammatical features may be input into a scoring model based on a deep learning network, for example, to obtain a readability score for the original code snippet using the scoring model. Structural features are used to indicate the overall organization and layout of the code snippet, such as: structural features describe the arrangement and combination of preset types of code elements (such as functions, classes, loops, conditional statements, etc.), and / or the module division method, hierarchical relationship, and the interaction between modules; grammatical features are used to indicate the way in which the code snippet uses the programming language, such as: grammatical features are used to indicate the use of keywords, symbols, indentation, etc. In addition, the readability score of the code snippet may be obtained by other means, and this embodiment does not limit the method for obtaining the readability score.
[0073] Step 102: Generate multiple programming question texts and corresponding answer codes of various preset question types using the large model, and use each programming question text and corresponding answer code in the multiple programming question texts as each text code data to form a text code data set.
[0074] A programming problem text is a text that describes a programming problem. For example, the programming problem text might be "Given an integer array nums and a target value target, find the indices of the two numbers in the array whose sum is target." The corresponding answer code for the programming problem text is the correct code for solving the programming problem described in the programming problem text.
[0075] Question type refers to the question type obtained by classifying the programming questions described in the programming question text. The classification rules can be, for example, classification according to the algorithm required to solve the question and / or classification according to the data type of the input or output data of the corresponding answer code. For example, programming questions can be classified into array type, string type, dynamic programming type, etc. according to the algorithm required to solve the question and the data type of the input data of the corresponding answer code. The number of question types (question types) can be determined according to actual needs, for example, there can be dozens (for example, 70) question types, etc. Optionally, programming questions can be manually classified to obtain multiple question types, or a classification model or clustering algorithm can be used to classify programming questions to obtain multiple question types. This embodiment does not limit the way of obtaining question types.
[0076] In one example, a large model is used to generate multiple programming question texts of various preset question types and corresponding answer codes, including steps 1021 and 1022:
[0077] Step 1021 , selecting one or more seed questions of each question type from a programming question bank to form a seed question set.
[0078] A programming question bank is a database or resource library that collects programming questions of various types. It includes questions of multiple types, with each type containing one or at least two questions. Examples of programming question banks include LeetCode, Codeforces, and other programming question banks.
[0079] For example, the seed questions can be the most frequently saved or most answered questions of each question type. The more frequently a question is saved or the more answers it receives, the more representative it is, and it can represent the core programming ideas of different questions of the same question type. Using these seed questions and generating a text code dataset based on the seed questions of each question type ensures that the text code dataset has both data diversity and reflects the core programming ideas of each question type, thereby ensuring the performance of the trained code generation model.
[0080] Step 1022: The large model generates multiple programming question texts of various question types and corresponding answer codes based on the seed question set.
[0081] The large model is a trained neural network model that has the ability to generate similar questions based on the input questions. The similar questions include but are not limited to questions with similar or identical test points and / or questions with similar or identical difficulty. The test points of the questions can be reflected as the knowledge points required to solve the questions. Optionally, the large model can be an existing general large model, such as a generative pre-trained transformer (GPT) or DeepSeek R1. Alternatively, it can be a special large model obtained by training or fine-tuning using a pre-prepared training set. This embodiment does not limit the implementation method of the large model.
[0082] Accordingly, reference Figure 2 , so that the big model generates multiple paragraphs of programming question texts and corresponding answer codes for various question types based on the seed question set, including: inputting the seed question set into the big model, so that the big model generates first multiple paragraphs of programming question texts and corresponding answer codes 21 for each question type in the various question types; inputting the first multiple paragraphs of programming question texts for each question type in the various question types into the big model, so that the big model generates second multiple paragraphs of programming question texts and corresponding answer codes 22 for each question type in the various question types; using a preset filtering algorithm to filter the first multiple paragraphs of programming question texts and the second multiple paragraphs of programming question texts, and using the filtered programming question texts as multiple paragraphs of programming question texts 23 for various question types.
[0083] For example, the first plurality of programming question texts and corresponding answer codes for each question type share the same test points as the seed questions of that question type. For example, the answer codes for different questions with the same test points may have the same code logic, but the scenarios and / or data structures may be different.
[0084] In this case, the first plurality of programming question texts for each question type includes at least two different programming question texts; and / or the corresponding answer codes for the first plurality of programming question texts for each question type include at least two corresponding answer codes for the same programming question text. In this way, the large model generates different questions for each question type under the same test topic. These questions can have diverse descriptions (i.e., the first plurality of programming question texts) and can also include different code solutions (i.e., different answer codes corresponding to the same programming question text).
[0085] For example, the seed question for Problem Type 1 is: "How many combinations can be made by using 1-yuan and 2-yuan coins to make 5 yuan?" The large model can modify the background description of the seed question for Problem Type 1 to produce the first multi-paragraph programming problem text: "How many color combinations can be made by painting 3 tiles with red and blue paint?" The first multi-paragraph programming problem text now covers the same key points as the seed question: designing state transition equations and handling boundary conditions in dynamic programming.
[0086] Exemplarily, the second plurality of programming question texts and corresponding answer codes for each question type have similar test points and / or similar difficulty levels as the first plurality of programming question texts for the question type. The answer codes for different questions with similar test points can use the algorithm logic of the same type of algorithm, but the branching algorithms or logic in the algorithm logic can be different, the input data types of the code can be different, the output data types can be different, and / or the constraints can be different. The answer codes for different questions of similar difficulty can use algorithms with similar logical complexity, but the background, input data types, and output data types of the algorithm logic can be different.
[0087] For example, the first multi-paragraph programming problem in question type 1 includes the following: "Paint three tiles with red and blue paint. Find the number of color schemes." The large model can modify the constraints to produce a second multi-paragraph programming problem with similar testing points and difficulty: "Paint five tiles with red and blue paint. Red can be used a maximum of twice, and blue is not limited. Each time, one tile can be painted red or two tiles can be painted blue. Find the number of color schemes." The second multi-paragraph programming problem uses the same algorithm as the first (i.e., dynamic programming), but with different boundary conditions.
[0088] In actual implementation, different questions with the same test points, different questions with similar test points, different questions with the same difficulty, and different questions with similar difficulty can be obtained by artificially dividing the questions. Accordingly, the big model uses each artificially divided question with the same test point, question with similar test points, question with the same difficulty, and question with similar difficulty to train the big model, so that the big model has the above-mentioned ability to generate the first multiple paragraphs of programming problem text and corresponding answer codes, as well as the second multiple paragraphs of programming problem text and corresponding answer codes.
[0089] Optionally, inputting the first multiple paragraphs of programming problem texts of each of the multiple question types into the large model may be inputting all the first multiple paragraphs of programming problem texts of each question type into the large model; or, may be randomly selecting a preset number of first multiple paragraphs of programming problem texts from all the first multiple paragraphs of programming problem texts of each question type and inputting them into the large model. This embodiment does not limit the number of the first multiple paragraphs of programming problems input into the large model.
[0090] Exemplarily, a preset filtering algorithm is used to filter the first plurality of programming problem texts and the second plurality of programming problem texts, including: using the preset filtering algorithm to calculate the similarity between different programming problem texts in the first plurality of programming problem texts and the second plurality of programming problem texts, wherein a higher similarity indicates a greater similarity between the programming problem texts; and comparing the calculated similarity with a preset similarity threshold to filter the first plurality of programming problem texts and the second plurality of programming problem texts, wherein the similarity between different programming problem texts after filtering is lower than the similarity threshold. In this way, the diversity of different programming problem texts after filtering can be ensured, thereby enabling the model to learn richer features.
[0091] Filtering algorithms include, but are not limited to, minihash and SimHash algorithms. This embodiment does not limit the implementation of the filtering algorithm. Taking the minihash algorithm as an example, the similarity threshold can be, for example, 0.8. In other implementations, the similarity threshold can also be set to other values based on filtering requirements. This embodiment does not limit the value of the similarity threshold.
[0092] Step 103 : Mix the pure code dataset with the text code dataset to form a mixed dataset including pure code data and text code data, and generate a training sample set based on the mixed dataset.
[0093] In one example, generating a training sample set based on a mixed data set includes steps 1031-1034:
[0094] Step 1031, convert multiple pure code data (each code snippet in the multiple code snippets is regarded as each pure code data) and multiple text code data (each programming question text and corresponding answer code in the multiple programming question texts and corresponding answer codes) in the mixed data set into corresponding multiple pure code word sequences and multiple text code word sequences respectively.
[0095] The pure code word sequence and the text code word sequence each include at least one word. The word (or token) is the smallest input unit of the code generation model. By converting the pure code data into a pure code word sequence and converting the text code data into a text code word sequence, the data in the mixed data set can be converted into a unified format that can be processed by the code generation model, so that the model can process data of different modalities.
[0096] Exemplarily, multiple pure code data and multiple text code data in a mixed data set are converted into corresponding multiple pure code word sequences and multiple text code word sequences, including: performing word segmentation processing on each pure code data in the multiple pure code data and each text code data in the multiple text code data according to a preset word segmentation rule to obtain corresponding multiple pure code word sequences and multiple text code word sequences; or, using a byte pair encoding (Byte-Pair Encoding, BPE) word segmentation algorithm to perform word segmentation processing on multiple pure code data and multiple text code data to obtain corresponding multiple pure code word sequences and multiple text code word sequences. In actual implementation, the method of converting multiple pure code data and multiple text code data into corresponding multiple pure code word sequences and multiple text code word sequences can also be other methods, which are not listed one by one in this embodiment. It should be understood that each pure code data can be converted into one or more code word sequences, and each text code data can be converted into one or more text word sequences and one or more code word sequences. It should be understood that a "pure code word sequence" in the present disclosure includes one or more code word sequences converted from a piece of pure code data (a code snippet), and a "text code word sequence" includes one or more text word sequences and one or more code word sequences converted from a piece of text code data (a programming question text and the corresponding answer code).
[0097] In step 1032, multiple pure code word sequences are compacted according to a preset sample length to obtain multiple pure code data-based samples, each having the preset sample length. The preset sample length can be, for example, a fixed number of word units, specifically, 4096 word units. This embodiment does not limit the specific value of the preset sample length.
[0098] Packing combines multiple word sequences into a single, long sample sequence to reduce filler usage and maximize the information density of each sample. When a piece of pure code data is converted into multiple code word sequences, these multiple code word sequences can first be packed into a single pure code word sequence. This single pure code word sequence is then packed together with the pure code word sequences converted from other pure code data to obtain a pure code word sequence with a predetermined sample length.
[0099] For example, reference Figure 3 As shown in the example of Sample 1 and Sample 2 based on pure code data, Sample 1 is obtained by compacting pure code word sequence 1 and pure code word sequence 2, and Sample 2 is obtained by compacting pure code word sequence 3, pure code word sequence 4, and pure code word sequence 5. Each of Pure Code Word Sequences 1-5 can be a pure code word sequence obtained by compacting multiple pure code word sequences converted from a piece of pure code data. The resulting Samples 1 and 2 based on pure code data have the same sample length (number of words).
[0100] It should be understood that each sample based on pure code data may include one or more complete pure code word sequences, or may include a portion of a pure code word sequence. For example, if the total number of words in one or more pure code word sequences exceeds the fixed number of words mentioned above, the portion of the pure code word sequence that exceeds the limit may be split into the beginning of the next sample. Since the context of the pure code data is basically of the same style and type, such a split will not affect the code generation model's understanding of the context. Therefore, by compacting multiple pure code word sequences so that the multiple pure code word sequences are closely arranged together, the space of each training sample can be maximized.
[0101] Step 1033 , compacting and filling in multiple text code word sequences according to the above-preset sample length, to obtain multiple samples based on text code data, each having the above-preset sample length.
[0102] Padding refers to adding placeholders (such as zeros) at the end of a string to make the lengths of different strings uniform and facilitate batch processing.
[0103] Compacting and filling in multiple text code word sequences may, for example, include: compacting the text word sequence and code word sequence included in each of the multiple text code word sequences to obtain a compacted text code word sequence including both text words and code words, and then filling in the compacted text code word sequence to obtain a sample based on the text code data having the above-mentioned preset sample length.
[0104] For example, reference Figure 3 As shown in Samples 3 and 4 based on text code data, Sample 3 is obtained by performing word filling after compacting the text word sequence and code word sequence in Text Code Word Sequence 1, and Sample 4 is obtained by performing word filling after compacting the text word sequence and code word sequence in Text Code Word Sequence 2. The resulting Samples 3 and 4 based on text code data have the same sample length, which is the same as the sample length of Samples 1 and 2.
[0105] Because different text code data can vary significantly in style and type, using the same processing method as pure code data (compacting the pure code word sequences converted from pure code data) may prevent the code generation model from properly understanding the context, affecting its training. Therefore, compacting and filling each text code word sequence converted from each piece of text code data ensures the code generation model's ability to understand samples based on the text code data.
[0106] In this embodiment, by compacting the pure code word sequence and compacting and filling the text code word sequence, the use of fillers can be reduced and the effective information of the pure code word sequence and the text code word sequence can be retained. While ensuring that the length of each training sample is consistent, the code generation model's ability to understand the training samples is ensured, which can not only improve training efficiency but also effectively balance resource utilization and model performance.
[0107] Step 1034 , using multiple samples based on pure code data and multiple samples based on text code data to form a training sample set.
[0108] In related technologies, samples based on pure code data often contain a large number of non-critical characters such as spaces and indentations, while samples based on text code data usually have higher information density and more direct semantic expressions. Due to this difference, when calculating the loss value during training, the characters that provide effective loss contribution in samples based on pure code data will be diluted by a large number of blank characters, and the loss value will be averaged, resulting in the samples based on pure code data contributing less to the gradient of the model, and showing a lower loss value compared to those based on text code data. A lower loss value means that the optimization effect on the model parameters is relatively weak. In the scenario where the model is trained by a mixture of samples based on pure code data and samples based on text code data, the parameter update of the model is more likely to lean towards the optimization direction of the text, while ignoring the characteristics and requirements of the code.
[0109] Based on the above technical issues, in order to enable the code generation model to be fully and effectively trained on samples based on pure code data, in one example, in the training sample set, the proportion of samples based on pure code data to the total number of samples is not less than a preset code proportion threshold.
[0110] The code ratio threshold is preferably set to a value that balances the loss of samples based on pure code data with the loss of samples based on text code data. For example, the code ratio threshold is set to a value greater than or equal to 25%. In this case, because the proportion of samples based on pure code data in the training sample set increases, the loss of samples based on pure code data can account for a larger proportion of the overall loss. This increases the gradient update amplitude for samples based on pure code data during backpropagation, enhances the model's ability to learn the features of samples based on pure code data, and improves model performance.
[0111] It should be understood that in order to improve the code generation model's ability to understand, communicate, and generalize text, in addition to samples based on pure code data and samples based on text code data, the training sample set can also include a certain number of samples based on pure text data. For example, multiple segments of plain text related to programming or involving general technology can be extracted from various technical websites, technical documents of various software or toolkits, algorithm books, etc., and the length of each segment of plain text can be adjusted through preprocessing or plain text within a preset length range can be filtered. Each segment of plain text is used as each piece of plain text data, and each piece of plain text data is converted into a sequence of plain text tokens. Multiple plain text token sequences can be compacted and / or word-filled to generate plain text-based samples with the above-mentioned preset sample length. Optionally, the proportion of plain text-based samples in the total number of samples in the training sample set can also be set (for example, 5%). Thus, a training dataset including samples based on pure code data, samples based on text code data, and samples based on plain text data can be used to train the code generation model.
[0112] Step 104 : training the code generation model using the training sample set so that the code generation model can generate a complete code snippet based on a portion of the code snippet or the programming problem text.
[0113] Training a code generation model using a training sample set may, for example, include: inputting each sample in the training sample set into the code generation model, causing the code generation model to output a predicted next code token for each code token of each sample, and using the actual next code token as a label, calculating a loss value based on the two, and updating the parameters of the code generation model based on the loss value, completing the training of the model using the sample until the model has been trained using all samples. Alternatively, a portion of the code token sequence in each sample based on pure code data in the training sample set may be used as input data, the remaining code token sequence in the sample may be used as a label, and a text token sequence in each sample based on text code data in the training sample set may be used as input data, the code token sequence in the sample may be used as a label; batch-feeding multiple input data into the code generation model to obtain model output results; comparing the model output results with the corresponding labels to obtain loss values; updating the model parameters of the code generation model based on the loss values; and again selecting multiple input data to batch-feed into the code generation model to update the model parameters until training has been completed using all input data.
[0114] Since a code word (or a portion of a code word sequence, or a text word sequence) is input into the code generation model during the training process, and the next code word of the code word (or the remaining code word sequence corresponding to the portion of the code word sequence, or the code word sequence corresponding to the text word sequence) is used as a label, the code generation model can learn the ability to generate the following code context based on the code or text context, thereby having the ability to generate a complete code snippet based on a portion of a code snippet or a text snippet. That is, in this embodiment, the code generation model has the following two capabilities:
[0115] Capability 1: Generate a complete code snippet based on a portion of a code snippet. At this point, the code generation model is able to understand the context of a portion of the code snippet and thus predict and generate the complete code snippet.
[0116] Capability 2: Generate complete code snippets based on programming problem text. In this case, the code generation model can generate complete code snippets based on natural language descriptions.
[0117] Optionally, the number of times the code generation model is trained using the training sample set is not less than a preset training number threshold. In related technologies, the code generation model is usually trained once using all training samples. However, in the present disclosure, in order to enhance the influence of code data on the code generation model and to more fully utilize the code data to train the code generation model, the code generation model can be trained multiple times using the training sample set. Preferably, a training number threshold can be set, and the code generation model can be trained using the training sample set for a number of times not less than the training number threshold, so that the model can better adapt to the characteristics of the code data. Specifically, the training number threshold can be, for example, an integer greater than 1 such as 4 or 5, and this embodiment does not limit the value of the training number threshold.
[0118] Optionally, when the number of times the code generation model is trained using the training sample set is greater than or equal to a training number threshold, the currently trained model may be verified, and the proportion of the number of samples based on pure code data to the total number of samples may be adjusted based on the verification results. For example, when the verification results indicate that the currently trained model does not achieve the expected accuracy, the proportion of the number of samples based on pure code data to the total number of samples may be increased. In this way, the proportion of the number of samples based on pure code data may be dynamically adjusted, thereby improving the training efficiency of the model and enhancing the code generation capability of the model.
[0119] In other embodiments, the training number threshold may not be set, but the code generation model may be continuously trained using the training sample set until the change in the model parameters is less than the preset change, or the training is stopped when other conditions are met. The present disclosure does not limit the conditions for stopping training.
[0120] In summary, the method for training a code generation model provided in this embodiment filters out multiple code snippets that meet the preset filtering conditions from multiple original code snippets according to preset filtering conditions, and uses each code snippet in the multiple code snippets as each pure code data to form a pure code dataset; uses a large model to generate multiple programming question texts of multiple preset question types and corresponding answer codes, and uses each programming question text and the corresponding answer code in the multiple programming question texts as each text code data to form a text code dataset; mixes the pure code dataset with the text code dataset to form a mixed dataset including pure code data and text code data, and generates a training sample set based on the mixed dataset; uses the training sample set to train the code generation model so that the code generation model can generate a complete code snippet based on a part of the code snippet or the programming question text; on the one hand, a high-quality pure code dataset can be filtered out by the filtering conditions, and on the other hand, a text code dataset can be generated by the large model; in this way, using the training sample set composed of the mixture of the pure code dataset and the text code dataset to train the code generation model can ensure that the model can be trained with high-quality and diverse training samples, thereby improving the code generation capability of the code generation model and making the code generation model more reliable and practical.
[0121] In addition, by setting the proportion of samples based on pure code data in the training sample set to no less than the preset code ratio threshold, samples based on pure code data can occupy a greater weight in the overall loss function, thereby playing a more significant role in updating model parameters during the backpropagation process and enhancing the model's ability to learn code features.
[0122] In addition, by setting the number of times the code generation model is trained using the training sample set to no less than a preset training threshold, samples based on pure code data can be fully trained, and model parameters are continuously adjusted during multiple training sessions, so that they can better adapt to the characteristics and structure of the sample code.
[0123] Figure 4 A block diagram of an apparatus for training a code generation model according to an embodiment of the present disclosure is shown, wherein the apparatus comprises: a first data set generation module 410 , a second data set generation module 420 , a training sample set generation module 430 , and a model training module 440 .
[0124] The first data set generating module 410 is configured to filter out a plurality of code snippets that meet a preset filtering condition from a plurality of original code snippets, and use each of the plurality of code snippets as a piece of pure code data to form a pure code data set;
[0125] A second data set generation module 420 is configured to generate a plurality of programming question texts and corresponding answer codes of various preset question types using the large model, and to use each programming question text and corresponding answer code in the plurality of programming question texts as each text code data to form a text code data set;
[0126] a training sample set generating module 430 for mixing the pure code data set with the text code data set to form a mixed data set including pure code data and text code data, and generating a training sample set based on the mixed data set;
[0127] The model training module 440 is used to train the code generation model using the training sample set so that the code generation model can generate a complete code snippet based on a part of the code snippet or the programming problem text.
[0128] The screening condition specifies at least one of an average length of all lines of the code snippet, the number of lines of the code snippet, the recognition degree of the code snippet, and the ratio of valid characters in the code snippet.
[0129] Optionally, in the training sample set, the proportion of samples based on pure code data to the total number of samples is not less than a preset code proportion threshold, and / or
[0130] The number of times the code generation model is trained using the training sample set is not less than a preset training number threshold.
[0131] Optionally, the second data set generating module 420 is configured to:
[0132] Select one or more seed questions of each question type from the programming question bank to form a seed question set;
[0133] The large model generates multiple programming question texts and corresponding answer codes of the multiple question types according to the seed question set.
[0134] The seed questions are the questions with the highest frequency of collection or the most answers of each question type.
[0135] Optionally, the step of causing the large model to generate multiple programming question texts of the various question types and corresponding answer codes based on the seed question set includes:
[0136] Inputting the seed question set into the large model, so that the large model generates a first plurality of programming question texts and corresponding answer codes for each question type of the plurality of question types;
[0137] Inputting a first plurality of programming question texts of each question type in the plurality of question types into the large model, so that the large model generates a second plurality of programming question texts and corresponding answer codes for each question type in the plurality of question types;
[0138] The first plurality of programming question texts and the second plurality of programming question texts are filtered using a preset filtering algorithm, and the filtered programming question texts are used as the plurality of programming question texts of the plurality of question types.
[0139] Optionally, the training sample set generating module 430 is configured to:
[0140] Converting the plurality of pure code data and the plurality of text code data in the mixed data set into corresponding plurality of pure code word unit sequences and plurality of text code word unit sequences respectively;
[0141] Compacting the plurality of pure code word sequences according to a preset sample length to obtain a plurality of pure code data-based samples each having the sample length;
[0142] According to the sample length, the plurality of text code word sequences are compacted and filled with words to obtain a plurality of samples based on the text code data, each having the sample length;
[0143] The training sample set is constructed using the plurality of samples based on pure code data and the plurality of samples based on text code data.
[0144] Optionally, the screening condition includes at least one of the following conditions:
[0145] The average length of all lines of the code snippet is within a preset length range, the number of lines in the code snippet does not exceed a preset line number threshold, the recognition of the code snippet is not lower than a preset recognition threshold, and the ratio of valid characters in the code snippet is not lower than a preset valid character ratio threshold.
[0146] The recognition degree of the code snippet is indicated by the frequency of the code snippet being marked by multiple users, and the valid characters in the code snippet do not include blank characters and any characters in comments.
[0147] Optionally, the screening condition further includes that the readability score of the code snippet evaluated according to a preset scoring standard does not exceed a preset readability score threshold, and the readability score is evaluated according to a preset readability score rule.
[0148] For relevant details, please refer to the above method embodiment.
[0149] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments. For the sake of brevity, it will not be repeated here.
[0150] An embodiment of the present disclosure also provides an apparatus for training a code generation model, comprising a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the above method.
[0151] An embodiment of the present disclosure further provides a non-volatile computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of the above method when executed by a processor.
[0152] An embodiment of the present disclosure further provides a computer program product, including a computer program, or a non-volatile computer-readable storage medium carrying the computer program, wherein the computer program implements the steps of the above method when executed by a processor.
[0153] Figure 5 1 is a block diagram of an apparatus 1900 for training a code generation model according to an exemplary embodiment. For example, the apparatus 1900 can be provided as a server or a terminal device. Figure 5 The apparatus 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions, such as an application, that can be executed by the processing component 1922. The application stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1922 is configured to execute the instructions to perform the above-described method.
[0154] The device 1900 may also include a power supply component 1925 configured to perform power management of the device 1900, a wired or wireless network interface 1950 configured to connect the device 1900 to a network, and an input / output interface 1958 (I / O interface). The device 1900 may operate based on an operating system stored in the memory 1932, such as Windows Server 2003. TM , MacOS X TM , Unix TM ,Linux TM , FreeBSD TM or similar.
[0155] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions that can be executed by the processing component 1922 of the apparatus 1900 to perform the above-described method.
[0156] A computer-readable storage medium can be a tangible device that can hold and store programs / instructions used by an instruction execution device. A computer-readable storage medium can be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disc read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination thereof. As used herein, a computer-readable storage medium is not to be construed as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through an electrical wire.
[0157] The computer programs (or computer-readable program instructions) described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions to be stored in the computer-readable storage medium in each computing / processing device.
[0158] The computer program (or computer program instructions) for performing the operations of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages such as Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The computer readable program instructions may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, by utilizing state information of computer-readable program instructions to personalize and customize an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), the electronic circuit can execute the computer-readable program instructions to implement various aspects of the present disclosure.
[0159] Various aspects of the present disclosure are described herein with reference to flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present disclosure. It should be understood that each block of the flowcharts and / or block diagrams, and combinations of blocks in the flowcharts and / or block diagrams, can be implemented by computer-readable program instructions.
[0160] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine such that when these instructions are executed by the processor of the computer or other programmable data processing device, a device is generated that implements the functions / actions specified in one or more blocks in the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium, where these instructions cause the computer, programmable data processing device, and / or other device to operate in a specific manner. Thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing various aspects of the functions / actions specified in one or more blocks in the flowchart and / or block diagram.
[0161] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device, so that a series of operational steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0162] The flow charts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and the part of the module, program segment or instruction contains one or more executable instructions for realizing the prescribed logical function. In some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a dedicated hardware-based system that performs the prescribed function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0163] While various embodiments of the present disclosure have been described above, the above descriptions are illustrative, non-exhaustive, and not intended to be limiting of the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is selected to best explain the principles of the embodiments, their practical applications, or technological improvements in the marketplace, or to enable other persons skilled in the art to understand the embodiments disclosed herein.
Claims
1. A method for training a code generation model, characterized in that The method comprises: According to a preset screening condition, a plurality of code snippets that meet the preset screening condition are screened out from the plurality of original code snippets, and each of the plurality of code snippets is used as each piece of pure code data to form a pure code data set; Generate multiple programming question texts and corresponding answer codes of various preset question types using the large model, and use each programming question text and corresponding answer code in the multiple programming question texts as each text code data to form a text code data set; Mixing the pure code dataset with the text code dataset to form a mixed dataset including pure code data and text code data, and generating a training sample set based on the mixed dataset; The code generation model is trained using the training sample set so that the code generation model can generate a complete code snippet based on a portion of the code snippet or the programming problem text. The screening condition specifies at least one of an average length of all lines of the code snippet, the number of lines of the code snippet, the recognition degree of the code snippet, and the ratio of valid characters in the code snippet.
2. The method according to claim 1, characterized in that In the training sample set, the proportion of samples based on pure code data to the total number of samples is not less than a preset code proportion threshold, and / or The number of times the code generation model is trained using the training sample set is not less than a preset training number threshold.
3. The method according to claim 2, characterized in that The method of using the large model to generate multiple programming question texts of various types and corresponding answer codes includes: Select one or more seed questions of each question type from the programming question bank to form a seed question set; The large model generates multiple programming question texts and corresponding answer codes of the multiple question types according to the seed question set. The seed questions are the questions with the highest frequency of collection or the most answers of each question type.
4. The method according to claim 3, characterized in that The step of causing the large model to generate multiple programming question texts of the various question types and corresponding answer codes based on the seed question set includes: Inputting the seed question set into the large model, so that the large model generates a first plurality of programming question texts and corresponding answer codes for each question type of the plurality of question types; Inputting a first plurality of programming question texts of each question type in the plurality of question types into the large model, so that the large model generates a second plurality of programming question texts and corresponding answer codes for each question type in the plurality of question types; The first plurality of programming question texts and the second plurality of programming question texts are filtered using a preset filtering algorithm, and the filtered programming question texts are used as the plurality of programming question texts of the plurality of question types.
5. The method according to any one of claims 2 to 4, characterized in that Generating a training sample set based on the mixed data set includes: Converting the plurality of pure code data and the plurality of text code data in the mixed data set into corresponding plurality of pure code word unit sequences and plurality of text code word unit sequences respectively; Compacting the plurality of pure code word sequences according to a preset sample length to obtain a plurality of pure code data-based samples each having the sample length; According to the sample length, the plurality of text code word sequences are compacted and filled with words to obtain a plurality of samples based on the text code data, each having the sample length; The training sample set is constructed using the plurality of samples based on pure code data and the plurality of samples based on text code data.
6. The method according to any one of claims 1 to 4, characterized in that The screening conditions include at least one of the following conditions: The average length of all lines of the code snippet is within a preset length range, the number of lines in the code snippet does not exceed a preset line number threshold, the recognition of the code snippet is not lower than a preset recognition threshold, and the ratio of valid characters in the code snippet is not lower than a preset valid character ratio threshold. The recognition degree of the code snippet is indicated by the frequency of the code snippet being marked by multiple users, and the valid characters in the code snippet do not include blank characters and any characters in comments.
7. The method according to claim 6, characterized in that The screening condition also includes that the readability score of the code snippet evaluated according to a preset scoring standard does not exceed a preset readability score threshold, and the readability score is evaluated according to a preset readability score rule.
8. A device for training a code generation model, comprising a memory, a processor, and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 7.
9. A non-volatile computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer program product comprising a computer program, or a non-volatile computer-readable storage medium carrying a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.