Auxiliary code generation method based on large language model, electronic equipment and program product
Through the auxiliary code generation method based on the large language model, the problems of inflexible guidance and incomplete content of traditional code generation methods are solved. The generated code is more in line with user needs and has higher integrity and adaptability.
Patent Information
- Application Number
- CN202411790108.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-05-02
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The traditional code generation method has problems such as inflexible generation and guidance and incomplete generation content, which is difficult to help beginners achieve smooth code writing and quickly improve their programming level in programming teaching.
The auxiliary code generation method based on the large language model is adopted to obtain the demand text that represents the user's intention, match the target code tags corresponding to the demand text, and use the large language model to generate auxiliary code corresponding to the demand text.
The generated code corresponds to user needs, and the code is more complete and adaptable, which improves the shortcomings of traditional code generation methods and provides more flexible and comprehensive code generation guidance.
Smart Images

Figure CN119917102A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an auxiliary code generation method, electronic equipment and program product based on a large language model. Background Art
[0002] With the vigorous development of technologies such as pre-trained models, multimodal technology, and generative algorithms, AIGC (Artificial Intelligence Generated Content) came into being.
[0003] In the field of programming teaching, current programming teaching is mainly conducted by teachers through PPT, videos, and code segments, and combined with students' self-practice to improve programming ability. In the actual teaching process, students are practicing by themselves. Due to the limited level of beginners, there is no relevant code reference and guidance in the process of programming to achieve a certain function. They are often unable to achieve smooth code writing and rapid improvement of programming level in practice.
[0004] In view of the above situation, traditional code editing software usually provides a code prompt function, that is, the software prompts a complete code sentence based on the partial field of the code entered by the user, thereby reducing the user's writing burden and providing code writing guidance for the user. However, this method relies on the user entering the correct partial field of the code, and the generated content is limited to the short sentence completion for the user input field. There are problems such as inflexible guidance and incomplete generated content. Summary of the invention
[0005] In view of this, the purpose of the embodiments of the present application is to provide an auxiliary code generation method, electronic device and program product based on a large language model, which can improve the problems of inflexible generation guidance and incomplete generation content in traditional code generation methods.
[0006] In order to achieve the above technical objectives, the technical solutions adopted in this application are as follows:
[0007] In a first aspect, an embodiment of the present application provides an auxiliary code generation method based on a large language model, the method comprising:
[0008] Obtain the requirement text that represents the user's intention;
[0009] According to the requirement text, matching the target code tag corresponding to the requirement text from a preset database;
[0010] According to the requirement text and the target code label, an auxiliary code corresponding to the requirement text is generated through a preset large language model.
[0011] In conjunction with the first aspect, in some optional implementations, before obtaining the requirement text representing the user's intention, the method further includes:
[0012] Acquire an original code set, wherein the original code set includes a plurality of original codes;
[0013] According to the original code set, determining a code label corresponding to each of the plurality of original codes by using the preset large language model, wherein the code label includes a function label and an edit label, wherein the function label represents a purpose achieved by the original code, and the edit label represents a calculation process and parameters required to achieve the purpose;
[0014] According to the code label, a database including the code label corresponding to each original code is constructed as the preset database.
[0015] In combination with the first aspect, in some optional implementations, matching the target code tag corresponding to the requirement text from a preset database according to the requirement text includes:
[0016] Determining the similarity between the demand text and the code tag in the preset database according to the demand text and the preset database;
[0017] The similarities are sorted, and the first n code tags with the largest similarities are determined as the target code tags, where n is an integer greater than or equal to 2.
[0018] In combination with the first aspect, in some optional implementations, determining the similarity between the requirement text and the code tag in the preset database according to the requirement text and the preset database includes:
[0019] Performing vector conversion on the demand text to obtain a first feature vector corresponding to the demand text;
[0020] Performing vector conversion on the function label in the code label to obtain a second feature vector corresponding to the code label;
[0021] The cosine similarity between the first eigenvector and the second eigenvector is determined as the similarity.
[0022] In combination with the first aspect, in some optional implementations, the method further includes:
[0023] Semantically encoding the auxiliary code in units of sentence granularity to obtain a semantic encoding sequence corresponding to each code sentence in the auxiliary code;
[0024] Based on the semantic optimization formula, semantic optimization is performed on the semantic coding sequence to obtain an optimized coding sequence;
[0025] Based on the semantic enhancement formula, semantic enhancement is performed on the optimized coding sequence to obtain an enhanced coding sequence;
[0026] According to the enhanced coding sequence, an optimized auxiliary code is generated through a preset code optimization model.
[0027] In combination with the first aspect, in some optional implementations, the semantic optimization formula is as follows:
[0028] A ij =f(W[x i ||x j(j≠i) ])
[0029]
[0030] In the formula, x i and x j denote the i-th and j-th semantic coding vectors in the semantic coding sequence, respectively, W denotes the preset weight feature vector, f(·) denotes the nonlinear activation function, [x i ||x j ] represents vector concatenation, A ij represents the element in the i-th row and j-th column of the autocorrelation feature matrix, exp(·) represents the exponential operation with the natural constant e as the base, n represents the number of semantic coding vectors in the semantic coding sequence minus one, and a ij represents the element in the i-th row and j-th column of the autocorrelation weight matrix, α and β represent trainable hyperparameters, σ1(·) represents the activation function, and x′ j Represents x i and x j The number of semantic encoding vectors between i represents the i-th optimized semantic encoding vector in the optimized encoding sequence.
[0031] In conjunction with the first aspect, in some optional implementations, the semantic enhancement formula is as follows:
[0032] X′=Avg(x′ i )
[0033] X″=Max(x′ i )
[0034]
[0035] y′ i = x′ i ⊙(tanh(B1+B2)⊙σ2(B1+B2))+x′i
[0036] In the formula, x′ i represents the i-th optimized semantic coding vector in the optimized coding sequence, Avg(·) represents the global mean in the calculation vector, Max(·) represents the maximum value in the calculation vector, Conv(·) represents a one-dimensional convolution operation, ReLU(·) represents the ReLU activation function, and denote the first trainable weight matrix and the second trainable weight matrix, respectively; B1 and B2 denote the context semantic mean feature vector and the context semantic maximum feature vector, respectively; tanh(·) is the tanh function; ⊙ denotes the dot product; y′ i Represents the i-th enhanced semantic encoding vector in the enhanced encoding sequence.
[0037] In conjunction with the first aspect, in some optional implementations, before obtaining the requirement text representing the user's intention, the method further includes:
[0038] Build a code optimizer based on the AIGC model as the initial code optimization model;
[0039] Acquire a training sample, wherein the training sample includes an original auxiliary code and a real optimized auxiliary code corresponding to the original auxiliary code;
[0040] Dividing the training samples into a training set and a test set according to a preset ratio as training data;
[0041] Performing semantic encoding, semantic optimization and semantic enhancement on the training data to obtain an enhanced training data encoding sequence corresponding to the training data;
[0042] Inputting the enhanced training data coding sequence into the initial code optimization model to generate a training optimization code corresponding to the enhanced training data coding sequence through the initial code optimization model;
[0043] Based on a preset loss function, calculating the loss value of the truly optimized auxiliary code and the training optimized code;
[0044] The initial code optimization model is trained according to the loss value until the loss function converges, and a trained initial code optimization model is obtained as the preset code optimization model.
[0045] In a second aspect, an embodiment of the present application further provides an electronic device, comprising a processor and a memory coupled to each other, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the electronic device executes the above method.
[0046] In a third aspect, an embodiment of the present application further provides a computer program product, including a computer program, which implements the above method when executed by a processor.
[0047] The invention adopting the above technical solution has the following advantages:
[0048] In the technical solution provided by the present application, the demand text representing the user's intention is first obtained. Then, according to the demand text, the target code tag corresponding to the demand text is matched from the preset database. Then, according to the demand text and the target code tag, the auxiliary code corresponding to the demand text is generated by the preset large language model. In this way, the user demand is used as the function of generating code, and the target code tag is used as the background description of the subsequent code generation. Finally, the auxiliary code is generated based on the user demand and the target code tag through the large language model, so that the generated code corresponds to the user's demand, and the code is more complete and adaptable, thereby improving the problems of inflexible generation guidance and incomplete generated content in the traditional code generation method. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] The present application may be further described by the non-limiting embodiments given in the accompanying drawings. It should be understood that the following drawings only illustrate certain embodiments of the present application and therefore should not be regarded as limiting the scope. For those of ordinary skill in the art, other relevant drawings may be obtained based on these drawings without creative effort.
[0050] Figure 1 A structural block diagram of an electronic device provided in an embodiment of the present application.
[0051] Figure 2 A flowchart of an auxiliary code generation method based on a large language model provided in an embodiment of the present application.
[0052] Icon: 100 - electronic device; 101 - processor; 102 - memory. DETAILED DESCRIPTION
[0053] The present application will be described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be noted that in the drawings or descriptions, similar or identical parts use the same figure numbers, and the implementation methods not shown or described in the drawings are forms known to ordinary technicians in the relevant technical field. In the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.
[0054] Please refer to Figure 1, an embodiment of the present application provides an electronic device 100 that may include a processor 101 and a memory 102. The memory 102 stores a computer program, and when the computer program is executed by the processor 101, the electronic device 100 can perform the corresponding steps in the following auxiliary code generation method based on a large language model.
[0055] In this embodiment, the processor 101 may be an integrated circuit chip having signal processing capabilities. The processor 101 may be a general-purpose processor. For example, the processor 101 may be a central processing unit (CPU), a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, and may implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application.
[0056] The memory 102 may be, but is not limited to, a random access memory, a read-only memory, a programmable read-only memory, an erasable programmable read-only memory, an electrically erasable programmable read-only memory, etc. In this embodiment, the memory 102 may be used to store a demand text, a preset database, a target code label, a preset large language model, an auxiliary code, a preset code optimization model, an optimized auxiliary code, etc. Of course, the memory 102 may also be used to store a program, and the processor 101 executes the program after receiving an execution instruction.
[0057] In this embodiment, the electronic device 100 may be a personal computer, a laptop computer, a cloud server, etc. It is used to obtain a demand text representing the user's intention, and match a target code tag corresponding to the demand text from a preset database according to the demand text. Then, an auxiliary code is generated through a large language model according to the demand text and the target code tag.
[0058] Understandably, Figure 1 The structure of the electronic device 100 shown in FIG. 1 is only a schematic diagram of a structure. The electronic device 100 may also include Figure 1 More components are shown. Figure 1 Each component shown in the figure can be implemented by hardware, software or a combination thereof.
[0059] Please refer to Figure 2The present application also provides an auxiliary code generation method based on a large language model, which can be applied to the above electronic device 100, and each step in the method is performed or implemented by the electronic device 100. The auxiliary code generation method based on a large language model can include the following steps:
[0060] Step 210, obtaining a demand text representing the user's intention;
[0061] Step 220, according to the requirement text, matching the target code tag corresponding to the requirement text from a preset database;
[0062] Step 230: Generate an auxiliary code corresponding to the requirement text through a preset large language model according to the requirement text and the target code label.
[0063] In the above implementation, the requirement text representing the user's intention is first obtained. Then, according to the requirement text, the target code tag corresponding to the requirement text is matched from the preset database. Then, according to the requirement text and the target code tag, the auxiliary code corresponding to the requirement text is generated by the preset large language model. In this way, the user's needs are used as the function of generating code, and the target code tag is used as the background description for subsequent code generation. Finally, the auxiliary code is generated based on the user's needs and the target code tag through the large language model, so that the generated code corresponds to the user's needs, and the code is more complete and adaptable, thereby improving the problems of inflexible generation guidance and incomplete generated content in the traditional code generation method.
[0064] The following is a detailed description of the steps of the auxiliary code generation method based on the large language model:
[0065] Prior to step 210, the method may include:
[0066] Acquire an original code set, wherein the original code set includes a plurality of original codes;
[0067] According to the original code set, determining a code label corresponding to each of the plurality of original codes by using the preset large language model, wherein the code label includes a function label and an edit label, wherein the function label represents a purpose achieved by the original code, and the edit label represents a calculation process and parameters required to achieve the purpose;
[0068] According to the code label, a database including the code label corresponding to each original code is constructed as the preset database.
[0069] In this embodiment, the original code can be understood as a code library, which contains a large amount of code that the user may use during the programming process, and serves as the data basis for subsequent code generation. In this embodiment, after obtaining the original code set, the code label of each original code in the original code set is identified by a preset large language model, and each code label may include a function label and an edit label (which can be understood as identifying the function or purpose, necessary parameters and operation process of the original code, and dividing it into a function label and an edit label, the function label records the function or purpose of the original code, and the edit label records the necessary parameters and operation process of the original code).
[0070] In this embodiment, after the code label corresponding to each original code is determined, all the code labels are stored in the same database as a preset database.
[0071] Before step 210, the method may further include:
[0072] Build a code optimizer based on the AIGC model as the initial code optimization model;
[0073] Acquire a training sample, wherein the training sample includes an original auxiliary code and a real optimized auxiliary code corresponding to the original auxiliary code;
[0074] Dividing the training samples into a training set and a test set according to a preset ratio as training data;
[0075] Performing semantic encoding, semantic optimization and semantic enhancement on the training data to obtain an enhanced training data encoding sequence corresponding to the training data;
[0076] Inputting the enhanced training data coding sequence into the initial code optimization model to generate a training optimization code corresponding to the enhanced training data coding sequence through the initial code optimization model;
[0077] Based on a preset loss function, calculating the loss value of the truly optimized auxiliary code and the training optimized code;
[0078] The initial code optimization model is trained according to the loss value until the loss function converges, and a trained initial code optimization model is obtained as the preset code optimization model.
[0079] Understandably, after the auxiliary code is generated, the generated code may fail to meet the user's needs because the expression of the user's demand text may deviate from the actual application of the code, or the original code input in advance can no longer adapt to the new code writing rules. Therefore, by building a code optimizer and training it, the generated auxiliary code is optimized using the trained code optimizer to improve the accuracy, usability and adaptability of code generation.
[0080] In this embodiment, a code optimizer is constructed based on a conventional AIGC model as an initial code optimization model. Then, a training sample input by a user is obtained, and the training sample contains the original auxiliary code and the corresponding real optimized code (which can be understood as the optimized auxiliary code, or the auxiliary code expected by the user), and the training sample is divided into a training set and a test set according to a preset ratio (flexibly set according to user needs, such as 8:2, 7:3, etc., and 8:2 is used as an example in this embodiment) as training data. Then, the training data is semantically encoded, semantically optimized, and semantically enhanced (refer to the description of semantic encoding, semantic optimization, and semantic enhancement in the following steps 240, 250, and 260), and an enhanced training data encoding sequence is obtained. Then, the enhanced training data encoding sequence is input into the aforementioned initial code optimization model to obtain the training optimization code generated by the initial code optimization model. And based on the preset loss function, the loss value between the training optimization code and the corresponding real optimized auxiliary code in the input enhanced training data encoding is calculated, and finally, the initial code optimization model is trained according to the loss value until the loss function converges, and the trained initial code optimization model is obtained as the preset code optimization model.
[0081] In step 210, after the aforementioned preset database and preset code optimization model are constructed, a requirement text representing the user's intention is obtained. The requirement text may be a text file or field input by the user that represents the auxiliary code function (i.e., the user's intention) and the necessary conditions for realizing the function. For example, if the user's intention is to generate a code that sums a and b, the requirement text may be "given a=3, b=4, sum a and b" that represents the code function.
[0082] In this embodiment, the demand text may be obtained by calling the text input by the user in the input box in real time, or the demand text may be edited by the user and stored in the memory 102 of the electronic device 100, and called based on the user's instructions in the subsequent generation process of the auxiliary code (also referred to as code). The method for obtaining the demand text is not specifically limited here.
[0083] In step 220, matching the target code tag corresponding to the requirement text from a preset database according to the requirement text may include:
[0084] Determining the similarity between the demand text and the code tag in the preset database according to the demand text and the preset database;
[0085] The similarities are sorted, and the first n code tags with the largest similarities are determined as the target code tags, where n is an integer greater than or equal to 2.
[0086] In this embodiment, determining the similarity between the requirement text and the code tag in the preset database according to the requirement text and the preset database may include:
[0087] Performing vector conversion on the demand text to obtain a first feature vector corresponding to the demand text;
[0088] Performing vector conversion on the function label in the code label to obtain a second feature vector corresponding to the code label;
[0089] The cosine similarity between the first eigenvector and the second eigenvector is determined as the similarity.
[0090] In this embodiment, the function labels in the requirement text and the code label are converted into the first feature vector and the second feature vector respectively, and then the cosine similarity between the two is calculated as the similarity, and the target code label is selected according to the similarity. In this way, the auxiliary code generated according to the target code label can be more adapted to the user's needs and the accuracy of code generation can be enhanced.
[0091] In this embodiment, the value of n can be flexibly set according to user needs, such as 2, 3, 4, etc. n is an integer greater than or equal to 2, that is, the number of target code tags is multiple, and the multiple target code tags are input into the preset large language model as background and requirement text to assist in code generation, thereby improving the integrity and adaptability of code generation.
[0092] In step 230, after obtaining the requirement text and the target code label, the requirement text and the target code label are input into the preset large language model to obtain the auxiliary code generated by the preset large language model. In this embodiment, the preset large language model can be flexibly set according to user needs. For example, the preset large language model can be ChatGPT, Wenxinyiyan, etc.
[0093] As an optional implementation, the method may further include:
[0094] Step 240, semantically encode the auxiliary code in units of sentence granularity to obtain a semantic encoding sequence corresponding to each code sentence in the auxiliary code;
[0095] Step 250, based on the semantic optimization formula, semantically optimize the semantic coding sequence to obtain an optimized coding sequence;
[0096] Step 260, based on the semantic enhancement formula, semantically enhance the optimized coding sequence to obtain an enhanced coding sequence;
[0097] Step 270, generating optimized auxiliary codes according to the enhanced coding sequence through a preset code optimization model.
[0098] In this embodiment, after the auxiliary code is generated through the above steps 210, 220 and 230, the auxiliary code is sequentially semantically encoded, semantically optimized and semantically enhanced to obtain an enhanced coding sequence. The enhanced coding sequence is then input into the preset code optimization model constructed above, and the optimized auxiliary code is output through the preset code optimization model. In this way, the initially generated auxiliary code is optimized so that the auxiliary code is more adapted to the needs of the user and has stronger stability, accuracy and adaptability.
[0099] In this embodiment, it is understandable that the auxiliary code is composed of multiple code statements. The sentence granularity is to take each code statement in the auxiliary code as a unit, perform semantic coding on all code statements, and obtain the semantic coding sequence corresponding to each code statement in the auxiliary code.
[0100] In this embodiment, the semantic optimization formula may be as follows:
[0101] A ij =f(W[x i ||x j(j≠i) ]) (1)
[0102]
[0103] In the formula, x i and x j denote the i-th and j-th semantic coding vectors in the semantic coding sequence, respectively, W denotes the preset weight feature vector, f(·) denotes the nonlinear activation function, [x i ||x j ] represents vector concatenation, A ij represents the element in the i-th row and j-th column of the autocorrelation feature matrix, exp(·) represents the exponential operation with the natural constant e as the base, n represents the number of semantic coding vectors in the semantic coding sequence minus one, and a ij represents the element in the i-th row and j-th column of the autocorrelation weight matrix, α and β represent trainable hyperparameters, σ1(·) represents the activation function, and x′ j Represents x i and x j The number of semantic encoding vectors between i represents the i-th optimized semantic encoding vector in the optimized encoding sequence.
[0104] In this embodiment, the i-th and j-th semantic coding vectors in the semantic coding sequence are first spliced (the splicing in this embodiment can be cascaded) and multiplied with a preset weight feature vector to obtain the autocorrelation feature between the i-th and j-th semantic coding vectors in the semantic coding sequence. The autocorrelation feature is then non-linearly activated to obtain the activated autocorrelation feature. The semantic coding vectors in the semantic coding sequence are then spliced without repetition and the corresponding activated autocorrelation features are obtained until all semantic coding vectors in the semantic coding sequence are traversed to obtain multiple activated autocorrelation features. An autocorrelation feature matrix is then constructed based on the multiple activated autocorrelation features, wherein each activated autocorrelation feature serves as an element of the autocorrelation feature matrix.
[0105] In this embodiment, after constructing the autocorrelation feature matrix, the autocorrelation weights corresponding to the i-th and j-th semantic coding vectors in the semantic coding sequence are calculated by formula (2), and all semantic coding vectors are traversed to obtain multiple autocorrelation weights. Then, an autocorrelation weight matrix is constructed based on the multiple autocorrelation weights.
[0106] In this embodiment, the autocorrelation weight matrix represents the correlation between different semantic coding vectors in the semantic coding sequence. Based on the autocorrelation weight matrix and the trainable hyperparameters, this embodiment performs weighted summation on the semantic coding sequence through formula (3) to achieve semantic optimization and obtain an optimized coding sequence.
[0107] In this embodiment, the semantic enhancement formula may be as follows:
[0108] X′=Avg(x′ i ) (4)
[0109] X″=Max(x′ i ) (5)
[0110]
[0111] y′ i = x′ i ⊙(tanh(B1+B2)⊙σ2(B1+B2))+x′ i (8)
[0112] In the formula, x′ i represents the i-th optimized semantic coding vector in the optimized coding sequence, Avg(·) represents the global mean in the calculation vector, Max(·) represents the maximum value in the calculation vector, Conv(·) represents a one-dimensional convolution operation, ReLU(·) represents the ReLU activation function, and denote the first trainable weight matrix and the second trainable weight matrix, respectively; B1 and B2 denote the context semantic mean feature vector and the context semantic maximum feature vector, respectively; tanh(·) is the tanh function; ⊙ denotes the dot product; y′ i Represents the i-th enhanced semantic encoding vector in the enhanced encoding sequence.
[0113] In this embodiment, in order to further improve the ability to understand the semantics of auxiliary codes, in this embodiment, the semantics of each code statement and important information and semantics related to the subsequent optimization tasks of the auxiliary code are captured through semantic enhancement formulas, helping users to better understand the logic and functions of the auxiliary code and improve the comprehensibility of the auxiliary code.
[0114] In this embodiment, by performing mean calculation and maximum calculation on each semantic coding vector in the optimized coding sequence, a global representation vector composed of multiple vector means and a semantically prominent representation vector composed of multiple vector maximum values are obtained respectively, and then the global representation vector and the semantically prominent representation vector are respectively subjected to one-dimensional convolution operation, ReLU activation operation, one-dimensional convolution operation and weighting operation respectively, to obtain a global feature vector corresponding to the global representation vector and a semantically prominent feature vector corresponding to the semantically prominent representation vector. Then, based on the global feature vector and the semantically prominent feature vector, the optimized coding sequence is weighted and summed by formula (8) to achieve semantic enhancement and obtain an enhanced coding sequence.
[0115] It should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the electronic device 100 described above can refer to the corresponding process of each step in the aforementioned method, and will not be elaborated herein.
[0116] The embodiment of the present application also provides a computer program product, including a computer program, and the computer program implements the above method when executed by the processor 101.
[0117] Through the description of the above implementation methods, technical personnel in this field can clearly understand that the present application can be implemented by hardware, and can also be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each implementation scenario of the present application.
[0118] In summary, the embodiments of the present application provide an auxiliary code generation method, electronic device and program product based on a large language model. In this technical solution, a demand text representing the user's intention is first obtained. Then, according to the demand text, a target code tag corresponding to the demand text is matched from a preset database. Then, according to the demand text and the target code tag, an auxiliary code corresponding to the demand text is generated through a preset large language model. In this way, user demand is used as the function of generating code, and the target code tag is used as the background description for subsequent code generation. Finally, the auxiliary code is generated based on the user demand and the target code tag through the large language model, so that the generated code corresponds to the user's demand, and the code is more complete and adaptable, thereby improving the problems of inflexible generation guidance and incomplete generation content in the traditional code generation method.
[0119] In the embodiments provided by the present application, it should be understood that the disclosed method can also be implemented in other ways. The method embodiments described above are merely schematic, for example, the flow charts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the methods and computer program products according to the multiple embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a part of a module, a program segment or a code, and a part of the module, a program segment or a code includes one or more executable instructions for realizing the specified logical function. It should also be noted that each box in the block diagram and / or the flow chart, and the combination of the boxes in the block diagram and / or the flow chart can be implemented by a dedicated hardware-based system that performs the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions. In addition, each functional module in each embodiment of the present application can be integrated together to form an independent part, or each module can exist separately, or two or more modules can be integrated to form an independent part.
[0120] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method for auxiliary code generation based on a large language model, characterized in that: The method comprises: Obtain the requirement text that represents the user's intention; According to the requirement text, matching the target code tag corresponding to the requirement text from a preset database; According to the requirement text and the target code label, an auxiliary code corresponding to the requirement text is generated through a preset large language model.
2. The method according to claim 1, characterized in that: Before obtaining the requirement text representing the user's intention, the method further includes: Acquire an original code set, wherein the original code set includes a plurality of original codes; According to the original code set, determining a code label corresponding to each of the plurality of original codes by using the preset large language model, wherein the code label includes a function label and an edit label, wherein the function label represents a purpose achieved by the original code, and the edit label represents a calculation process and parameters required to achieve the purpose; According to the code label, a database including the code label corresponding to each original code is constructed as the preset database.
3. The method according to claim 2, characterized in that The step of matching a target code tag corresponding to the requirement text from a preset database according to the requirement text includes: Determining the similarity between the demand text and the code tag in the preset database according to the demand text and the preset database; The similarities are sorted, and the first n code tags with the largest similarities are determined as the target code tags, where n is an integer greater than or equal to 2.
4. The method according to claim 3, characterized in that Determining the similarity between the demand text and the code tag in the preset database according to the demand text and the preset database includes: Performing vector conversion on the demand text to obtain a first feature vector corresponding to the demand text; Performing vector conversion on the function label in the code label to obtain a second feature vector corresponding to the code label; The cosine similarity between the first eigenvector and the second eigenvector is determined as the similarity.
5. The method according to claim 1, characterized in that The method further comprises: Semantically encoding the auxiliary code in units of sentence granularity to obtain a semantic encoding sequence corresponding to each code sentence in the auxiliary code; Based on the semantic optimization formula, semantic optimization is performed on the semantic coding sequence to obtain an optimized coding sequence; Based on the semantic enhancement formula, semantic enhancement is performed on the optimized coding sequence to obtain an enhanced coding sequence; According to the enhanced coding sequence, an optimized auxiliary code is generated through a preset code optimization model.
6. The method according to claim 5, characterized in that The semantic optimization formula is as follows: A ij =f(W[x i ||x j(j≠i) ]) In the formula, x i and x j denote the i-th and j-th semantic coding vectors in the semantic coding sequence, respectively, W denotes the preset weight feature vector, f(·) denotes the nonlinear activation function, [x i ||x j ] represents vector concatenation, A ij represents the element in the i-th row and j-th column of the autocorrelation feature matrix, exp(·) represents the exponential operation with the natural constant e as the base, n represents the number of semantic coding vectors in the semantic coding sequence minus one, and a ij represents the element in the i-th row and j-th column of the autocorrelation weight matrix, α and β represent trainable hyperparameters, σ1(·) represents the activation function, and x′ j Represents x i and x j The number of semantic encoding vectors separated by x| i represents the i-th optimized semantic encoding vector in the optimized encoding sequence.
7. The method according to claim 5, characterized in that The semantic enhancement formula is as follows: X′=Avg(x′ i ) X″=Max(x′ i ) y′ i =x′ i ⊙(tanh(B1+B2)⊙σ2(B1+B2))+x′ i In the formula, x′ i represents the i-th optimized semantic coding vector in the optimized coding sequence, Avg(·) represents the global mean in the calculation vector, Max(·) represents the maximum value in the calculation vector, Conv(·) represents a one-dimensional convolution operation, ReLU(·) represents the ReLU activation function, and denote the first trainable weight matrix and the second trainable weight matrix, respectively; B1 and B2 denote the context semantic mean feature vector and the context semantic maximum feature vector, respectively; tanh(·) is the tanh function; ⊙ denotes the dot product; y′ i Represents the i-th enhanced semantic encoding vector in the enhanced encoding sequence.
8. The method according to claim 5, characterized in that Before obtaining the requirement text representing the user's intention, the method further includes: Build a code optimizer based on the AIGC model as the initial code optimization model; Acquire a training sample, wherein the training sample includes an original auxiliary code and a real optimized auxiliary code corresponding to the original auxiliary code; Dividing the training samples into a training set and a test set according to a preset ratio as training data; Performing semantic encoding, semantic optimization and semantic enhancement on the training data to obtain an enhanced training data encoding sequence corresponding to the training data; Inputting the enhanced training data coding sequence into the initial code optimization model to generate a training optimization code corresponding to the enhanced training data coding sequence through the initial code optimization model; Based on a preset loss function, calculating the loss value of the truly optimized auxiliary code and the training optimized code; The initial code optimization model is trained according to the loss value until the loss function converges, and a trained initial code optimization model is obtained as the preset code optimization model.
9. An electronic device, characterized in that: The electronic device comprises a processor and a memory coupled to each other, wherein the memory stores a computer program. When the computer program is executed by the processor, the electronic device executes the method according to any one of claims 1 to 8.
10. A computer program product, characterized in that The invention comprises a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 8.