Code construction method, model fine-tuning method, and device and storage medium

By automatically generating the code candidate text of the programming language by generating the model, and using the code text of the original programming language for verification, the problem of insufficient programming language training data is solved, and the code construction efficiency and model training effect are improved.

WO2025092404A1PCT designated stage expired Publication Date: 2025-05-08ALIBABA (CHINA) CO LTD

Patent Information

Application Number
PCT/CN2024/124560
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-10-30
Filing Date
2024-10-12
Publication Date
2025-05-08

AI Technical Summary

Technical Problem

In the prior art, some programming languages ​​have insufficient training data, resulting in poor model training effects, and manual development of training data is time-consuming and labor-intensive and inefficient.

Method used

By generating the model, it will automatically generate code candidate text for zero-resource/low-resource programming languages, and use the code text of the original programming language to verify it, expand the training data of the target programming language, thereby iterating the training of the big model and improving its code generation ability.

Benefits of technology

It effectively improves the efficiency and accuracy of building code, improves the overall effect of model training, enhances the processing ability of large models for low-resource programming languages, and reduces the burden on developers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024124560_08052025_PF_FP_ABST
    Figure CN2024124560_08052025_PF_FP_ABST
Patent Text Reader

Abstract

Provided in the present disclosure are a code construction method, a model fine-tuning method, and a device and a storage medium. The code construction method comprises: acquiring requirement information and source code text, which is implemented on the basis of a source programming language and corresponds to the requirement information; on the basis of the requirement information, obtaining at least one piece of corresponding candidate code text by means of a generation model, wherein the at least one piece of candidate code text is implemented on the basis of a target programming language; and checking the at least one piece of candidate code text on the basis of the source code text, so as to obtain target code text, which is implemented on the basis of the target programming language and corresponds to the requirement information. By means of the present disclosure, code text corresponding to a target programming language can be effectively expanded, thereby improving the efficiency and accuracy of the construction of the code text, and then fine-tuning training can be performed on a model on the basis of constructed code text, thereby improving the processing capability of the model for the target programming language, and also improving the training effect of the model.
Need to check novelty before this filing date? Find Prior Art

Description

Code construction method, model fine-tuning method, equipment and storage medium

[0001] This disclosure claims priority to the Chinese patent application filed with the China Patent Office on October 30, 2023, with application number 202311427814.9 and application name “Code construction method, model fine-tuning method, device and storage medium”, the entire contents of which are incorporated by reference in this disclosure. Technical Field

[0002] The present disclosure relates to artificial intelligence technology, and in particular to a code construction method, a model fine-tuning method, a device, and a storage medium. Background Art

[0003] With the continuous development of computer technology, the demand for software development is also increasing. In order to assist in software development, large models can be used for code generation to improve the overall efficiency of development.

[0004] Before generating code from a large model, the large model can be trained based on training data. In the prior art, there are many programming languages, such as C, C++, Java, and Python. When training a large model for a particular programming language, it is often necessary to first obtain code examples for that programming language before completing the training of the large model.

[0005] However, some programming languages ​​currently have insufficient training data, resulting in poor model training results.

[0006] Summary of the Invention

[0007] The present disclosure provides a code construction method, a model fine-tuning method, a device, and a storage medium to improve the efficiency and accuracy of code construction, thereby improving the overall effect of model training.

[0008] In a first aspect, an embodiment of the present disclosure provides a code construction method, comprising:

[0009] Obtaining requirement information and original code text corresponding to the requirement information implemented in an original programming language;

[0010] According to the requirement information, obtaining at least one corresponding candidate code text by generating a model, wherein the at least one candidate code text is implemented based on a target programming language;

[0011] The at least one candidate code text is verified according to the original code text to obtain a target code text implemented based on the target programming language and corresponding to the requirement information.

[0012] In a second aspect, embodiments of the present disclosure provide a model fine-tuning method for fine-tuning a target model for at least one round, wherein the process of any round of fine-tuning includes:

[0013] Obtaining demand information and corresponding target code text, wherein the target code text is obtained based on the method described in the first aspect;

[0014] The target model is trained according to the requirement information and the corresponding target code text.

[0015] In a third aspect, an embodiment of the present disclosure provides a code generation method, including:

[0016] Obtain pending demand information;

[0017] Inputting the demand information into the target model to obtain a code text corresponding to the demand information;

[0018] Outputting the code text;

[0019] Wherein, the target model is obtained by training through the method described in the second aspect.

[0020] In a fourth aspect, an embodiment of the present disclosure provides an electronic device, including:

[0021] at least one processor; and

[0022] a memory communicatively coupled to the at least one processor;

[0023] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the electronic device to execute the method described in any one of the above aspects.

[0024] In a fifth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the method described in any one of the above aspects is implemented.

[0025] In a sixth aspect, an embodiment of the present disclosure provides a computer program product, comprising a computer program, which implements the method described in any of the above aspects when executed by a processor.

[0026] The code construction method, model fine-tuning method, device, and storage medium provided by the embodiments of the present disclosure can obtain requirement information and original code text corresponding to the requirement information implemented in the original programming language, and obtain at least one corresponding candidate code text based on the requirement information through a generation model. The at least one candidate code text is implemented based on the target programming language, and the at least one candidate code text is verified based on the original code text to obtain a target code text corresponding to the requirement information implemented in the target programming language. The embodiments of the present disclosure can automatically generate candidate code texts using the generation model, thereby improving the efficiency of constructing code texts, and verify the target programming language in combination with the original programming language to improve the accuracy of the obtained code text, thereby effectively expanding the code text corresponding to the target programming language. The generation model or other models can then be fine-tuned based on the constructed code text, thereby improving the model's processing capabilities for the target programming language and enhancing the model's training effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0028] FIG1 is a schematic diagram of an application scenario provided by an embodiment of the present disclosure;

[0029] FIG2 is a schematic diagram of a fine-tuning training provided by an embodiment of the present disclosure;

[0030] FIG3 is a flow chart of a code construction method provided by an embodiment of the present disclosure;

[0031] FIG4 is a schematic diagram of generating candidate code texts provided by an embodiment of the present disclosure;

[0032] FIG5 is a schematic diagram of a verification method provided by an embodiment of the present disclosure;

[0033] FIG6 is a schematic diagram of another verification method provided by an embodiment of the present disclosure;

[0034] FIG7 is a schematic diagram of a flow chart of a model fine-tuning method provided by an embodiment of the present disclosure;

[0035] FIG8 is a schematic diagram of training according to text length provided by an embodiment of the present disclosure;

[0036] FIG9 is a schematic diagram of a flow chart of a code generation method provided by an embodiment of the present disclosure;

[0037] FIG10 is a schematic structural diagram of an electronic device provided in an embodiment of the present disclosure.

[0038] The above drawings illustrate specific embodiments of the present disclosure, which will be described in more detail below. These drawings and textual descriptions are not intended to limit the scope of the present disclosure in any way, but rather to illustrate the concepts of the present disclosure to those skilled in the art by reference to specific embodiments. DETAILED DESCRIPTION

[0039] Exemplary embodiments are described in detail herein, with examples illustrated in the accompanying drawings. When the following description refers to the drawings, identical numerals in different drawings represent identical or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present disclosure.

[0040] It should be noted that the user information (including but not limited to user device information, user attribute information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards, and corresponding operation entrances must be provided for users to choose to authorize or refuse.

[0041] The disclosed embodiments can be implemented through a large model, for example, a large language model. Among them, a large language model refers to a deep learning language model with large-scale language model parameters, which usually contains hundreds of millions, tens of billions, hundreds of billions, trillions or even more than ten trillion language model parameters. The large language model can also be called a cornerstone language model / foundation model (Foundation Model). The large language model is pre-trained through large-scale unlabeled corpus to produce a pre-trained language model with more than 100 million parameters. This language model can adapt to a wide range of downstream tasks, and the language model has good generalization ability, such as a large-scale language model (LLM), a multi-modal pre-training language model, etc.

[0042] In practical applications, large language models only require a small number of samples to fine-tune the pre-trained language model and can be applied to different tasks. Large language models can be widely used in natural language processing (NLP), computer vision and other fields. Specifically, they can be applied to computer vision tasks such as visual question answering (VQA), image caption (IC), and image generation, as well as natural language processing tasks such as text-based sentiment classification, text summary generation, and machine translation. The main application scenarios of large language models include digital assistants, intelligent robots, search, online education, office software, e-commerce, and intelligent design.

[0043] First, the terms involved in this disclosure are explained:

[0044] Programming language: It is a formal language used to define computer programs. It is a standardized communication skill that can be used to achieve communication between humans and machines.

[0045] Zero / few-shot learning: Zero-shot learning is generally understood as using dataset A to train a model. The trained model can then process (e.g., classify) dataset B, but the labels (e.g., categories) corresponding to dataset A and dataset B are completely different, or only slightly identical. In the present disclosure, this specifically refers to the ability to generate code text even if the model hasn't encountered certain requirements during training.

[0046] The application scenarios of the present disclosure are first described below.

[0047] In the field of programming, big models can be used to implement functions such as code generation and code modification. For example, by inputting requirement information into the big model, utilizing the characteristics of the big model and combining it with the grammatical rules and constraints of the program code, code snippets or complete codes that meet the requirements can be automatically generated.

[0048] To equip large models with the necessary coding capabilities, they can be trained based on training data. However, the current programming field involves a wide range of programming languages. Existing training datasets for programming code suffer from an imbalance in the amount of training data available for each language. Commonly used languages ​​have more training data, while less common languages ​​have less or no training data at all. This results in poor performance of large models for less common languages. Manually developing training data is time-consuming, labor-intensive, and inefficient.

[0049] In order to solve this problem, the present invention uses a generative model to heuristically generate code corresponding to zero-resource / low-resource programming languages, thereby enhancing the code of zero-resource / low-resource programming languages, and iteratively trains large models to enhance the code generation capabilities of large models.

[0050] Specifically, for a low-resource programming language that you want to enhance, you can use a generative model to generate multiple candidate codes corresponding to the programming language, and use code samples of another programming language that already exist in the training dataset to verify the generated candidate codes. If the verification passes, the candidate code is considered correct and can be added to the training dataset and used to train the large model to enhance the large model's processing capabilities for low-resource programming languages.

[0051] Optionally, the generative model used to construct the training data and the large model used for iterative training based on the training data can be the same model or different models. The following explanation takes the two as the same model as an example, that is, the training data is obtained using a large model with certain generative capabilities, and the training data is used to further train the large model.

[0052] Figure 1 is a schematic diagram of an application scenario provided by an embodiment of the present disclosure. As shown in Figure 1 , assuming Python is a low-resource programming language and C++ is a programming language with abundant training data, the C++ training data can be used to assist in generating Python training data, and the generated Python training data can be used to train the large model. The training data can include requirement information and corresponding code.

[0053] During the generation process, we first obtain the requirement information and corresponding C++ code from the C++ training dataset. For example, the requirement information can be: "Given a string s, please find the length of the longest substring that does not contain repeated characters." Then, we use the large model to generate n candidate Python implementation codes.

[0054] Each of the n generated candidate codes is verified using C++ code. The Python interpreter and C++ compiler can process the Python and C++ codes, assisting in the verification process. If the verification passes, the candidate code is added to the Python training dataset. For example, if the candidate code with ID 2 in Figure 1 passes verification, while the other candidate codes in the same batch fail verification, then the candidate code with ID 2 can be added to the Python training dataset.

[0055] After generating a certain amount of Python training data in this way, the training process begins. During the training process, the Python training data can be used to fine-tune the large model, thereby obtaining a large model with high-quality Python code generation capabilities.

[0056] Figure 2 is a schematic diagram of a fine-tuning training provided by an embodiment of the present disclosure. As shown in Figure 2, the initial capabilities of the large model can be used to generate a certain amount of target code text (such as Python code), and then the generated Python code can be used to fine-tune the large model. Then, the fine-tuned large model can be used to regenerate a certain amount of Python code, and the regenerated Python code can be used to continue fine-tuning the large model. This cycle is repeated until the large model meets the requirements, thereby automatically generating training data and fine-tuning based on the capabilities of the large model itself, achieving training under zero or low resources.

[0057] The disclosed embodiments address the imbalance of programming languages ​​in existing programming code training datasets and the scarcity of some programming languages. By leveraging the large model's zero / few-shot generation and diversified text generation capabilities, and combining it with other programming languages ​​to verify the target programming language, the disclosed embodiments can effectively expand the training data for the target programming language. Furthermore, the large model can be fine-tuned based on the training data for the target programming language, improving the large model's processing capabilities for the target programming language and enhancing the model's training effectiveness. The disclosed embodiments have high practical application value in terms of improving development efficiency, reducing the burden on developers, and reducing code error rates.

[0058] Some embodiments of the present disclosure are described in detail below with reference to the accompanying drawings. The following embodiments and features thereof may be combined with one another unless they conflict with each other. Furthermore, the sequence of steps in the following method embodiments is provided for illustrative purposes only and is not intended to be a strict limitation.

[0059] FIG3 is a flow chart of a code construction method provided by an embodiment of the present disclosure. The method in this embodiment can be implemented on any device with data processing capabilities, for example, on the cloud, locally deployed, on a client, or on an IOT (Internet of Things) device. As shown in FIG3 , the method may include:

[0060] Step 301: Obtain requirement information and original code text corresponding to the requirement information implemented in an original programming language.

[0061] Among them, the demand information can be used to represent the programming problem to be processed. The form of the demand information is not limited. It can be a text description of the programming problem to be processed, or it can be information in other modalities, for example, information in any one of the modalities of pictures, audio, and video, or it can be a combination of multiple modal information, such as a combination of pictures and text.

[0062] The original code text is a code text corresponding to the requirement information, and the original programming language is a programming language adopted by the original code text, such as C++.

[0063] Optionally, the requirement information and original code text can be obtained from an existing code library, wherein the existing code library can be used as a training data set. In the embodiment of the present disclosure, the training data can include the requirement information and the corresponding code text, which is used to train the generation model or other models so that the model can obtain the corresponding code text based on the requirement information. Alternatively, the requirement information and original code text can be input by the user or obtained from other devices. The original code text can be used as the correct code text to verify the candidate code text generated subsequently.

[0064] Step 302: According to the requirement information, obtain at least one corresponding candidate code text by generating a model, where the at least one candidate code text is implemented based on a target programming language.

[0065] The generative model may be any model capable of generating code, for example, a large model, or a small model may be pre-trained as the generative model, wherein the small model is any model with fewer parameters than the large model.

[0066] By inputting the requirement information into the generation model, candidate code texts corresponding to the generation model can be obtained. The candidate code texts are implemented based on the target programming language, which is the programming language to be enhanced.

[0067] For example, if Python has less training data, but C++ has more, then C++ can be used as the source language and Python as the target language, leveraging C++'s rich resources to enhance Python's training resources. Of course, the choice of source and target languages ​​is not limited to this. Even if a language has less training data, it can still be used as the source language to enhance the training data of other languages.

[0068] Optionally, obtaining at least one corresponding candidate code text through a generation model based on the requirement information may include: inputting the requirement information and prompt information into the generation model to obtain at least one corresponding candidate code text; wherein the prompt information is used to prompt the generation model to implement the candidate code text based on the target programming language.

[0069] For example, the requirement may be: "Given a string s, find the length of the longest substring that does not contain repeated characters." The prompt may include: "Please use Python to complete the following problem:." The input to the generation model may include: "Please use Python to complete the following problem: Given a string s, find the length of the longest substring that does not contain repeated characters."

[0070] Optionally, the generation model is a pre-trained model, and the training data used for pre-training may include training data corresponding to one or more programming languages.

[0071] In an optional implementation, the training data used for pre-training may include: training data corresponding to the original programming language and training data corresponding to the target programming language. In this step, the generation model is directly prompted to implement the candidate code text based on the target programming language.

[0072] In another optional implementation, the training data used for pre-training does not include training data corresponding to the target programming language; in addition to prompting the generation model to implement the candidate code text based on the target programming language, the prompt information may also include: grammatical rules corresponding to the target programming language.

[0073] Through the above scheme, the target programming language can be used or not during pre-training. If the target programming language is used, the generation model is directly prompted to generate candidate code text corresponding to the target programming language, thereby improving processing efficiency. If the target programming language is not used during pre-training, the grammatical rules of the target programming language can be added to the prompt information, thereby improving the generation ability of the generation model in programming languages ​​that have not been seen before.

[0074] In other optional implementations, even if the target programming language is used during pre-training, the grammatical rules of the target programming language can still be added to the prompt information when generating candidate code text using the generative model to ensure generation quality. In addition, the generative model can also be pre-trained in programming languages ​​other than the target programming language and the original programming language, which is not limited in the embodiments of the present disclosure.

[0075] Optionally, the grammatical rules corresponding to the target programming language may be rules that need to be followed when generating code corresponding to the target programming language. Different programming languages ​​may have different grammatical rules.

[0076] For example, the grammar rules may include: a statement must end with a certain symbol, a variable name must meet certain requirements, etc.

[0077] Alternatively, to improve the generation of candidate code texts, grammar rules can be used to indicate how one or more specific functions are implemented in the target programming language, for example, how the print function is implemented in the target programming language.

[0078] Optionally, before inputting the requirement information and prompt information into the generation model to obtain at least one corresponding candidate code text, the method may further include:

[0079] Determining the grammatical rule according to at least one function corresponding to the requirement information and / or at least one original sentence contained in the original code text;

[0080] The grammatical rules are used to indicate: statements corresponding to the at least one function and / or statements corresponding to the at least one original statement in the target programming language.

[0081] In one example, a grammar rule to be presented to a generation model can be determined based on at least one function corresponding to the requirement information. The at least one function can be directly extracted from the requirement information through keyword matching, or the requirement information can be input into the generation model to determine the at least one function corresponding to the requirement information. After determining the at least one corresponding function, the implementation method of the relevant function can be determined based on the grammar library of the target programming language as the corresponding grammar rule.

[0082] In another example, the grammar rules can be determined based on at least one original statement contained in the original code text. Taking the original programming language as C++ and the target programming language as Python as an example, assuming that according to the grammar rules of C++, a certain original statement contained in the original code text is determined to be used to implement the print function, then the corresponding candidate code text should also implement the print function. Therefore, the grammar rules prompted to the generation model can include the implementation method of the print function in Python.

[0083] In another example, the requirements information and the original code text can be used to jointly determine the functions that may be used in the candidate code text, and the corresponding grammatical rules can be prompted to the generation model. If there are duplicate functions determined by the requirements information and the original code text, the duplicate functions can be removed first, and then the grammatical rules corresponding to the removed functions can be prompted, thereby achieving more comprehensive and accurate prompts.

[0084] Since the target programming language may have more functions and corresponding grammatical rules are also relatively rich, if the grammatical rules corresponding to all functions are input into the generation model as prompt information, the input will be too large and the generation effect will be poor. By analyzing the requirement information and the original code text, and prompting the grammatical rules of the relevant functions to the generation model, the accuracy of the prompts can be improved.

[0085] In addition, the hint information may also include other information that helps the generation model generate correct code, such as constraints: certain algorithms, strategies, etc. need to be used to implement the candidate code text.

[0086] In the embodiments of the present disclosure, prompt information can be obtained in a variety of ways.

[0087] In an optional implementation, a template may be pre-set, and prompt information may be determined based on the template. For example, the template may include functions to be filled in, grammatical rules, etc. The template may be filled in according to the requirement information and the original code text to obtain prompt information.

[0088] In another optional implementation, the prompt information can be obtained by generating a model. When the prompt information does not contain grammatical rules, a prompt instruction can be directly input into the generation model, and the prompt instruction is used to instruct the generation model to generate one or more prompt information.

[0089] When the prompt information includes a grammatical rule, determining the grammatical rule according to at least one function corresponding to the requirement information and / or at least one original sentence included in the original code text may include:

[0090] Inputting the requirement information, at least one of the original code text, and a prompt instruction into a generation model to obtain prompt information containing grammatical rules;

[0091] The prompt instruction is used to instruct the generation model to determine the corresponding grammatical rules according to the requirement information and / or the original code text, and obtain prompt information according to the grammatical rules.

[0092] Exemplarily, the prompt instruction may include: "Please generate prompt information according to the requirement information. The prompt information is used to prompt the model to generate Python code according to the requirement information. The prompt information needs to include grammatical rules corresponding to relevant functions in the requirement information."

[0093] Figure 4 is a schematic diagram of a method for generating candidate code text according to an embodiment of the present disclosure. As shown in Figure 4, the requirement information, at least one of the original code text (C++ code), and a prompt instruction can be input into the generation model to obtain the prompt information. The prompt information and the requirement information can then be input into the generation model to obtain the candidate code text (Python code).

[0094] Optionally, when generating Python code, the requirement information, C++ code, and prompt information can also be input into the generation model together. The prompt information can be used to prompt the generation model to obtain Python code based on the requirement information, and provide the corresponding C++ code as a reference, so that the generation model can generate Python code with reference to the grammatical rules of C++ code and Python.

[0095] Through the above method, prompt information can be generated based on the generation model, and then the prompt information and requirement information can be input into the generation model to obtain the corresponding candidate code text, thereby improving the accuracy and diversity of the prompt information and thus improving the generation effect of the candidate code text.

[0096] In other optional implementations, the prompt information can also be pre-set. For example, one or more prompt information can be pre-set. When generating candidate code texts, one of the prompt information can be spliced ​​with the required information and input into the generation model to obtain a candidate code text. Multiple prompt information can be used to obtain multiple candidate code texts. In addition, due to the random sampling of the generation model during the generation process, multiple different candidate code texts can be obtained by inputting the same information into the generation model multiple times.

[0097] Step 303: Verify the at least one candidate code text according to the original code text to obtain a target code text implemented in a target programming language and corresponding to the requirement information.

[0098] Through the above steps, at least one candidate code text can be heuristically generated based on the generation capability of the generation model. In this step, the at least one candidate code text can be verified using the original code text.

[0099] Alternatively, the target code text may be determined by a candidate code text that has passed verification, that is, the target code text may be determined based on the candidate code text that has passed verification. For example, for any candidate code text, if the candidate code text passes verification, it may be used as the target code text, and the target code text and the corresponding requirement information may be added to the target code library. Alternatively, if the candidate code text passes verification, the candidate code text may be displayed to the user, who may modify or confirm the candidate code text before adding it to the target code library.

[0100] The target code text in the target code library can be used to train generative models or other models, and can also have other uses. For example, the target code library can be opened to users, allowing users to search for corresponding codes based on their requirements, providing convenience for users.

[0101] In an optional implementation, verifying the at least one candidate code text according to the original code text may include:

[0102] Obtaining a test case, and processing the test case according to the original code text and the at least one candidate code text to obtain a corresponding test result;

[0103] For any candidate code text, whether the candidate code text passes verification is determined based on the test result corresponding to the candidate code text and the test result corresponding to the original code text.

[0104] Processing the test case based on the original code text and the at least one candidate code text can be considered as a process of testing the original code text and the candidate code text using the test case. Testing the code using the test case can determine whether the code runs normally.

[0105] For example, the requirement information is: "Given a string s, please find the length of the longest substring that does not contain repeated characters." The corresponding test case can contain the string s, for example, s = "abcc". By processing the test case using the original code text, the corresponding test result can be obtained. Since the length of the longest substring that does not contain repeated characters in the string "abcc" is 3, the test result corresponding to the original code text is 3.

[0106] FIG5 is a schematic diagram of a verification method provided by an embodiment of the present disclosure. As shown in FIG5, for any one of at least one candidate code text, the test case is processed using the candidate code text, and the obtained test result is compared with the test result corresponding to the original code text. If the two are the same, the test result corresponding to the candidate code text is considered correct; otherwise, it is considered incorrect.

[0107] Specifically, the original code text or the candidate code text may be converted into a machine language using a compiler, and then the obtained machine language may be run to process the test case to obtain the final test result.

[0108] When the number of test cases is one, for any candidate code text, if the corresponding test result is correct, the candidate code text passes the verification; otherwise, the verification fails.

[0109] When there are multiple test cases, it can be determined whether the candidate code text has passed verification based on the number of test cases with correct results.

[0110] Optionally, determining whether the candidate code text passes verification based on a test result corresponding to the candidate code text and a test result corresponding to the original code text includes:

[0111] Determining a pass rate corresponding to the candidate code text, wherein the pass rate is determined by the number of test cases that are successfully matched among the multiple test cases and the number of the multiple test cases;

[0112] If the pass rate meets the requirement, it is determined that the candidate code text verification has passed;

[0113] Among them, for any test case, if the test result obtained after the original code text processes the test case is the same as the test result obtained after the candidate code text processes the test case, then the test case is a successfully matched test case, that is, a test case with a correct result.

[0114] For any test case, if the test result obtained after the original code text is processed on the test case is different from the test result obtained after the candidate code text is processed on the test case, the test case is recorded as an unsuccessful match test case, that is, a test case with an incorrect result.

[0115] Assume there are m test cases. For any candidate code text, use the candidate code text to process the i-th test case among the m test cases. The resulting test result is compared with the test result obtained after processing the i-th test case with the original code text. If they are consistent, the i-th test case is recorded as a successfully matched test case. A similar method can be used for other test cases. If the number of successfully matched test cases among the m test cases is k, then the pass rate corresponding to the candidate code text is k / m.

[0116] Optionally, the pass rate may be calculated for candidate code texts that have at least one successful test case; and the pass rate calculation may be omitted for candidate code texts that do not have any successful test case.

[0117] After obtaining the pass rate, it is possible to determine whether the candidate code text has passed the verification based on the pass rate. Optionally, if the pass rate meets the requirements, determining that the candidate code text has passed the verification includes:

[0118] If the pass rate corresponding to the candidate code text is greater than the pass rate threshold, it is determined that the candidate code text has passed the verification;

[0119] Among them, the target code text obtained after verification is used to perform multiple rounds of iterative fine-tuning on the generation model. During the multiple rounds of iteration, the rounds are positively correlated with the pass rate threshold.

[0120] Optionally, the code construction method in this embodiment can be used to obtain the target code text based on the generation model, and then the target code text can be used to fine-tune the generation model, and then the fine-tuned generation model can be used to continue to obtain the target code text, thereby achieving fine-tuning training of the generation model through multiple rounds of iterations.

[0121] Among them, in the process of multiple rounds of iterations, the pass rate threshold can be gradually increased, that is, the round and the pass rate threshold are positively correlated. The larger the round, the larger the pass rate threshold, and the smaller the round, the smaller the pass rate threshold.

[0122] For example, when the number of rounds is 1, the pass rate threshold can be 40%. That is, when generating the target code text corresponding to the first round of fine-tuning, the pass rate threshold is 40%. The pass rate thresholds corresponding to the second and third rounds can be 50% and 60%, respectively, and so on. As the number of fine-tuning rounds increases, the pass rate threshold gradually increases.

[0123] In practical applications, the pre-trained generative model has a certain level of code generation capability. However, its initial code generation capability is weak, resulting in a low pass rate for the generated candidate code texts. From this, a subset of candidate code texts with higher pass rates can be selected as target code texts. While the quality of these target code texts may not be high enough, they are already better than the current generation capability of the generative model (better than the average quality of the code currently generated by the generative model). Therefore, these target code texts can be used to fine-tune the generative model. After fine-tuning, the generation capability of the generative model improves. At this point, the pass rate threshold can be increased to improve the quality of the subsequent target code texts, thereby gradually improving the performance of the generative model through multiple rounds of iteration.

[0124] In addition to the pass rate threshold, candidate code texts can also be screened using other methods. For example, if the pass rate meets the requirement, determining that the candidate code text has passed verification can include: if the pass rate corresponding to the candidate code text is in the top X or top 1 / Y of the pass rates corresponding to at least one candidate code text, then determining that the candidate code text has passed verification. The values ​​of X and Y can be set according to actual needs.

[0125] This approach leverages the runnable nature of code to validate candidate code texts using test cases, improving verification accuracy. Furthermore, when there are multiple test cases for a requirement, verification can be determined based on the test results of these multiple test cases, further improving verification accuracy.

[0126] In another optional implementation, verifying the at least one candidate code text according to the original code text may include:

[0127] Compiling the original code text and the at least one candidate code text respectively to obtain a first machine language text corresponding to the original code text and a second machine language text corresponding to each candidate code text;

[0128] For any candidate code text, if the second machine language text corresponding to the candidate code text is consistent with the first machine language text, it is determined that the candidate code text has passed the verification.

[0129] Figure 6 is a schematic diagram of another verification method provided by an embodiment of the present disclosure. As shown in Figure 6, the original code text (such as C++ code) and the candidate code text (such as Python code) can be compiled separately by a compiler. After compilation, a first machine language corresponding to the original code text and a second machine language text corresponding to the candidate code text can be obtained. If the first machine language text and the second machine language text are consistent, it means that the processing logic and specific process of the original code text and the candidate code text are the same. On the basis that the original code text is correct, the candidate code text should also be correct. At this time, it can be directly determined that the candidate code text has passed the verification.

[0130] In some cases, the candidate code text may still be correct even though the compiled machine language is inconsistent. If the first machine language is inconsistent and the second machine language text is inconsistent, it can be considered a verification failure. Although some correct candidate code text is lost, it can ensure that the code text added to the target code library is correct.

[0131] Optionally, to improve the generation effect, the first machine language text and the second machine language text can be compared. If they are consistent, the verification passes and the candidate code text is directly added to the target code library. If they are inconsistent, the candidate code text can be further verified using test cases using the aforementioned method, thus achieving a balance between efficiency and accuracy.

[0132] Through the above method, the compilable feature of the code can be used to verify the candidate code text, effectively improving the verification effect, reducing the use of test cases, improving the efficiency of verification, and thus improving the overall effect of obtaining the target code text through the generation model.

[0133] The code construction method provided in this embodiment can obtain requirement information and original code text corresponding to the requirement information implemented based on the original programming language. According to the requirement information, at least one corresponding candidate code text is obtained through a generation model. The at least one candidate code text is implemented based on the target programming language, and the at least one candidate code text is verified based on the original code text to obtain a target code text corresponding to the requirement information implemented based on the target programming language. Therefore, the generation model can be used to automatically generate candidate code texts, thereby improving the efficiency of constructing code texts. The target programming language can be verified in combination with the original programming language to improve the accuracy of the obtained code text, thereby effectively expanding the code text corresponding to the target programming language. Furthermore, the generation model or other models can be fine-tuned based on the constructed code text to improve the model's processing capabilities for the target programming language and enhance the model's training effect.

[0134] In actual applications, many programming languages ​​come with some built-in modules for user convenience. In the disclosed embodiment, the user is also allowed to select the modules they wish to enhance, and the target code text is constructed in a targeted manner based on the modules they wish to enhance. Optionally, the acquisition of the requirement information in step 301 and the original code text corresponding to the requirement information implemented in the original programming language may include:

[0135] Obtaining a module to be enhanced for the target programming language input by a user through an interactive interface;

[0136] Determining a module in the original programming language that matches the module to be enhanced;

[0137] Obtaining the original code text and corresponding requirement information of the matching module;

[0138] The prompt information is also used to prompt the generation model to use the module to be enhanced when generating candidate code text.

[0139] A module can refer to a code file in a programming language that implements a specific function or provides a specific service. Optionally, the user can directly enter the name of the module or the name of a package or library. A package or library can contain one or more modules, thereby enhancing the package or library.

[0140] For the module to be enhanced, a search is performed in the original programming language for modules with the same or similar functions as the module to be enhanced, and these modules are used as matching modules. The matching relationship between modules can be pre-set or input by the user. From the original code library corresponding to the original programming language, the original code text and corresponding requirement information that use the matching module are selected for subsequent construction of the target code text corresponding to the target programming language, thereby obtaining more code that uses the module to be enhanced.

[0141] In order to improve the accuracy of generation, the module to be enhanced may be indicated in the prompt information, so that the generation model generates candidate code texts according to the module to be enhanced.

[0142] For example, Python is a relatively mature language, but there may still be a situation in the target code library where there is less code text using a certain Python package. In order to enhance the generation model's ability to process the package, you can focus on enhancing the package. After the user selects the package as the module to be enhanced, you can search for modules in C++ that match this package, and use the relevant original code text (C++ code text) and requirement information to construct the Python target code text. When generating candidate code text for Python through the generation model, you can prompt the generation model to use the above-mentioned package in Python.

[0143] In this way, the above-mentioned package to be enhanced will be used in the target code text, so as to more accurately generate the target code text for the specific module, facilitate the enhancement of the processing ability of the generation model for the relevant modules, meet the actual development needs of users, and improve the user experience.

[0144] The module to be enhanced is indicated in the prompt information, and the original code text and requirement information are determined according to the module to be enhanced. They can be used simultaneously or one of them can be used selectively.

[0145] In one or more embodiments of the present disclosure, optionally, at least one of the following interaction modes may be performed:

[0146] In an optional interactive mode, the requirement information and the target code text are displayed through an interactive interface, so that the user can modify or confirm the target code text according to the requirement information, and add the modified or confirmed target code text to the target code library.

[0147] Optionally, the modified or confirmed target code text and requirement information can be added to the target code library together so that the target code text can be searched based on the requirement information, or the requirement information and target code text can be extracted from the target code library as training data to train the generative model or other models.

[0148] Optionally, the at least one candidate code text may be displayed through an interactive interface, so that the user can modify or filter the at least one candidate code text and verify the modified or filtered candidate code text.

[0149] Optionally, the candidate code text that has passed the verification can also be displayed through the interactive interface, so that the user can modify or confirm the candidate code text that has passed the verification, and use the modified or confirmed candidate code text as the target code text.

[0150] In another optional interaction mode, the requirement information may be displayed through an interactive interface, so that the user can input corresponding test cases according to the requirement information.

[0151] The user may input one or more test cases, and use the one or more test cases to verify the candidate code text.

[0152] In yet another optional interaction manner, a plurality of candidate programming languages ​​may be displayed through an interactive interface, so that the user can select at least one original programming language and / or at least one target programming language based on the plurality of candidate programming languages.

[0153] Optionally, the original programming language selected by the user can be one or more. When there are multiple original programming languages, the target code text can be jointly constructed based on the original code texts corresponding to the multiple original programming languages. For example, the original programming languages ​​can include C++ and JAVA. C++ has 1,000 pairs of original code texts and requirement information, and Java has 500 pairs of original code texts and requirement information. Therefore, there are a total of 1,500 pairs of original code texts and requirement information, which can be used to construct the target code text of Python.

[0154] Optionally, the target programming language selected by the user may be one or more. When there are multiple target programming languages, corresponding candidate code texts may be generated for each of them, and the candidate code texts may be verified based on the original code text to obtain the target code text.

[0155] In the embodiments of the present disclosure, the target programming language and the original programming language may be different programming languages ​​or the same programming language. For example, new Python code may be generated based on existing high-quality Python code.

[0156] In addition to the above-mentioned interaction methods, during the process of constructing the target code text, the output of each step can be displayed to the user for easy modification and confirmation. The input of each step can also be selected by the user.

[0157] This solution allows users to modify or confirm the target code text and candidate code text during the code construction process, improving the accuracy of the final target code text. It also allows users to input test cases based on their requirements, thereby improving the accuracy of the test cases and their compatibility with the candidate code text, which helps improve the accuracy of the target code text. Users can also select the target programming language or the original programming language to meet the actual usage needs of different scenarios and further enhance the user experience.

[0158] Based on the code construction method provided in the above embodiment, the present disclosure also provides a model fine-tuning method. Figure 7 is a flow chart of a model fine-tuning method provided in the present disclosure. As shown in Figure 7, the model fine-tuning method can be used to fine-tune the target model for at least one round. The process of any round of fine-tuning includes:

[0159] Step 701: Obtain requirement information and corresponding target code text.

[0160] The target code text is obtained based on the method described in any of the aforementioned embodiments.

[0161] Optionally, the number of required information or target code texts obtained in this step may be multiple. The method in this embodiment may be executed after a certain number of target code texts are obtained through the method of the above embodiment.

[0162] Step 702: Train the target model according to the requirement information and the corresponding target code text.

[0163] The target model may be the above-mentioned generative model or other models. In terms of the form of the model, the target model may be a large language model or other forms of models.

[0164] Optionally, the acquired requirement information and target code text can be used as training data, wherein the requirement information is used as the input of the target model, and the target code text is used as the training label. The target model is trained using technologies such as SFT (Supervised fine-tuning), so that the trained target model can output the corresponding code text according to the requirement information.

[0165] After the model is trained based on the current requirements and target code, the next iteration begins. The model is retrained using the aforementioned code construction method to generate multiple target code texts. The target model is then fine-tuned based on the newly generated target code texts. After multiple iterations, a high-quality target model capable of handling the target programming language can be obtained.

[0166] Optionally, after each round of training is completed, the accuracy of the code text output by the target model can be determined. If the accuracy meets the preset conditions, the fine-tuning can be ended; alternatively, the fine-tuning can be ended after a preset number of rounds.

[0167] The model fine-tuning method provided in this embodiment can use the target code text generated with the assistance of the original code text to fine-tune the target model until the performance of the target model meets expectations, thereby improving the target model's processing capabilities for the target programming language and improving the model's training effect. Furthermore, tasks such as code generation can be implemented based on the target model, reducing the burden on developers, improving development efficiency, and reducing code error rates.

[0168] Optionally, if the target model includes the generation model, during the loop iteration process, a pass rate threshold can be determined based on the current round; wherein the pass rate threshold is used to verify at least one candidate code text obtained by the generation model.

[0169] Specifically, for any candidate code text, if its pass rate for the test case is greater than a pass rate threshold, it is considered to have passed the verification and can be used as the target code text. The pass rate threshold can be increased with the number of iterations, thereby gradually improving the performance of the target model through multiple rounds of iteration.

[0170] Optionally, when multiple target code texts are obtained, one round of fine-tuning may include multiple batches of training processes. During the multiple batches of training processes, techniques such as curriculum learning may be used to improve training performance.

[0171] Optionally, training the target model according to the requirement information and the corresponding target code text may include:

[0172] Determine the text length corresponding to each target code text;

[0173] When training any batch, the corresponding text length is determined according to the current batch, and target code texts that meet the text length are selected from multiple target code texts for training the current batch, wherein there is a positive correlation between the text length of the batch and the target code text.

[0174] Specifically, multiple target code texts can be distinguished by text length, which can be represented by the number of lines or characters in the target code. Based on the text length of the target code text, the target model is trained first using the shorter target text code, and then the target model is trained using the longer target text code.

[0175] Figure 8 is a schematic diagram of a text length-based training method provided by an embodiment of the present disclosure. As shown in Figure 8, a black bar can be used to represent the target code text, and the length of the black bar is used to represent the corresponding text length. A round can include multiple batches, and there can be a positive correlation between the batch and the text length of the target code text. That is, the larger the batch, the longer the text. Thus, by training the target model from easy to difficult, the training effect is improved.

[0176] Optionally, in an embodiment of the present disclosure, the user may be allowed to adjust the training strategy of the target model through an interactive interface, including but not limited to: model input, model output, model structure, model training process, etc.

[0177] For example, in terms of model input, users can adjust the input format and modality, and add, modify, or filter requirement information in the target code library. In terms of model output, users can adjust the output format and modality, and add, modify, or filter labels. In terms of model structure, users can adjust the model's specific structure and parameter count, and add, reduce, or modify one or more modules in the model. In terms of the model training process, users can plan the model's training phases, selecting the training data, loss function, and training stop conditions for each phase.

[0178] Optionally, relevant information to assist the user in making a selection can be displayed on the interactive interface, such as the various available options or the detailed content of each available option. Furthermore, various dynamic information during the model training process can be displayed to the user, such as intermediate results of model training, to facilitate timely updating of training strategies.

[0179] In the embodiments of the present disclosure, by providing users with various interactive interfaces, users are allowed to configure relevant functions used in the training process, which can meet the various actual needs of users, is conducive to improving the overall efficiency and accuracy of model training in specific scenarios, and has strong flexibility and applicability.

[0180] Based on the model fine-tuning method provided in the above embodiment, the present disclosure also provides a code generation method. FIG9 is a flow chart of a code generation method provided in the present disclosure. As shown in FIG9, the code generation method includes:

[0181] Step 901: Obtain demand information to be processed.

[0182] Step 902: Input the requirement information into the target model to obtain the code text corresponding to the requirement information.

[0183] Step 903: Output the code text.

[0184] The target model is obtained by training using the method described in any of the aforementioned embodiments.

[0185] The code generation method provided in this embodiment can generate code using a target model trained with target code text assisted by original code text, effectively improving the accuracy of code generation, reducing the burden on developers, improving development efficiency, and reducing code error rates.

[0186] Optionally, inputting the requirement information into the target model to obtain the code text corresponding to the requirement information may include: inputting the historical code information, language structure information and the requirement information written by the target user into the target model to generate corresponding multiple code texts; wherein, the target user is the target user who inputs the requirement information to be processed.

[0187] Specifically, after obtaining the demand information input by the target user, the demand information can be directly input into the model for code generation, or the historical code information and language structure information written by the target user can be obtained first, wherein the historical code information can be the code written by the target user in the past, and the language structure information can be the language structure in the code written by the target user in the past, or the language structure preferred by the target user, and the historical code information and language structure information are input into the model together with the demand information, prompting the model to understand the target user's preferences and style based on the target user's historical code information and language structure information, and generate multiple code texts corresponding to the demand information based on the target user's preferences and style, and the multiple code texts form a code candidate list.

[0188] After obtaining the code candidate list, the code candidate list can be directly displayed to the target user, or a search box for the code candidate list can be provided to facilitate the target user to search and select.

[0189] Correspondingly, outputting the code text includes: displaying a search box through an interactive interface, obtaining search information input by a target user through the search box; and searching for matching code texts in the generated multiple code texts based on the search information and outputting the matching code texts.

[0190] Specifically, the search information entered by the target user can be a field, statement, or the like in the code. Based on the search information entered by the target user, code text that matches the search information can be searched, for example, code text that contains the search information, or code text that is highly similar to the search information. The retrieved code text is displayed to the target user, making it easier for the target user to find relevant code text based on the search information.

[0191] Optionally, the subsequent code generation capability can be adjusted in real time based on the target user's selection. Specifically, the code text selected by the target user from the matching code texts can be obtained, and the target model is trained based on the code text selected by the target user.

[0192] When the target user selects one or more code texts from multiple code texts, it means that the code text selected by the target user is more in line with the user's expectations. The demand information and the code text selected by the target user can be used as training samples to further train the target model.

[0193] Through the above scheme, when performing code generation, multiple corresponding code texts can be generated based on the target user's historical code information and language structure information, and the target user can be allowed to search and select through the search box, so that the target user can use the generation ability of the model to quickly and conveniently obtain code texts that better meet user needs. In addition, the code text selected by the target user can also be used to further train the target model and improve the subsequent code generation ability of the target model.

[0194] In addition to code generation tasks, the target code text obtained by the embodiments of the present disclosure can also be used for training tasks such as code modification and code filling. For example, after obtaining the target code text, the target code text can be modified or masked, and the modified or masked code text can be used as the input of the target model. The target code text can be used as a training label to train the target model, so that the target model can be used to perform tasks of modifying or filling the code text.

[0195] The disclosed embodiment also provides another code construction method, including: obtaining requirement information; obtaining at least one corresponding candidate code text through a generation model based on the requirement information, wherein the at least one candidate code text is implemented based on a target programming language; verifying the at least one candidate code text to obtain a target code text implemented based on the target programming language and corresponding to the requirement information.

[0196] Optionally, the test cases and the correct test results corresponding to the test cases can be obtained in advance. After generating at least one candidate code text through the generation model, for any candidate code text, the test case can be processed by the candidate code text to obtain the test result, and the test result can be compared with the correct test result. If they are consistent, the test result of the candidate code text for the test case is considered to be correct, otherwise it is incorrect.

[0197] Whether the candidate code text passes verification can be determined based on whether the test result corresponding to the test case is correct.

[0198] When there are multiple test cases, the candidate code text can be determined to have passed verification based on the pass rate. The specific principles are similar to those of the aforementioned embodiment, except that the comparison object for the candidate code text test results is replaced with the aforementioned correct test results instead of the test results of the original code text. The implementation principles of the other steps in this embodiment can also be referred to in the aforementioned embodiment and will not be repeated here.

[0199] In this way, the generated candidate code text can be verified without using the original code text to obtain the target code text that meets the requirements, thereby improving the performance of the target model in zero-resource or low-resource situations.

[0200] Corresponding to the above method, on one hand, an embodiment of the present disclosure further provides a code construction device, including:

[0201] An acquisition module, configured to acquire requirement information and an original code text corresponding to the requirement information and implemented in an original programming language;

[0202] A generation module, configured to obtain, based on the requirement information, at least one corresponding candidate code text by generating a model, wherein the at least one candidate code text is implemented based on a target programming language;

[0203] A verification module is used to verify the at least one candidate code text based on the original code text to obtain a target code text implemented based on the target programming language and corresponding to the requirement information.

[0204] On the other hand, the embodiments of the present disclosure further provide a model fine-tuning device for fine-tuning a target model for at least one round, wherein the process of any round of fine-tuning includes:

[0205] An acquisition module, configured to acquire requirement information and a corresponding target code text, wherein the target code text is obtained based on the method described in any of the aforementioned embodiments;

[0206] The training module is used to train the target model according to the requirement information and the corresponding target code text.

[0207] In another aspect, the present disclosure further provides a code generation device, comprising:

[0208] Acquisition module, used to obtain demand information to be processed;

[0209] An input module, configured to input the requirement information into a target model to obtain a code text corresponding to the requirement information;

[0210] An output module, used for outputting the code text;

[0211] The target model is obtained by training using the method described in any of the aforementioned embodiments.

[0212] The specific implementation principles and effects of each device provided in the embodiments of the present disclosure can be found in the aforementioned method embodiments and will not be repeated here.

[0213] FIG10 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure. As shown in FIG10 , the electronic device of this embodiment may include:

[0214] At least one processor 1001; and a memory 1002 communicatively connected to the at least one processor; wherein the memory 1002 stores instructions executable by the at least one processor 1001, and the instructions are executed by the at least one processor 1001 to cause the electronic device to perform the method as described in any of the above embodiments. Optionally, the memory 1002 can be independent or integrated with the processor 1001.

[0215] The implementation principle and technical effects of the electronic device provided in this embodiment can be found in the aforementioned embodiments and will not be described in detail here.

[0216] An embodiment of the present disclosure further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the method described in any of the above embodiments is implemented.

[0217] An embodiment of the present disclosure further provides a computer program product, including a computer program, which implements the method described in any of the aforementioned embodiments when executed by a processor.

[0218] In the several embodiments provided herein, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the module divisions described are merely one type of logical functional division. In actual implementation, other divisions may be employed, such as combining or integrating multiple modules into another system, or omitting or disabling certain features.

[0219] The integrated modules implemented in the form of software function modules can be stored in a computer-readable storage medium. The software function modules stored in a storage medium include several instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) or a processor to execute some of the steps of the methods described in various embodiments of the present disclosure.

[0220] It should be understood that the above-mentioned processor can be a processing unit (Central Processing Unit, referred to as CPU), or it can be other general-purpose processors, digital signal processors (Digital Signal Processor, referred to as DSP), application specific integrated circuits (Application Specific Integrated Circuit, referred to as ASIC), etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the application can be directly embodied as being executed by a hardware processor, or can be executed by a combination of hardware and software modules in the processor. The memory may include high-speed RAM (Random Access Memory) memory, and may also include non-volatile storage NVM (Non-Volatile Memory), such as at least one disk memory, and can also be a USB flash drive, a mobile hard disk, a read-only memory, a disk or an optical disk, etc.

[0221] The above-mentioned storage medium can be implemented by any type of volatile or non-volatile memory 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 storage medium can be any available medium that can be accessed by a general-purpose or special-purpose computer.

[0222] An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be an integral part of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the storage medium can also exist as discrete components in an electronic device or a main control device.

[0223] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.

[0224] The serial numbers of the above-mentioned embodiments of the present disclosure are for description only and do not represent the advantages or disadvantages of the embodiments.

[0225] Through the description of the above embodiments, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better embodiment. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present disclosure.

[0226] The above are only preferred embodiments of the present disclosure and are not intended to limit the patent scope of the present disclosure. Any equivalent structure or equivalent process transformation made using the contents of the present disclosure and the drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present disclosure.

Claims

1. A code construction method, wherein: include: Obtaining demand information and original code text corresponding to the demand information and implemented in an original programming language; According to the requirement information, obtaining at least one corresponding candidate code text by generating a model, wherein the at least one candidate code text is implemented based on a target programming language; The at least one candidate code text is verified according to the original code text to obtain a target code text corresponding to the requirement information and implemented based on the target programming language.

2. The method according to claim 1, wherein: The generation model is a pre-trained model, and the training data used in the pre-training includes training data corresponding to the original programming language and training data corresponding to the target programming language; According to the requirement information, at least one corresponding candidate code text is obtained by generating a model, including: Inputting the requirement information and prompt information into a generation model to obtain at least one corresponding candidate code text; The prompt information is used to prompt the generation model to implement the candidate code text based on the target programming language.

3. The method according to claim 1, wherein: The generation model is a pre-trained model, and the training data used in the pre-training does not include the training data corresponding to the target programming language; According to the requirement information, at least one corresponding candidate code text is obtained by generating a model, including: Inputting the requirement information and prompt information into a generation model to obtain at least one corresponding candidate code text; The prompt information is used to prompt the generation model to implement the candidate code text based on the target programming language, and the prompt information also includes: grammar rules corresponding to the target programming language.

4. The method according to claim 3, wherein: Before inputting the requirement information and the prompt information into the generation model to obtain at least one corresponding candidate code text, the method further includes: Determining the grammar rule according to at least one function corresponding to the requirement information and / or at least one original sentence included in the original code text; The grammatical rules are used to indicate: statements in the target programming language corresponding to the at least one function, and / or statements corresponding to the at least one original statement.

5. The method according to claim 4, wherein: Determining the grammar rule according to at least one function corresponding to the requirement information and / or at least one original sentence contained in the original code text includes: Inputting the requirement information, at least one of the original code texts, and a prompt instruction into a generation model to obtain prompt information containing grammatical rules; The prompt instruction is used to instruct the generation model to obtain corresponding grammar rules according to the requirement information and / or the original code text, and obtain prompt information according to the grammar rules.

6. The method according to any one of claims 1 to 5, wherein: Verifying the at least one candidate code text according to the original code text to obtain a target code text corresponding to the requirement information and implemented in a target programming language, including: Acquire a test case, and process the test case using the original code text and the at least one candidate code text respectively to obtain a corresponding test result; For any candidate code text, determine whether the candidate code text passes verification according to the test result corresponding to the candidate code text and the test result corresponding to the original code text; Determine the target code text based on the candidate code text that has passed the verification.

7. The method according to claim 6, wherein: The number of the test cases is multiple; determining whether the candidate code text passes the verification according to the test results corresponding to the candidate code text and the test results corresponding to the original code text includes: Determine a pass rate corresponding to the candidate code text, wherein the pass rate is determined by the number of successfully matched test cases in a plurality of test cases and the number of the plurality of test cases; If the pass rate meets the requirement, it is determined that the candidate code text verification has passed; Among them, for any test case, if the test result obtained after the original code text is processed on the test case is the same as the test result obtained after the candidate code text is processed on the test case, then the test case is a successfully matched test case.

8. The method according to claim 7, wherein: If the pass rate meets the requirement, determining that the candidate code text verification has passed includes: If the pass rate corresponding to the candidate code text is greater than the pass rate threshold, it is determined that the candidate code text has passed the verification; Among them, the target code text obtained after verification is used to perform multiple rounds of iterative fine-tuning on the generation model. During the multiple rounds of iterations, the rounds are positively correlated with the pass rate threshold.

9. The method according to any one of claims 1 to 5, wherein: Verifying the at least one candidate code text according to the original code text includes: Compiling the original code text and the at least one candidate code text respectively to obtain a first machine language text corresponding to the original code text and a second machine language text corresponding to each candidate code text; For any candidate code text, if the second machine language text corresponding to the candidate code text is consistent with the first machine language text, it is determined that the candidate code text has passed the verification.

10. The method according to any one of claims 2 to 5, wherein: Obtaining demand information and original code text corresponding to the demand information implemented in an original programming language, including: Obtaining a module to be enhanced for the target programming language input by a user through an interactive interface; Determine a module in the original programming language that matches the module to be enhanced; Obtaining the original code text and corresponding requirement information of the matching module; The prompt information is also used to prompt the generation model to use the module to be enhanced when generating candidate code texts.

11. The method according to claim 6, wherein: Also includes at least one of the following: Displaying the requirement information and the target code text through an interactive interface, so that the user can modify or confirm the target code text according to the requirement information, and add the modified or confirmed target code text to the target code library; Displaying the requirement information through an interactive interface so that the user can input the corresponding test case according to the requirement information; A plurality of candidate programming languages ​​are displayed through an interactive interface, so that a user can select at least one original programming language and / or at least one target programming language according to the plurality of candidate programming languages.

12. A model fine-tuning method, wherein: Used to perform at least one round of fine-tuning on the target model, wherein the process of any round of fine-tuning includes: Obtaining demand information and corresponding target code text, wherein the target code text is obtained based on the method described in any one of claims 1 to 11; The target model is trained according to the requirement information and the corresponding target code text.

13. The method according to claim 12, wherein: The target model includes the generation model; the method further includes: Determine the pass rate threshold based on the current round; The pass rate threshold is used to verify at least one candidate code text obtained by the generation model.

14. The method according to claim 12 or 13, wherein: There are multiple target code texts obtained, and one round of fine-tuning includes multiple batches of training processes; According to the requirement information and the corresponding target code text, the target model is trained, including: Determine the text length corresponding to each target code text; When training any batch, the corresponding text length is determined according to the current batch, and a target code text that meets the text length is selected from multiple target code texts to train the current batch, wherein there is a positive correlation between the text length of the batch and the target code text.

15. A code generation method, wherein: include: Obtain demand information to be processed; Input the demand information into the target model to obtain the code text corresponding to the demand information; Outputting the code text; Wherein, the target model is obtained by training through the method described in any one of claims 12-14.

16. The method according to claim 15, wherein: Input the requirement information into the target model to obtain the code text corresponding to the requirement information, including: Inputting historical code information, language structure information and the requirement information written by the target user into the target model to generate a plurality of corresponding code texts; wherein the target user is the user who inputs the requirement information to be processed; Accordingly, the code text is output, including: Displaying a search box through an interactive interface to obtain search information input by a target user through the search box; According to the search information, searching for matching code texts from the generated multiple code texts and outputting them; The method further includes: obtaining a code text selected by a user from the matching code texts; and training the target model according to the code text selected by the user.

17. An electronic device, wherein: include: at least one processor; as well as a memory communicatively coupled to the at least one processor; The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the electronic device to perform the method described in any one of claims 1-16.

18. A computer-readable storage medium, wherein: The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the method according to any one of claims 1 to 16 is implemented.

19. A computer program product comprising a computer program, wherein: When the computer program is executed by a processor, the method according to any one of claims 1 to 16 is implemented.

Citation Information

Patent Citations

  • A method and deviceapparatus for generating codes

    CN109614111A

  • Code verification method, device and equipment and readable storage medium

    CN116578475A

  • Code generation method and device

    CN116719520A

  • Program translation model obtaining method, program translation method and program translation device

    CN116795379A

  • Code construction method, model fine tuning method, equipment and storage medium

    CN117369796A

Cited By

  • Code generation method and computing device

    CN121166525A

  • Generated code detection method and device, medium and equipment

    CN122152672A