Code generation method, electronic equipment, storage medium and computer program product
By analyzing the feature information and variant direction of the original code, generating multiple variant solutions and modifying the original code, the problem that code data enhancement in the prior art is difficult to overcome syntax or semantic problems, and the performance and generalization capabilities of the code generation model are improved.
Patent Information
- Application Number
- CN202411959810.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-03-28
AI Technical Summary
When the existing technology enhances the code data, it is difficult to effectively overcome syntax or semantic problems, resulting in insufficient generalization capabilities of the generated code model and difficult to cope with complex and changeable real application scenarios.
By determining the characteristic information and variant direction of the original code, multiple variant schemes are generated, and the original code is modified according to these schemes to obtain the variant code. This method ensures that the variant code differs from the original code in feature information and variant directions, and avoids overfitting.
It improves the performance and generalization capabilities of the code generation model, can better deal with complex and changeable real application scenarios, and avoids syntax and logic accuracy issues.
Smart Images

Figure CN119718416A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to technical fields such as data processing, and more particularly to a code generation method, an electronic device, a storage medium, and a computer program product. Background Art
[0002] In order to improve the performance of the code generation model, a large amount of high-quality code is usually required as training data for the model to learn. For the code, it strictly follows specific grammatical and semantic rules, and even slight changes may cause the program to fail to run or logical errors. In order to overcome grammatical or semantic problems, related technologies usually use some methods that do not change the code processing logic when enhancing code data. However, when training the model, the enhanced code obtained by the aforementioned method will cause the generated model to have insufficient generalization ability due to the problem of overfitting of the training data, making it difficult to cope with complex and changeable real application scenarios. Summary of the invention
[0003] The present disclosure provides a code generation method, an electronic device, a storage medium, and a computer program product.
[0004] According to one aspect of the present disclosure, a code generation method is provided, comprising: determining feature information of an original code, the feature information being used to characterize the purpose and structure of the original code; determining multiple variant schemes for the original code according to a variant direction and the feature information, the variant schemes comprising variant operations on the original code; and modifying the original code according to the variant schemes to obtain variant codes, wherein the variant codes have the feature information and are different from the original code in the variant direction.
[0005] In some embodiments, multiple variant schemes for the original code are determined based on the variant direction and the feature information, including: determining a variant strategy for the original code in the variant direction based on the feature information, the variant strategy being a directional variant suggestion for the original code; and generating multiple variant schemes that satisfy the variant strategy.
[0006] In some embodiments, determining the variant strategy of the original code in the variant direction includes: when the variant direction is the depth direction, generating a first variant strategy, the first variant strategy specifies at least one logical code fragment that can be modified in the original code, and at least one modification method corresponding to each of the logical code fragments, the first variant strategy is a modification strategy for the original logic in the original code.
[0007] In some embodiments, determining a variant strategy of the original code in the variant direction includes: when the variant direction is a breadth direction, generating a second variant strategy, wherein the second variant strategy specifies a range of extended code snippets that can be added to the original code, the extended code snippets being new functional code snippets or new component code snippets that the original code does not have, and the second variant strategy is an extension strategy based on the original code.
[0008] In some embodiments, obtaining a variant code includes: modifying the original code according to the variant scheme to obtain a process code, wherein the process code is a result of executing the variant scheme on the original code; determining the similarity between the process code and each code in the target code library; and determining that the process code is a variant code when the similarity between the process code and each code in the target code library is less than a similarity threshold.
[0009] In some implementations, after obtaining the variant code, the method includes: performing multiple rounds of iterative processing on the multiple variant schemes to obtain multiple new variant codes, wherein the number of rounds of iterative processing is less than a round threshold.
[0010] In some embodiments, multiple rounds of iterative processing are performed on multiple variant schemes to obtain multiple new variant codes, including: in a first round of iterative processing, the multiple variant schemes are arranged and combined to obtain multiple first iterative schemes, the first iterative scheme is one of the results of the arrangement and combination of the multiple variant schemes; and the original code is modified according to the first iterative scheme to obtain a new variant code, wherein the process of odd-numbered rounds of iterative processing is the same as the process of the first round of iterative processing.
[0011] In some embodiments, the original code is modified according to the first iteration scheme to obtain a new variant code, including: modifying the original code according to the first iteration scheme to obtain a new process code; determining whether the similarity between the new process code and each code in the target code library is less than a similarity threshold; and when the similarity between the new process code and each code in the target code library is less than the similarity threshold, using the new process code as a new variant code; or, when the similarity between the new process code and any code in the target code library is greater than or equal to the similarity threshold, eliminating the new process code and the first iteration scheme corresponding to it.
[0012] In some embodiments, after obtaining multiple first iteration schemes, it also includes: in a second round of iterative processing, generating a second iteration scheme different from the first iteration scheme according to a variant strategy of the original code, and each first iteration scheme that is not eliminated generates a corresponding second iteration scheme; and modifying the original code according to the second iteration scheme to obtain a new variant code, wherein the process of even-numbered rounds of iterative processing is the same as the process of the second round of iterative processing.
[0013] In some implementations, the further step includes: generating an iteration path of the variant code, wherein the iteration path records the association between the variant code and other codes, wherein the other codes include the original code and other variant codes.
[0014] According to another aspect of the present disclosure, an electronic device is provided, comprising: a memory storing execution instructions; and a processor executing the execution instructions stored in the memory, so that the processor executes the code generation method of any embodiment of the present disclosure.
[0015] According to another aspect of the present disclosure, a readable storage medium is provided, in which execution instructions are stored. When the execution instructions are executed by a processor, the code generation method of any embodiment of the present disclosure is implemented.
[0016] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the code generation method of any embodiment of the present disclosure is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings illustrate exemplary embodiments of the present disclosure and together with the description serve to explain the principles of the present disclosure. These drawings are included to provide a further understanding of the present disclosure and are incorporated in and constitute a part of this specification.
[0018] Figure 1 It is a schematic diagram of an application scenario of the code generation method according to an embodiment of the present disclosure.
[0019] Figure 2 It is a flow chart of a code generation method according to an embodiment of the present disclosure.
[0020] Figure 3 is a flow chart of a variant code generation process according to an embodiment of the present disclosure.
[0021] Figure 4 is a flowchart of an iterative processing process according to an embodiment of the present disclosure.
[0022] Figure 5It is a schematic diagram of an iterative processing process according to an embodiment of the present disclosure.
[0023] Figure 6 It is a schematic block diagram of the structure of a code generation device according to an embodiment of the present disclosure.
[0024] Figure 7 It is a schematic block diagram of the structure of an electronic device according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0025] The present disclosure is further described in detail below in conjunction with the accompanying drawings and examples. It is understood that the specific examples described herein are only used to explain the relevant content, rather than to limit the present disclosure. It should also be noted that, for ease of description, only the parts related to the present disclosure are shown in the accompanying drawings.
[0026] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in the present disclosure can be combined with each other. The technical solution of the present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0027] In order to improve the performance of the code generation model, a large amount of high-quality code is usually required as training data for the model to learn. Some common practices are to increase the amount of training data by using data augmentation, such as flipping images. However, unlike data such as images and text, the code strictly follows specific grammatical and semantic rules, and even slight changes may cause the program to fail to run or logical errors. Therefore, conventional data augmentation methods are not suitable for code. In order to overcome grammatical or semantic problems, related technologies use methods that do not change the code processing logic, such as variable name replacement, function renaming, inserting useless code that does not affect the program logic, and changing the code structure, when enhancing the code data. When training the model, the enhanced code obtained by the above method will cause the generated model to have insufficient generalization ability due to the problem of overfitting, and it will be difficult to cope with complex and changeable real application scenarios.
[0028] To this end, the present disclosure proposes a code generation method.
[0029] Figure 1 Schematic diagram of an application scenario of the code generation method according to an embodiment of the present disclosure. Figure 1 As shown, in this application scenario, a server 100 and a terminal device 200 may be included. The server 100 and the terminal device 200 may be connected via a network or Bluetooth to exchange data. The server 100 may be a cloud server or a physical server, and the terminal device 200 may be a smart device such as a computer, a mobile phone, or a tablet. The server 100 is used to provide the basic data required to run the code generation method, and the terminal device 200 executes the code generation method of the present disclosure based on the basic data provided by the server 100.
[0030] For the convenience of description and to make the technical solutions of the specific implementation methods of the present disclosure easier to understand, before describing the code generation method implemented in the present disclosure, the technical terms involved in the specific implementation methods of the present disclosure are explained as follows: Source code: is the variant basis of the variant code. It can be an element code, such as the code of front-end elements such as components or pages; the corresponding element can be obtained by rendering the source code. The source code records the processing logic and style of the functions of the corresponding elements; each element can have one or more functions. If the element corresponding to the source code is a component, the style recorded in the source code can be the appearance of the component; if the element corresponding to the source code is a page, the style recorded in the source code can be the appearance of each component, as well as the layout of all components on the page. Of course, the source code can also include other code content, which is not limited here.
[0031] Feature information: used to characterize the purpose and structure of the original code, including purpose characteristics and structural characteristics. The purpose characteristics are essentially the functional positioning of the original code, which can be determined based on the source of the original code; for example, the original code comes from a library management system and is used to render a library management table, so its purpose characteristics are library management. Structural characteristics can be determined based on the syntax and code content of the original code, including the developer's writing habits, the calling relationship between code blocks in the original code, the interaction relationship between code blocks, the scope of the processing logic (that is, the code block that is acted on), etc.; among them, a code block can be a complete code snippet in the original code that describes a certain function, or a complete code snippet in the original code that describes a certain component, etc., which has complete processing logic.
[0032] Variant direction: indicates the focus of the original code variant, including depth direction and breadth direction. The depth direction focuses on modifying the original logic of the original code, including the adjustment and deep rewriting of the code flow, condition judgment, and function call; the breadth direction focuses on adding new function code snippets, new component code snippets, etc. based on the original functions of the original code. The variant direction of each original code is randomly selected.
[0033] Variant strategy: Based on personalized feature information, it recommends directional variants of the original code in the variant direction, without involving specific actions. For example, if the variant direction is breadth, and the feature information shows that the original code is a book management table without any functions, then the variant suggestion can be to add data management functions to the original code.
[0034] Variant scheme: It is a specific variant operation of the original code, which clarifies the variant object and variant target. The variant scheme should comply with the guidance requirements of the variant strategy.
[0035] Iteration: It is an iterative process of combining or transforming variant schemes. Each variant scheme will generate a variant code. By permuting, combining or transforming the variant schemes, the number of variant codes of the original code is increased. As the number of iterative processing rounds increases, the number of valid variant codes generated will decrease. Therefore, in order to avoid invalid iterations, the allowed number of iterative processing rounds can usually be preset, such as two or three times.
[0036] Variant code: is a variant of the original code according to a variant or iteration scheme. Compared with the original code, the variant code may have different processing logic for the same function, or may add new function code snippets or new component code snippets. Variant code can be used as training data for code generation models.
[0037] Iteration path: records the change process of the variant code from the original code to the current state, that is, the relationship between the variant code and the remaining code, where the remaining code includes the original code and other variant codes. The iteration path can be used as training data for the variant solution generation model.
[0038] Figure 2 is a flow chart of a code generation method according to an embodiment of the present disclosure. Figure 2 As shown, the present disclosure proposes a code generation method M200, which obtains variant codes through steps S210 to S230, solves the problem of overfitting when performing data enhancement on the code, and avoids the grammatical and logical accuracy of the code. The data of running the code generation method M200 can be recorded in Figure 1 The method M200 is executed by the server 100 in the terminal device 200. It should be noted that the method M200 can be executed by the intelligent agent Agent carried in the terminal device 200. The Agent has the ability to autonomously run the method M200 and can call the large language model in various processing links to assist in performing corresponding tasks.
[0039] In step S210, feature information of the original code is determined.
[0040] In this process, the large language model can be used to analyze the original code to determine the characteristic information of the original code, including usage characteristics and structural characteristics. The usage characteristics can be determined according to the source of the original code. For example, if the original code comes from a library management system and is used to describe the library management table of the system, then the usage characteristics of the original code can be library management. The structural characteristics can be determined according to the syntax and content of the original code. Different developers have different code writing habits. Therefore, the specific writing habits of the developer of the original code can be determined by the syntax, so that when the variant code is generated later, the developer's writing habits can be imitated to produce a more realistic and personal variant code. The structural characteristics can also include the calling relationship between the code blocks in the original code, the interaction relationship between the code blocks, the scope of the processing logic (i.e., the code block in question), etc.; wherein, the code block can be a complete code snippet in the original code that describes a certain function, or a complete code snippet in the original code that describes a certain component, etc., with complete processing logic. By extracting the characteristic information of the original code, a rich contextual basis is provided for the subsequent acquisition of variant code, which is the basis for generating high-quality variant code, making the variant code more realistic and logically reasonable.
[0041] In step S220, multiple variant solutions for the original code are determined according to the variant directions and feature information.
[0042] Specifically, according to the feature information, a variant strategy of the original code in the variant direction is determined, where the variant strategy is a directional variant suggestion for the original code; and multiple variant solutions that meet the variant strategy are generated.
[0043] Among them, when the variant direction is the depth direction, a first variant strategy is generated, the first variant strategy specifies at least one logic code snippet that can be modified in the original code, and at least one modification method corresponding to each logic code snippet, and the first variant strategy is a modification strategy for the original logic in the original code. When the variant direction is the breadth direction, a second variant strategy is generated, the second variant strategy specifies the range of extended code snippets that can be added to the original code, the extended code snippets are new functional code snippets or new component code snippets that the original code does not have, and the second variant strategy is an extension strategy based on the original code.
[0044] The variant direction is randomly selected, which can be depth or breadth, and determines the focus of the variant. The depth direction focuses more on the changes to the original logic in the original code, while the breadth direction focuses more on the addition of functions or components that are not in the original code. By randomly selecting the depth and breadth directions, the differences between different variant codes in the training data are improved, avoiding the overfitting problem of the training data.
[0045] Different variant directions and personalized feature information of the original code will generate different variant plans. The variant plan is a specific variant operation on the original code, which clarifies the variant object and variant target. For example, replace the code snippet about logic A in the original code with the code snippet about logic B to implement the function corresponding to logic A in the original code or upgrade it based on the function implemented by logic A.
[0046] In step S230, the original code is modified according to the variant scheme to obtain a variant code.
[0047] Specifically, the original code is modified according to the variant scheme to obtain the process code, which is the result of executing the variant scheme on the original code; the similarity between the process code and each code in the target code library is determined; and when the similarity between the process code and each code in the target code library is less than a similarity threshold, the process code is determined to be a variant code.
[0048] The part of the original code that needs to be mutated (i.e., the variant object) is operated according to the variant scheme, and finally the variant code that can meet the expectations of the variant scheme is obtained. For example, a new functional code fragment C is added to the fifth line of the source code. Then the variant code is essentially the result of inserting the new functional code fragment C into the fifth line of the original code.
[0049] After step S210, the process includes: performing multiple rounds of iterative processing on multiple variant schemes to obtain multiple new variant codes, wherein the number of rounds of iterative processing is less than a round threshold.
[0050] Specifically, in the first round of iterative processing, multiple variant schemes are arranged and combined to obtain multiple first iterative schemes, where the first iterative scheme is one of the results of permuting and combining the multiple variant schemes; and the original code is modified according to the first iterative scheme to obtain a new variant code, wherein the process of odd-numbered rounds of iterative processing is the same as that of the first round of iterative processing.
[0051] In some embodiments, after obtaining the new variant code, it is determined whether the similarity between the new variant code and each code in the target code library is less than a similarity threshold; and if the similarity between the new variant code and each code in the target code library is less than the similarity threshold, the new variant code is written into the target code library; or, if the similarity between the new variant code and any code in the target code library is greater than or equal to the similarity threshold, the new variant code and the first iteration scheme corresponding thereto are eliminated.
[0052] In some embodiments, in the second round of iterative processing, a second iterative scheme different from the first iterative scheme is generated according to a variant strategy of the original code, and a second iterative scheme is generated for each first iterative scheme that is not eliminated; and the original code is modified according to the second iterative scheme to obtain a new variant code, wherein the process of iterative processing of even rounds is the same as the process of the second round of iterative processing.
[0053] In some implementations, an iteration path of the variant code is generated, and the iteration path records the association between the variant code and other codes, where the other codes include the original code and other variant codes.
[0054] The code generation method disclosed in the present invention randomly determines the variant direction, and determines multiple variant schemes for the original code based on the feature information of the original code; each variant scheme generates a variant code. The difference between different variant codes is guaranteed, and the overfitting problem between variant codes is avoided; at the same time, because the feature information is taken into account in the variant process, the variant code will not deviate from the syntax or purpose of the original code, and has the characteristics of authenticity, reliability and accuracy, avoiding the problems such as syntax deviation generated when the code is enhanced with data.
[0055] Figure 3 is a flow chart of the variant code generation process according to the embodiment of the present disclosure. Figure 3 A more detailed and complete description of the variant code generation process.
[0056] In step 301, the direction of the variation of the original code is determined. The variation direction includes the depth direction and the breadth direction. The variation of these two directions has different focuses. The depth direction focuses more on the modification of the original logic of the original code, while the breadth direction focuses more on the expansion based on the original function or original component of the original code. The description of the variation direction can be referred to above and will not be repeated here.
[0057] In step 302, the feature information of the original code is analyzed. The feature information of the original code characterizes the purpose and structure of the original code, including purpose features and structural features. The purpose features are essentially the functional positioning of the original code; the structural features can be determined based on the syntax and code content of the original code, including the developer's writing habits, the calling relationship between the code blocks in the original code, the interaction relationship between the code blocks, the scope of the processing logic (i.e. the code blocks acted on), etc. For the description of the feature information, please refer to the previous text and will not be repeated here. Different original codes have different feature information. The feature information is the personalized parameter of the original code. The feature information can make the variant code evolved from the original code have a closer to real performance.
[0058] In step 303, a variation strategy is determined according to the variation direction and feature information.
[0059] The variant strategy is a directional variant suggestion for the original code after combining feature information and variant direction. It is the guiding information for generating variant solutions and is used to constrain the scope of variant solutions. For example, the original code includes logic A and logic B. When the variant direction is depth direction, the variant suggestion can be to replace the code snippet corresponding to logic A or to replace the code snippet corresponding to logic B; the variant solution can be to replace the code snippet corresponding to logic A with the code snippet corresponding to logic C, or to replace the code snippet corresponding to logic B with the code snippet corresponding to logic D, but it cannot be to add a new function snippet E to the fifth line of the original code.
[0060] Step 303 can be implemented by calling the large language model, that is, using the variant direction and feature information as the input of the large language model to control its output variant strategy. This variant strategy will serve as a prompt template when the large language model generates variant solutions. By determining the variant strategy, the flexibility of subsequent generation of variant solutions is guaranteed, while the generated variant solutions do not deviate from the constraints of the variant direction and feature information.
[0061] In step 304, multiple variant solutions for the original code are determined based on the variant strategy.
[0062] The variant strategy and the original code can be used as the input of the large language model, and then the number of variant strategies required can be set. The variant strategy can be n, where n is any positive integer, for example, n=3. Then, the large language model can output n variant solutions of different dimensions. The variant solution needs to meet the requirements of the variant strategy. The variant solution should be a specific variant operation of the original code, such as replacing the code snippet corresponding to logic A with the code snippet corresponding to logic C.
[0063] In step 305, the variant solution is executed to generate the corresponding process code. The process code is the result of executing the variant solution on the original code. When the similarity between the process code and the existing code in the target code library is less than the similarity threshold, the process code is a valid variant code. The target code library is used to record the original code and the variant code.
[0064] In order to avoid the overfitting problem of variant codes, before writing the process code as a variant code into the target code library, step 306 is executed to determine whether the similarity between the process code and each code in the target code library is less than the similarity threshold. If the similarity between the process code and each code in the target code library is less than the similarity threshold, it indicates that there are large differences between the process code and each code in the target code library, then it can be written into the target code library as a variant code, and the variant scheme for generating the code is valid. On the contrary, if the similarity between the process code and any code in the target code library is greater than or equal to the similarity threshold, it means that the process code is similar or identical to the corresponding code. Since there is no need to repeatedly train the model using similar or identical codes, step 307 should be executed to eliminate the process code, and the variant scheme for generating the process code should also be eliminated. Both steps 306 and 307 can be executed by calling a large language model.
[0065] In step 308, the variant scheme is iteratively processed to obtain a plurality of new variant codes.
[0066] For variant codes whose similarity with each code in the target code library is less than the similarity threshold, multiple variant schemes for generating such variant codes are arranged and combined to obtain multiple iterative schemes. Then, the original code is mutated based on these iterative schemes to obtain multiple new variant codes. Of course, when obtaining new variant codes, it is necessary to determine the similarity between the new process code and each code in the target code library. For new process codes whose similarity with each code in the target code library is less than the threshold, they are stored in the target code library as new variant codes. Otherwise, the corresponding new process code and its iterative scheme are eliminated. The process of generating new variant codes is the same as steps 306 and 307.
[0067] Further, it is determined whether the round of iterative processing of the original code is less than the round threshold through step 309. The round threshold m can be 2 or 3. In order to ensure that there are differences between the process code and each code in the target code library, the round threshold should not be too large, but the specific value can also be set according to demand and is not limited here.
[0068] If the number of iterative processing rounds is less than the round threshold, then repeat step 308 to perform a new round of iterative processing on the original code. Otherwise, the new variant code is stored in the target code library.
[0069] Figure 4 is a flowchart of an iterative processing process according to an embodiment of the present disclosure. Figure 4 , showing the specific process of iterative processing of the original code. Figure 3 A refinement of step 308 to step 309.
[0070] In step 401, multiple variant solutions are obtained. These variant solutions are obtained by Figure 3 The variant schemes of the variant codes retained by the similarity evaluation in step 306.
[0071] In step 402, multiple variant solutions are arranged and combined to obtain multiple first iteration solutions. Figure 5 is a schematic diagram of an iterative processing process according to an embodiment of the present disclosure, with reference to Figure 5 , assuming that the variant solutions obtained in step 401 include A and B, after the first round of iterative processing, the first iterative solutions are obtained: A, B, AB. The first iterative solution is the result of the permutation and combination of the variant solutions. If there are 3 variant solutions, then there will be 7 first iterative solutions. The permutation and combination of the variant solutions is the most common permutation and combination method, and no further introduction will be made.
[0072] In step 403, a corresponding process code is generated according to each first iteration scheme. Then, step 404 is executed to determine whether the similarity between the process code and each code in the target code library is less than a similarity threshold. The similarity threshold can be set according to the needs and is not limited again. If there is any code in the target code library whose similarity with the process code is greater than or equal to the similarity threshold, step 405 is executed to eliminate the process code and its first iteration scheme. On the contrary, if the similarity between the process code and each code in the target code library is less than the similarity threshold, step 406 is executed to use the process code as the new variant code. Reference Figure 5 During the first round of iterative processing, the new variant code corresponding to the first iterative scheme A may be a, the new variant code corresponding to the second iterative scheme B may be b, and the new variant code corresponding to the first iterative scheme AB may be ab.
[0073] It should be noted that when there is an iterative process, the new variant codes generated by each round of iterative schemes are usually written into the target database, while the variant codes of the variant schemes directly generated from the original code are not written into the target database. For example, when the first iterative scheme is a variant scheme, if the variant codes generated by the variant scheme are written into the target code library, then when the similarity evaluation is performed on the new variant codes generated by the first iterative scheme, the first iterative scheme is mistakenly deleted because the similarity is greater than the similarity threshold. In this case, the second iterative scheme cannot be generated based on the first iterative scheme, resulting in unnecessary code reduction problems. For example, the first iterative scheme A is a variant scheme A. If the variant code a generated by the variant scheme A is written into the target code library, then when the first iterative scheme A generates code a, since code a is the same as the variant code a already in the target code library, the first iterative scheme A will be eliminated, and then the second iterative scheme C cannot be generated according to the first iterative scheme A in the second round of iterative processing, which obviously causes the reduction of the new variant code c.
[0074] Furthermore, in step 407, it is determined whether the number of rounds of iterative processing is less than the round threshold. If the number of rounds of iterative processing is greater than or equal to the round threshold, it means that sufficient variants have been made to the original code. If it is iterated again, the probability that the similarity between the generated new process code and the code in the target code library is greater than or equal to the similarity threshold will increase, and the amount of effective new variant code generated will decrease. Such meaningless iteration will waste the computing power of the device terminal running this method.
[0075] If the number of iterative processing rounds is less than the round threshold, it means that the original code has not been sufficiently mutated, so step 408 is executed to determine whether the next iterative processing round is an even round. If it is an odd round, steps 402 to 407 are repeated.
[0076] If it is an even round, step 409 is executed to generate a corresponding second iteration scheme according to each first iteration scheme that has not been eliminated.
[0077] In this process, the first iteration solution input, feature information, variant style and requirements are input into the large language model. The requirement can be to generate a second iteration solution that is different from the first iteration solution. Each first iteration solution generates a corresponding second iteration solution. Figure 5 In the second round of iterative processing, through the large language model, the first iteration scheme A is iterated into the second iteration scheme C, the first iteration scheme B is iterated into the second iteration scheme D, and the first iteration scheme AB is iterated into the second iteration scheme E; among them, at least the first iteration scheme A is different from the second iteration scheme C, the first iteration scheme B is different from the second iteration scheme D, and the first iteration scheme AB is different from the second iteration scheme E.
[0078] Further, step 410 is executed to generate a corresponding new variant code according to the second iteration scheme. Figure 5 , the second iteration scheme C generates a new variant code c, the second iteration scheme D generates a new variant code d, and the second iteration scheme E generates a new variant code e. Of course, before obtaining the new variant code, the new process codes generated by the various second iteration schemes will be subjected to the same similarity evaluation and processing process as steps 404 to 406, and the new process codes retained after the similarity evaluation are determined to be new variant codes, which will not be described in detail here.
[0079] After step 410, the iterative processing round of the original code is incremented by one, and then step 407 is repeated to determine whether the current iterative processing round is less than the round threshold. If it is less than the round threshold, step 408 is executed, otherwise the iterative processing process of the original code is terminated.
[0080] Furthermore, the new variant code obtained through the first round of iterative processing and the new variant code obtained through the second round of iterative processing are written into the target code library.
[0081] At the same time, step 311 is executed to generate an iteration path for each variant code. The iteration path represents the association between the variant code and the remaining codes, including the remaining variant codes and the original code. Each code has a unique code identifier. For example, assuming that the code identifier of the original code is o, then for Figure 5 For the new variant code c in , its iteration path can be "o→a→c", and the iteration paths of other variant codes are the same, which are not listed here one by one. The iteration path records the change process of the variant code from the original code to the current state, which can be used as training data for the variant solution generation model. After using the iteration path to train the variant solution generation model, various variant solutions and iteration solutions can be directly generated through the model, providing a new generation idea for obtaining variant codes.
[0082] Ultimately, the various variant codes generated can be used to train the code generation model so that the code generation model has sufficient generalization capabilities. Ultimately, the code generation model can be used to generate usable code that is close to real coding scenarios, meets multiple coding needs, and is usable.
[0083] The code generation method disclosed in the present invention randomly determines the variant direction, and determines multiple variant schemes for the original code based on the feature information of the original code; each variant scheme generates a variant code. The difference between different variant codes is guaranteed, and the overfitting problem between variant codes is avoided; at the same time, because the feature information is taken into account in the variant process, the variant code will not deviate from the syntax or purpose of the original code, and has the characteristics of authenticity, reliability and accuracy, avoiding the problems such as syntax deviation generated when the code is enhanced with data.
[0084] Figure 6 It is a schematic block diagram of the structure of a code generation device according to an embodiment of the present disclosure.
[0085] like Figure 6 As shown, the present disclosure provides a code generating device 600, which can be arranged in Figure 1 In the terminal device 200 shown in FIG. 1 , various data required for its operation can be recorded in Figure 1 The device 600 includes: a feature information determination module 610, a scheme determination module 620 and a variant code generation module 630.
[0086] Among them, the feature information determination module 610 is used to determine the feature information of the original code, and the feature information is used to characterize the purpose and syntax of the original code; the scheme determination module 620 is used to determine multiple variant schemes for the original code according to the variant direction and feature information, and the variant scheme includes variant operations on the original code; and the variant code generation module 630 is used to modify the original code according to the variant scheme to obtain the variant code, wherein the variant code has feature information and is different from the original code in the variant direction.
[0087] The code generation device 600 of the present disclosure may be in the form of computer software, and each module of the code generation device may be in the form of a computer software module.
[0088] The various modules of the code generation device 600 disclosed in the present invention are configured to implement the various steps of the code generation method. The execution principles and steps thereof may be referred to above and will not be described in detail here.
[0089] The code generation device disclosed in the present invention randomly determines the variant direction, and determines multiple variant schemes for the original code based on the feature information of the original code; each variant scheme generates a variant code. The difference between different variant codes is guaranteed, and the overfitting problem between variant codes is avoided; at the same time, because the feature information is considered in the variant process, the variant code will not deviate from the syntax or purpose of the original code, and has the characteristics of authenticity, reliability and accuracy, avoiding the problems such as syntax deviation generated when the code is enhanced with data.
[0090] Figure 7 The electronic device 1000 can execute the code generation method of any embodiment described above in the present disclosure.
[0091] like Figure 7As shown, the hardware structure of the electronic device 1000 can be implemented using a bus architecture. The bus architecture can include any number of interconnected buses and bridges, depending on the specific application and overall design constraints of the hardware. The bus 1100 connects various circuits including one or more processors 1200, memory 1300 and / or hardware modules together. The bus 1100 can also connect various other circuits 1400 such as peripherals, voltage regulators, power management circuits, external antennas, etc.
[0092] The bus 1100 may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Component (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the figure only uses one connecting line, but does not mean that there is only one bus or one type of bus.
[0093] The present disclosure also provides a readable storage medium, in which a computer program is stored, and the computer program is used to implement the above method when executed by a processor. "Readable storage medium" can be any device that can contain, store, communicate, propagate or transmit a program for use in an instruction execution system, device or equipment or in combination with these instruction execution systems, devices or equipment. More specific examples of readable storage media include the following: an electrical connection portion (electronic device) with one or more wirings, a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and editable read-only memory (EPROM or flash memory), an optical fiber device, and a portable read-only memory (CDROM), etc.
[0094] The present disclosure also provides a computer program product. The method of the present disclosure can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instruction is loaded and executed, the process or function of the present disclosure is executed in whole or in part.
[0095] The computer program or instructions may be stored in a readable storage medium or transmitted from one readable storage medium to another readable storage medium, for example, the computer program or instructions may be transmitted from one website, computer, server or data center to another website, computer, server or data center by wired or wireless means. The readable storage medium may be any available medium that can be accessed or a data storage device such as a server, data center, etc. that integrates one or more available media. The available medium may be a magnetic medium, such as a floppy disk, a hard disk, or a magnetic tape; it may also be an optical medium, such as a digital video disk; it may also be a semiconductor medium, such as a solid state drive. The computer readable storage medium may be a volatile or non-volatile storage medium, or may include both volatile and non-volatile types of storage media.
[0096] The code generation device, readable storage medium and computer program product disclosed in the present invention all have the following effects: randomly determine the variant direction, and determine multiple variant schemes for the original code based on the feature information of the original code; each variant scheme generates a variant code. The difference between different variant codes is guaranteed, and the overfitting problem between variant codes is avoided; at the same time, because the feature information is considered in the variant process, the variant code will not deviate from the syntax or purpose of the original code, and has the characteristics of authenticity, reliability and accuracy, avoiding the problems such as syntax deviation generated when the code is enhanced with data.
[0097] Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as methods, systems, or computer program products. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present disclosure may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0098] The present disclosure is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the present disclosure. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0099] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0100] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0101] In the description of this specification, the description with reference to the terms "one embodiment / method", "some embodiments / methods", "example", "specific example", or "some examples" etc. means that the specific features, structures, or characteristics described in conjunction with the embodiment / method or example are included in at least one embodiment / method or example of the present disclosure. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment / method or example. Moreover, the specific features, structures, or characteristics described may be combined in any one or more embodiments / methods or examples in a suitable manner. In addition, those skilled in the art may combine and combine different embodiments / methods or examples described in this specification and features of different embodiments / methods or examples, unless they are contradictory.
[0102] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present disclosure, "plurality" means at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0103] Those skilled in the art should understand that the above embodiments are only for the purpose of clearly illustrating the present disclosure, and are not intended to limit the scope of the present disclosure. For those skilled in the art, other changes or modifications may be made based on the above disclosure, and these changes or modifications are still within the scope of the present disclosure.
Claims
1. A code generation method, characterized in that: include: Determining characteristic information of the original code, wherein the characteristic information is used to characterize the purpose and structure of the original code; Determine multiple variant solutions for the original code according to the variant direction and the feature information, wherein the variant solutions include variant operations on the original code; as well as The original code is modified according to the variant scheme to obtain a variant code, wherein the variant code has the characteristic information and is different from the original code in the variant direction.
2. The code generation method according to claim 1, characterized in that: According to the variation direction and the feature information, multiple variation schemes for the original code are determined, including: Determining, according to the feature information, a variation strategy of the original code in the variation direction, wherein the variation strategy is a directional variation suggestion for the original code; and A plurality of the variation schemes satisfying the variation strategy are generated.
3. The code generation method according to claim 2, characterized in that: Determining a variation strategy of the original code in the variation direction includes: When the variant direction is the depth direction, a first variant strategy is generated, wherein the first variant strategy specifies at least one logic code fragment that can be modified in the original code, and at least one modification method corresponding to each logic code fragment, and the first variant strategy is a modification strategy for the original logic in the original code.
4. The code generation method according to claim 2, characterized in that: Determining a variation strategy of the original code in the variation direction includes: When the variant direction is the breadth direction, a second variant strategy is generated, wherein the second variant strategy specifies the range of extended code snippets that can be added to the original code, wherein the extended code snippets are new functional code snippets or new component code snippets that the original code does not have, and the second variant strategy is an extension strategy based on the original code.
5. The code generation method according to claim 1, characterized in that: Get the variant code, including: Modify the original code according to the variant scheme to obtain a process code, where the process code is a result of executing the variant scheme on the original code; Determining the similarity between the process code and each code in the target code library; and When the similarity between the process code and each code in the target code library is less than a similarity threshold, the process code is determined to be a variant code.
6. The code generation method according to claim 1, characterized in that: After you get the variant code, include: Multiple rounds of iterative processing are performed on the multiple variant schemes to obtain multiple new variant codes, and the rounds of the iterative processing are less than a round threshold.
7. The code generation method according to claim 6, characterized in that: Multiple rounds of iterative processing are performed on the multiple variant schemes to obtain multiple new variant codes, including: In the first round of iterative processing, a plurality of variant solutions are arranged and combined to obtain a plurality of first iterative solutions, where the first iterative solution is one of the results of the arrangement and combination of the plurality of variant solutions; and The original code is modified according to the first iteration scheme to obtain a new variant code, wherein the process of odd-numbered rounds of iterative processing is the same as the process of the first round of iterative processing.
8. The code generation method according to claim 7, characterized in that: Modifying the original code according to the first iteration scheme to obtain a new variant code includes: Modify the original code according to the first iteration scheme to obtain a new process code; Determine whether the similarity between the new process code and each code in the target code library is less than a similarity threshold; and When the similarity between the new process code and each code in the target code library is less than a similarity threshold, the new process code is used as a new variant code; or, when the similarity between the new process code and any code in the target code library is greater than or equal to the similarity threshold, the new process code and the first iteration scheme corresponding to it are eliminated.
9. The code generation method according to claim 8, characterized in that: After obtaining multiple first iteration solutions, the following is further included: In the second round of iterative processing, a second iterative solution different from the first iterative solution is generated according to the variant strategy of the original code, and one second iterative solution is generated for each first iterative solution that is not eliminated; and The original code is modified according to the second iteration scheme to obtain a new variant code, wherein the process of the even-numbered rounds of iterative processing is the same as the process of the second round of iterative processing.
10. The code generation method according to any one of claims 1 to 9, characterized in that: Also includes: An iterative path of the variant code is generated, wherein the iterative path records the association between the variant code and other codes, wherein the other codes include the original code and other variant codes.
11. An electronic device, characterized in that: include: A memory storing execution instructions; as well as A processor, wherein the processor executes the execution instruction stored in the memory, so that the processor executes the code generation method according to any one of claims 1 to 10.
12. A readable storage medium, characterized in that: The readable storage medium stores execution instructions, which are used to implement the code generation method according to any one of claims 1 to 10 when executed by a processor.
13. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the code generation method according to any one of claims 1 to 10 is implemented.