Method, apparatus, storage medium and electronic device for code generation

By adjusting the matrix structure of the code generation model and optimizing the model accuracy, the problem of insufficient application capabilities of the code generation model in the vertical field is solved, and more efficient code generation is achieved.

CN118276836BActive Publication Date: 2025-07-18FEISUANSHUZHI TECHNOLOGY (SHENZHEN) CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202410256487.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-06
Publication Date
2025-07-18
Estimated Expiration
2044-03-06

AI Technical Summary

Technical Problem

In the prior art, the code generation model has insufficient application capabilities in the vertical field, and has a long generation time and low accuracy, resulting in low work efficiency.

Method used

By adjusting the matrix structure of the target code generation model, using the target parameter matrix and the specified parameter matrix to generate the target matrix, combining the preset vector library and the target excitation model to optimize the accuracy of the code generation model, reducing the code generation time.

Benefits of technology

Improve the accuracy and work efficiency of code generation, expand the application scope of code generation, and reduce generation time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118276836B_ABST
    Figure CN118276836B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a method, apparatus, storage medium, and electronic device for code generation; obtaining an input statement input by a user; obtaining a target code corresponding to the input statement through a target code generation model according to the input statement; wherein, the target code generation model is obtained according to a target matrix; the target matrix is obtained according to a target parameter matrix and a specified parameter matrix; the target parameter matrix is used for feature extraction of the input statement; through the above technical solution, the matrix structure of the target code generation model can be adjusted to reduce the time for code generation and improve work efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of artificial intelligence technology, and more specifically, to a method, apparatus, storage medium, and electronic device for code generation. Background Art

[0002] Dialogue generation is to input a dialogue into a large model, and the large model generates a user response based on its own parameters and historical dialogue information. To ensure the application of the large model in various scenarios, the large model is trained on a corpus integrating various fields, so that the large model can meet the basic problems of users in multiple aspects such as information retrieval, academic questions, programming, etc.

[0003] Code generation is an in-depth application of dialogue generation in the programming direction, which solves the problem that the large model has a wide application direction but lacks capabilities in vertical fields. However, in the related art, code generation only targets some language types, resulting in a lack of capabilities in vertical fields and unable to be widely applied; moreover, the code generation takes a long time and has low accuracy, resulting in low work efficiency. Summary of the Invention

[0004] The present disclosure provides a method, apparatus, storage medium, and electronic device for code generation, which are used to improve the accuracy of code generation.

[0005] To achieve the above object, in a first aspect, the present disclosure provides a method for code generation; the method includes:

[0006] Obtain an input statement input by a user;

[0007] According to the input statement, obtain a target code corresponding to the input statement through a target code generation model;

[0008] Wherein, the target code generation model is obtained according to a target matrix; the target matrix is obtained according to a target parameter matrix and a specified parameter matrix; the target parameter matrix is used to extract features from the input statement.

[0009] Optionally, the target code generation model is generated in the following manner:

[0010] Obtain the target matrix according to the target parameter matrix and the specified parameter matrix;

[0011] Obtain the target code generation model according to the target matrix.

[0012] Optionally, the obtaining the target matrix according to the target parameter matrix and the specified parameter matrix includes:

[0013] Multiply the specified parameter matrix by the target parameter matrix to obtain the target matrix; or,

[0014] Parallelize the specified parameter matrix and the target parameter matrix to obtain the target matrix.

[0015] Optionally, the specified parameter matrix includes a first specified parameter matrix and a second specified parameter matrix; obtaining the target matrix according to the target parameter matrix and the specified parameter matrix includes:

[0016] Multiply the first specified parameter matrix by the target parameter matrix to obtain a candidate matrix;

[0017] Parallelize the candidate matrix and the second specified parameter matrix to obtain the target matrix.

[0018] Optionally, obtaining the target code corresponding to the input statement through the target code generation model according to the input statement includes:

[0019] Determine the target vector corresponding to the input statement through a preset vector library according to the input statement;

[0020] Obtain the target code through the target code generation model according to the input statement and the target vector.

[0021] Optionally, the method further includes:

[0022] Adjust the accuracy of the target code generation model through a target incentive model to obtain the adjusted target code generation model;

[0023] Obtaining the target code corresponding to the input statement through the target code generation model according to the input statement includes:

[0024] Obtain the target code corresponding to the input statement through the adjusted target code generation model according to the input statement.

[0025] Optionally, adjusting the accuracy of the target code generation model through the target incentive model to obtain the adjusted target code generation model includes:

[0026] Obtain multiple codes through the target code generation model according to a preset statement;

[0027] Use the multiple codes as the input of the target incentive model to obtain the output candidate code;

[0028] Adjust the accuracy of the target code generation model according to the candidate code.

[0029] In a second aspect, the present disclosure provides a code generation device; the device includes:

[0030] An acquisition module, configured to acquire an input statement input by a user;

[0031] A determination module, configured to obtain, according to the input statement, a target code corresponding to the input statement through a target code generation model;

[0032] Wherein, the target code generation model is determined according to a target matrix; the target matrix is obtained according to a target parameter matrix and a specified parameter matrix; the target parameter matrix is used for feature extraction of the input statement.

[0033] Optionally, the target code generation model is generated in the following manner:

[0034] Obtain the target matrix according to the target parameter matrix and the specified parameter matrix;

[0035] Obtain the target code generation model according to the target matrix.

[0036] Optionally, the obtaining the target matrix according to the target parameter matrix and the specified parameter matrix includes:

[0037] Multiply the specified parameter matrix by the target parameter matrix to obtain the target matrix; or,

[0038] Parallelize the specified parameter matrix and the target parameter matrix to obtain the target matrix.

[0039] Optionally, the specified parameter matrix includes a first specified parameter matrix and a second specified parameter matrix; the obtaining the target matrix according to the target parameter matrix and the specified parameter matrix includes:

[0040] Multiply the first specified parameter matrix by the target parameter matrix to obtain a candidate matrix;

[0041] Parallelize the candidate matrix and the second specified parameter matrix to obtain the target matrix.

[0042] Optionally, the acquisition module is configured to determine a target vector corresponding to the input statement through a preset vector library according to the input statement; and obtain the target code according to the input statement and the target vector through the target code generation model.

[0043] Optionally, the apparatus further includes an adjustment module;

[0044] The adjustment module is configured to adjust the accuracy of the target code generation model through a target excitation model to obtain the adjusted target code generation model;

[0045] The determining module is configured to obtain the target code corresponding to the input statement by using the adjusted target code generation model according to the input statement.

[0046] Optionally, the adjusting module is configured to obtain multiple codes by using the target code generation model according to a preset statement; use the multiple codes as inputs of the target incentive model to obtain candidate codes as output; and adjust the accuracy of the target code generation model according to the candidate codes.

[0047] In a third aspect, the present disclosure provides a non-transitory computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the steps of the code generation method described in the first aspect above are implemented.

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

[0049] A memory, on which a computer program is stored;

[0050] A processor, configured to execute the computer program in the memory to implement the steps of the code generation method described in the first aspect above.

[0051] Through the above technical solutions, the matrix structure of the target code generation model can be adjusted to reduce the code generation time and improve the work efficiency.

[0052] Other features and advantages of the present disclosure will be described in detail in the subsequent specific implementation section. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] The drawings are used to provide a further understanding of the present disclosure, and constitute a part of the specification. Together with the following specific implementation, they are used to explain the present disclosure, but do not constitute a limitation to the present disclosure. In the drawings:

[0054] Figure 1 is a flowchart of a code generation method shown according to an exemplary embodiment.

[0055] Figure 2 is a block diagram of a target matrix shown according to an exemplary embodiment.

[0056] Figure 3 is according to Figure 1 The flowchart of a code generation method shown according to an exemplary embodiment of.

[0057] Figure 4 is according to Figure 3 The flowchart of a code generation method shown according to an exemplary embodiment of.

[0058] Figure 5 is a flowchart of a method for code generation shown according to an exemplary embodiment of Figure 4 .

[0059] Figure 6 is a block diagram of an apparatus for code generation shown according to an exemplary embodiment.

[0060] Figure 7 is a block diagram of another apparatus for code generation shown according to an exemplary embodiment.

[0061] Figure 8 is according to Figure 7 an exemplary embodiment of

[0062] Figure 9 is a block diagram of an electronic device shown according to an exemplary embodiment.

[0063] Figure 10 is a block diagram of another electronic device shown according to an exemplary embodiment. Detailed Embodiments

[0064] The following will describe in detail the specific embodiments of the present disclosure with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only for explaining and illustrating the present disclosure, and are not used to limit the present disclosure.

[0065] First, the application scenarios of the present disclosure are introduced. The present disclosure is applied to the scenario of generating software code through a network model. In the related art, dialogue generation can be performed through a large model. A large model refers to a network model with a large number of parameters, and this network model can be a deep learning model or a machine learning model, etc., which is not limited herein.

[0066] Dialogue generation is to input a dialogue into a large model, and the large model generates a user response based on its own parameters and historical dialogue information. In order to ensure the application of the large model in various scenarios, the large model will be trained on a corpus integrating various fields, so that the large model can meet the basic problems of users in multiple aspects such as information retrieval, subject questions, and programming.

[0067] Code generation is a further application of dialogue generation in the programming direction, which solves the problem that the large model has a wide application direction but lacks vertical domain capabilities. However, code generation only targets some language types, resulting in a lack of capabilities in the vertical domain and unable to be widely applied; moreover, the time taken for code generation is long and the accuracy is not high, resulting in low work efficiency.

[0068] To solve the above problems, the present disclosure provides a method, apparatus, storage medium, and electronic device for code generation; obtaining an input statement input by a user; obtaining, according to the input statement, a target code corresponding to the input statement through a target code generation model; wherein, the target code generation model is obtained according to a target matrix; the target matrix is obtained according to a target parameter matrix and a specified parameter matrix; the target parameter matrix is used for feature extraction of the input statement; through the above technical solution, by adjusting the matrix structure of the target code generation model, the time for code generation can be reduced, and the work efficiency can be improved.

[0069] Figure 1 is a flowchart of a method for code generation shown according to an exemplary embodiment. As Figure 1 shown, the method may include the following steps:

[0070] S101. Obtain an input statement input by a user.

[0071] S102. Obtain, according to the input statement, a target code corresponding to the input statement through a target code generation model.

[0072] Wherein, the target code generation model is obtained according to a target matrix; the target matrix is obtained according to a target parameter matrix and a specified parameter matrix; the target parameter matrix is used for feature extraction of the input statement.

[0073] Exemplarily, the input statement may be converted into a corresponding multi-dimensional input vector; according to the multi-dimensional input vector, a multi-dimensional output vector corresponding to the multi-dimensional input vector is obtained through the target code generation model; the multi-dimensional output vector is converted into a corresponding target code.

[0074] Exemplarily, the multi-dimensional output vector corresponding to the multi-dimensional input vector may be obtained by performing an operation on the multi-dimensional input vector through the target matrix in the target code generation model; and the multi-dimensional output vector is converted into a corresponding target code.

[0075] Exemplarily, the target code model may be used to generate Python code to improve the generation ability of the code generation model in the field of Python code and expand the application scope of code generation.

[0076] It should be noted that the cross entropy may be calculated between the multi-dimensional output vector and a preset output vector, and backpropagation may be performed according to the gradient descent method to update each parameter in the specified parameter matrix, and the above steps are cyclically executed until the multi-dimensional output vector actually output by the target code generation model and the preset output vector are basically fitted, thereby completing the adjustment of the matrix parameters of the target code generation model.

[0077] Through the above technical solution, the matrix structure of the target code generation model can be adjusted to reduce the code generation time and improve work efficiency.

[0078] In some embodiments, the target code generation model can be generated in the following manner: obtaining the target matrix according to the target parameter matrix and the specified parameter matrix; obtaining the target code generation model according to the target matrix.

[0079] Exemplarily, the target code generation model can be obtained based on a preset network model. For example, the preset network model can be the open-source model ChatGLM2. The target parameter matrix can be the inherent parameter matrix of the preset network model, which is used to extract features from the input statements. The specified parameter matrix can be an added parameter matrix used to adjust the model structure. In this way, by adding the specified parameter matrix, the target code generation model can be fine-tuned, thereby reducing the number of parameters of the target code generation model and improving the code generation efficiency without increasing the running time.

[0080] In other embodiments, obtaining the target matrix according to the target parameter matrix and the specified parameter matrix may include: multiplying the specified parameter matrix by the target parameter matrix to obtain the target matrix; or, paralleling the specified parameter matrix with the target parameter matrix to obtain the target matrix.

[0081] Among them, the specified parameter matrix can be right-multiplied by the target parameter matrix to obtain the target matrix. Matrix right-multiplication means multiplying a multi-dimensional input vector by a matrix to obtain a multi-dimensional output vector. Multiple matrices in parallel means multiplying the multi-dimensional input vector by each matrix respectively to obtain operation results, and linearly adding the operation results to obtain a multi-dimensional output vector.

[0082] Exemplarily, the multi-dimensional input vector can be multiplied by the target parameter matrix and the specified parameter matrix to obtain the multi-dimensional output vector. Or, multiplying the multi-dimensional input vector by the target parameter matrix to obtain a first operation result; multiplying the multi-dimensional input vector by the specified parameter matrix to obtain a second operation result; and linearly adding the first operation result and the second operation result to obtain the multi-dimensional output vector.

[0083] For example, assume that the multi-dimensional input vector is X, the multi-dimensional output vector is H; the target parameter matrix includes the W matrix, and the specified parameter matrix includes the B matrix and the A matrix; then in the case of multiplying the specified parameter matrix by the target parameter matrix, the multi-dimensional output vector H = WBAX; in the case of paralleling the specified parameter matrix with the target parameter matrix, the multi-dimensional output vector H = WX + BAX.

[0084] It should be noted that the dimension of the W matrix is W ∈ R d×k, the dimension of matrix B is B ∈ R d×r , the dimension of A is B ∈ R r×k , where r is much smaller than min(d, k). In this way, the number of parameters of the model can be reduced by specifying the parameter matrix, and the training speed of the model is accelerated.

[0085] In some embodiments, the specified parameter matrix includes a first specified parameter matrix and a second specified parameter matrix; obtaining the target matrix according to the target parameter matrix and the specified parameter matrix may include: multiplying the first specified parameter matrix by the target parameter matrix to obtain a candidate matrix; parallelizing the candidate matrix with the second specified parameter matrix to obtain the target matrix.

[0086] Among them, the candidate matrix can be obtained by multiplying the specified parameter matrix by the target parameter matrix on the right. Exemplarily, the multi-dimensional input vector can be multiplied by the first specified parameter matrix and the target parameter matrix to obtain a third operation result; the multi-dimensional input vector can be multiplied by the second specified parameter matrix to obtain a fourth operation result; and the third operation result and the fourth operation result are linearly added to obtain the multi-dimensional output vector.

[0087] For example, as Figure 2 shown, assume that the multi-dimensional input vector is X and the multi-dimensional output vector is H; the target parameter matrix includes matrix W, the first specified parameter matrix may include matrix D and matrix C; the second specified parameter matrix may include matrix B and matrix A, then the multi-dimensional output vector H = WDCX + BAX.

[0088] Figure 3 is a flowchart of a method for code generation shown according to an exemplary embodiment of Figure 1 . As Figure 3 shown, the above step S101 may include:

[0089] S1011. According to the input statement, determine the target vector corresponding to the input statement through a preset vector library.

[0090] S1012. According to the input statement and the target vector, obtain the target code through the target code generation model.

[0091] Exemplarily, the preset vector library can be obtained in the following manner: obtain the document corresponding to the specified type of code; split the document into multiple segments; obtain the embedded vector words corresponding to each segment through a preset language model; according to the embedded vector words, obtain the corresponding vectors through a preset algorithm; the vectors are used to represent the content of each segment; obtain the preset vector library according to multiple such vectors.

[0092] Exemplarily, the corresponding target vector can be determined from the preset vector library according to the input statement through cosine similarity.

[0093] Exemplarily, the specified type of code can be Python code; the preset language model can be a Transformer model; the preset algorithm can be the Mean Pooling algorithm. The preset vector library can be trained by means of asymmetric semantic retrieval, so that the preset vector library can find corresponding code answers for relevant questions. In this way, the input statement of the user can be analyzed through the preset vector library to obtain a target vector, so as to improve the accuracy of the model's analysis of the input statement, thereby improving the accuracy of code generation and improving work efficiency.

[0094] Figure 4 is based on Figure 3 The flowchart of a code generation method shown in an exemplary embodiment of Figure 4 As shown in

[0095] S103. Adjust the accuracy of the target code generation model through the target incentive model to obtain the adjusted target code generation model.

[0096] S104. According to the input statement, use the adjusted target code generation model to obtain the target code corresponding to the input statement.

[0097] Exemplarily, the target incentive model can be obtained based on the GAN (Generative Adversarial Network). The target incentive model can be used as the generator of the GAN to generate the running results of the code. In this way, the target code generation model can be adjusted through the target incentive model to improve the accuracy of the code generation model, and further improve the accuracy of code generation.

[0098] Figure 5 is based on Figure 4 The flowchart of a code generation method shown in an exemplary embodiment of Figure 5 As shown in

[0099] S1031. According to the preset statement, obtain multiple codes through the target code generation model.

[0100] S1032. Use the multiple codes as the input of the target incentive model to obtain the output candidate codes.

[0101] S1033. Adjust the accuracy of the target code generation model according to the candidate codes.

[0102] In some embodiments, the above step S1032 may include: determining, by the target incentive model, a first running result of each piece of code; each first running result corresponding to a preset score; and taking the code with the highest preset score as the candidate code.

[0103] Exemplarily, the target incentive model may include unit tests; and the first running result of each code segment may be determined through the unit tests. The first running result may include passing all test cases, passing some test cases, running errors, or compilation errors. The preset score corresponding to passing all test cases may be 1.0; the preset score corresponding to passing some test cases may be -0.3; the preset score corresponding to running errors may be -0.6; and the preset score corresponding to compilation errors may be -1.0. In this way, the candidate code can be quickly determined according to the preset score, improving work efficiency.

[0104] In some other embodiments, multiple codes that pass all test cases may be determined through the target incentive model, and a target code set may be established; and a specified code in the target code set may be taken as the candidate code. In this way, the accuracy of the target code generation model can be further adjusted by high-quality codes, improving work efficiency.

[0105] In some embodiments, the second running result of each piece of code may be determined through a compiler; a discriminator may be used to determine whether there is a difference between the first running result and the second running result; in the case where it is determined that there is a difference between the first running result and the second running result, the accuracy of the discriminator may be adjusted according to the first running result and the second running result; and the accuracy of the target incentive model may be adjusted according to the adjusted discriminator.

[0106] Exemplarily, the discriminator may be obtained based on a GAN (Generative Adversarial Network), and the discriminator and the target incentive model (generator) may form the GAN. The second running result may include passing all test cases, passing some test cases, running errors, or compilation errors. Each second running result corresponds to a preset score, where the preset score corresponding to passing all test cases may be 1.0; the preset score corresponding to passing some test cases may be -0.3; the preset score corresponding to running errors may be -0.6; and the preset score corresponding to compilation errors may be -1.0. The discriminator may determine whether there is a difference between the first running result and the second running result through the preset scores of the first running result and the second running result.

[0107] It should be noted that the technical solutions for adjusting the accuracy of the discriminator and for adjusting the accuracy of the generator (target incentive model) according to the discriminator have been disclosed in relevant technical literature and will not be elaborated here.

[0108] In some other embodiments, the above step S1033 may include: obtaining a target character from the target code generation model according to the candidate code; determining the perplexity of the target code generation model according to the target character; the perplexity characterizes the accuracy of the target code generation model; the perplexity is negatively correlated with the accuracy of the target code generation model; repeating the steps of obtaining a target character from the target code generation model according to the candidate code and determining the perplexity of the target code generation model according to the target character until the perplexity is less than or equal to a preset perplexity threshold, and stopping adjusting the accuracy of the target code generation model according to the candidate code.

[0109] Exemplarily, target characters may be obtained from the target code generation model according to subsequences (from short to long) of the candidate code; the target characters may be Tokens; this can simplify the model generation steps and quickly adjust the model accuracy.

[0110] Exemplarily, the perplexity may characterize the probability of the target code generation model generating a sentence. Suppose a certain sentence S is composed of n words W, i.e., S = W1, W2, …, W n ; then the probability of generating this sentence by the target code generation model is:

[0111] P(S) = P(W1, W2, …, W N ) = P(W1)P(W2|W1) … P(W n |W1, W2, …, W k-1 );

[0112] Then the perplexity (PPL) can be determined by the following formula:

[0113]

[0114] Exemplarily, according to the perplexity, each parameter of the specified parameter matrix of the target code generation model can be updated by backpropagation until the multi-dimensional output vector actually output by the target code generation model and the preset output vector are basically fitted, thereby completing the further adjustment of the matrix parameters of the target code generation model.

[0115] In some other embodiments, the target code generation model may include a fusion calculation module; the fusion calculation module is obtained by fusing multiple calculation modules. Exemplarily, the calculation module may be an operator (OP) for implementing an operation process; the operation process may be addition, multiplication, exponentiation, etc. Since each operation needs to call an operator, occupying video memory reading and writing, a large amount of video memory reading and writing will be occupied during the operation process. By fusing multiple calculation modules, the number of video memory accesses can be reduced during the operation process, improving the working efficiency of the model.

[0116] Figure 6 is a block diagram of a code generation device shown according to an exemplary embodiment. As Figure 6 shown, the device may include a preset vector library, a target code generation model, a target excitation model, a compiler, and a discriminator.

[0117] First, an input statement of a user can be obtained; and a target vector corresponding to the input statement can be determined through the preset vector library; according to the input statement and the target vector, an output code can be obtained through the target code generation model.

[0118] Second, a preset statement can be obtained, and a vector corresponding to the preset statement can be determined through the preset vector library; according to the input statement and the vector, a plurality of output codes can be obtained through the target code generation model. Then, the plurality of codes are used as inputs to the target excitation model to obtain candidate codes as outputs. The candidate codes are input into the target code generation model to adjust the accuracy of the target code generation model.

[0119] Third, according to the plurality of output codes, a first operation result can be obtained through the target excitation model; according to the plurality of output codes, a second operation result can be obtained through the compiler; the first operation result and the second operation result are input into the discriminator, and the discriminator is used to determine whether there is a difference between the first operation result and the second operation result. In the case where it is determined that there is a difference between the first operation result and the second operation result, the accuracy of the discriminator is adjusted according to the first operation result and the second operation result. Then, the first operation result and the second operation result are input into the target excitation model to adjust the accuracy of the target excitation model.

[0120] Through the above technical solution, by adjusting the matrix structure of the target code generation model, the time for code generation can be reduced, and the work efficiency can be improved.

[0121] Figure 7 is a block diagram of another code generation device shown according to an exemplary embodiment. As Figure 7 shown, the device 700 may include an acquisition module 710 and a determination module 720;

[0122] The acquisition module 710 is configured to acquire an input statement input by a user;

[0123] The determination module 720 is configured to obtain a target code corresponding to the input statement through the target code generation model according to the input statement;

[0124] Wherein, the target code generation model is determined according to a target matrix; the target matrix is obtained according to a target parameter matrix and a specified parameter matrix; the target parameter matrix is used for feature extraction of the input statement.

[0125] Through the above technical solution, the matrix structure of the target code generation model can be adjusted to reduce the time for code generation and improve work efficiency.

[0126] Optionally, the target code generation model is generated in the following manner:

[0127] Obtain the target matrix based on the target parameter matrix and the specified parameter matrix;

[0128] Obtain the target code generation model based on the target matrix.

[0129] Optionally, obtaining the target matrix based on the target parameter matrix and the specified parameter matrix includes:

[0130] Multiply the specified parameter matrix by the target parameter matrix to obtain the target matrix; or,

[0131] Parallelize the specified parameter matrix and the target parameter matrix to obtain the target matrix.

[0132] Optionally, the specified parameter matrix includes a first specified parameter matrix and a second specified parameter matrix; obtaining the target matrix based on the target parameter matrix and the specified parameter matrix includes:

[0133] Multiply the first specified parameter matrix by the target parameter matrix to obtain a candidate matrix;

[0134] Parallelize the candidate matrix and the second specified parameter matrix to obtain the target matrix.

[0135] Optionally, the obtaining module 710 is configured to determine a target vector corresponding to the input statement through a preset vector library according to the input statement; and obtain the target code according to the input statement and the target vector through the target code generation model.

[0136] Figure 8 is a block diagram of a code generation device shown according to an exemplary embodiment of. As Figure 7 shown, the device 700 may further include an adjustment module 730; Figure 8 As

[0137] The adjustment module 730 is configured to adjust the accuracy of the target code generation model through a target excitation model to obtain the adjusted target code generation model;

[0138] The determination module 720 is configured to obtain the target code corresponding to the input statement according to the input statement through the adjusted target code generation model.

[0139] Optionally, the adjustment module 730 is configured to obtain multiple codes through the target code generation model according to a preset statement; use the multiple codes as inputs to the target incentive model to obtain candidate codes as outputs; and adjust the accuracy of the target code generation model according to the candidate codes.

[0140] Regarding the apparatus in the above embodiments, the specific manners in which each module performs operations have been described in detail in the embodiments related to the method, and will not be elaborated herein.

[0141] In summary, the present disclosure provides a method, apparatus, storage medium, and electronic device for code generation; obtaining an input statement input by a user; obtaining a target code corresponding to the input statement through a target code generation model according to the input statement; wherein the target code generation model is obtained according to a target matrix; the target matrix is obtained according to a target parameter matrix and a specified parameter matrix; the target parameter matrix is used for feature extraction of the input statement; through the above technical solution, the matrix structure of the target code generation model can be adjusted to reduce the time for code generation and improve work efficiency.

[0142] Figure 9 is a block diagram of an electronic device 900 shown according to an exemplary embodiment. As Figure 9 shown, the electronic device 900 may include: a processor 901, a memory 902. The electronic device 900 may further include one or more of a multimedia component 903, an input / output interface 904, and a communication component 905.

[0143] Among them, the processor 901 is used to control the overall operation of the electronic device 900 to complete all or part of the steps in the above-mentioned code generation method. The memory 902 is used to store various types of data to support the operation of the electronic device 900. These data may include, for example, instructions for any application or method operating on the electronic device 900, as well as application-related data, such as contact data, received and sent messages, pictures, audio, video, and so on. The memory 902 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic memory, flash memory, a magnetic disk, or an optical disc. The multimedia component 903 may include a screen and an audio component. The screen may be, for example, a touch screen, and the audio component is used to output and / or input audio signals. For example, the audio component may include a microphone for receiving external audio signals. The received audio signal may be further stored in the memory 902 or sent through the communication component 905. The audio component also includes at least one speaker for outputting audio signals. The input / output interface 904 provides an interface between the processor 901 and other interface modules, and the above-mentioned other interface modules may be a keyboard, a mouse, buttons, etc. These buttons may be virtual buttons or physical buttons. The communication component 905 is used for wired or wireless communication between the electronic device 900 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G, 4G, NB-IoT, eMTC, or other 5G, etc., or a combination of one or more of them, is not limited herein. Therefore, the corresponding communication component 905 may include: a Wi-Fi module, a Bluetooth module, an NFC module, and so on.

[0144] In an exemplary embodiment, the electronic device 900 can be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components, and is used to execute the above-mentioned code generation method.

[0145] In another exemplary embodiment, a computer-readable storage medium including program instructions is further provided. When the program instructions are executed by a processor, the steps of the above-mentioned code generation method are implemented. For example, the computer-readable storage medium can be the above-mentioned memory 902 including program instructions, and the above-mentioned program instructions can be executed by the processor 901 of the electronic device 900 to complete the above-mentioned code generation method.

[0146] Figure 10 is a block diagram of another electronic device 1000 shown according to an exemplary embodiment. For example, the electronic device 1000 can be provided as a server. Referring to Figure 10 , the electronic device 1000 includes a processor 1022, the number of which can be one or more, and a memory 1032 for storing computer programs executable by the processor 1022. The computer programs stored in the memory 1032 can include one or more modules each corresponding to a set of instructions. In addition, the processor 1022 can be configured to execute the computer program to execute the above-mentioned code generation method.

[0147] In addition, the electronic device 1000 can further include a power supply component 1026 and a communication component 1050. The power supply component 1026 can be configured to perform power management of the electronic device 1000, and the communication component 1050 can be configured to implement communication of the electronic device 1000, for example, wired or wireless communication. In addition, the electronic device 1000 can further include an input / output interface 1058. The electronic device 1000 can operate based on an operating system stored in the memory 1032.

[0148] In another exemplary embodiment, there is also provided a computer-readable storage medium including program instructions which, when executed by a processor, implement the steps of the above-described code generation method. For example, the non-transitory computer-readable storage medium may be the above-described memory 1032 including program instructions, and the above program instructions may be executed by the processor 1022 of the electronic device 1000 to complete the above-described code generation method.

[0149] In another exemplary embodiment, there is also provided a computer program product which includes a computer program capable of being executed by a programmable device, and the computer program has a code portion for executing the above-described code generation method when executed by the programmable device.

[0150] The preferred embodiments of the present disclosure have been described in detail above in conjunction with the accompanying drawings. However, the present disclosure is not limited to the specific details in the above embodiments. Within the scope of the technical concept of the present disclosure, various simple modifications can be made to the technical solutions of the present disclosure, and these simple modifications all fall within the protection scope of the present disclosure.

[0151] In addition, it should be noted that, in the above specific embodiments, the various specific technical features described can be combined in any suitable manner without conflict. To avoid unnecessary repetition, the present disclosure does not separately describe various possible combination manners.

[0152] In addition, any combination can be made between various different embodiments of the present disclosure as long as it does not violate the idea of the present disclosure, and it should also be regarded as the content disclosed by the present disclosure.

Claims

1. A method for code generation, characterized in that, The method includes: Obtain an input statement entered by a user; According to the input statement, obtain target code corresponding to the input statement through a target code generation model; Among them, the target code generation model is obtained according to a target matrix; the target matrix is obtained according to a target parameter matrix and a specified parameter matrix; the target parameter matrix is used to perform feature extraction on the input statement; The method further includes: Adjust the accuracy of the target code generation model through a target excitation model to obtain the adjusted target code generation model, where the target excitation model is obtained based on a GAN (Generative Adversarial Network); The step of obtaining target code corresponding to the input statement through the target code generation model according to the input statement includes: According to the input statement, obtain the target code corresponding to the input statement through the adjusted target code generation model; The step of adjusting the accuracy of the target code generation model through the target excitation model to obtain the adjusted target code generation model includes: According to a preset statement, obtain multiple codes through the target code generation model; Use the multiple codes as the input of the target excitation model to obtain candidate codes as output; Adjust the accuracy of the target code generation model according to the candidate codes; The step of adjusting the accuracy of the target code generation model according to the candidate codes includes: According to the candidate codes, obtain target characters through the target code generation model; Determine the perplexity of the target code generation model according to the target characters; the perplexity characterizes the accuracy of the target code generation model, and the perplexity is negatively correlated with the accuracy of the target code generation model; Repeat the steps of obtaining target characters through the target code generation model according to the candidate codes and determining the perplexity of the target code generation model according to the target characters until the perplexity is less than or equal to a preset perplexity threshold, and stop adjusting the accuracy of the target code generation model according to the candidate codes; The step of obtaining target code corresponding to the input statement through the target code generation model according to the input statement includes: Convert the input statement into a corresponding multi-dimensional input vector; obtain a multi-dimensional output vector corresponding to the multi-dimensional input vector through the target code generation model according to the multi-dimensional input vector; convert the multi-dimensional output vector into the corresponding target code; The matrix parameters of the target code generation model are adjusted in the following manner: Calculate the cross-entropy between the multi-dimensional output vector and a preset output vector; Perform backpropagation according to the gradient descent method to update each parameter in the specified parameter matrix; Loop through the step of calculating the cross-entropy between the multi-dimensional output vector and the preset output vector to the step of performing backpropagation according to the gradient descent method until the multi-dimensional output vector actually output by the target code generation model and the preset output vector are basically fitted.

2. The method according to claim 1, wherein The target code generation model is generated in the following manner: Obtain the target matrix according to the target parameter matrix and the specified parameter matrix; The target code generation model is obtained based on the target matrix.

3. The method according to claim 2, wherein The obtaining of the target matrix according to the target parameter matrix and the specified parameter matrix includes: multiplying the specified parameter matrix by the target parameter matrix to obtain the target matrix; or, parallelizing the specified parameter matrix and the target parameter matrix to obtain the target matrix.

4. The method according to claim 2, characterized in that, The specified parameter matrix includes a first specified parameter matrix and a second specified parameter matrix; the obtaining of the target matrix according to the target parameter matrix and the specified parameter matrix includes: multiplying the first specified parameter matrix by the target parameter matrix to obtain a candidate matrix; parallelizing the candidate matrix and the second specified parameter matrix to obtain the target matrix.

5. The method according to claim 1, wherein The obtaining of the target code corresponding to the input statement through the target code generation model according to the input statement includes: determining a target vector corresponding to the input statement through a preset vector library according to the input statement; obtaining the target code through the target code generation model according to the input statement and the target vector.

6. A code generation device, characterized in that, The apparatus includes: an obtaining module, configured to obtain an input statement input by a user; a determining module, configured to obtain a target code corresponding to the input statement through a target code generation model according to the input statement; wherein, the target code generation model is determined according to a target matrix; the target matrix is obtained according to a target parameter matrix and a specified parameter matrix; the target parameter matrix is used for feature extraction of the input statement; an adjustment module, configured to adjust the accuracy of the target code generation model through a target incentive model to obtain the adjusted target code generation model, and the target incentive model is obtained based on a GAN (Generative Adversarial Network); the determining module is further configured to obtain the target code corresponding to the input statement through the adjusted target code generation model according to the input statement; the adjustment module is configured to obtain multiple codes through the target code generation model according to a preset statement; use the multiple codes as inputs of the target incentive model to obtain candidate codes output; and adjust the accuracy of the target code generation model according to the candidate codes; The adjusting the accuracy of the target code generation model according to the candidate codes includes: obtaining target characters through the target code generation model according to the candidate codes; determining the perplexity of the target code generation model according to the target characters; the perplexity characterizes the accuracy of the target code generation model, and the perplexity is negatively correlated with the accuracy of the target code generation model; repeating the steps of obtaining target characters through the target code generation model according to the candidate codes and determining the perplexity of the target code generation model according to the target characters until the perplexity is less than or equal to a preset perplexity threshold, and stopping adjusting the accuracy of the target code generation model according to the candidate codes; The obtaining of the target code corresponding to the input statement through the target code generation model according to the input statement includes: Convert the input statement into a corresponding multi-dimensional input vector; obtain a multi-dimensional output vector corresponding to the multi-dimensional input vector through the target code generation model according to the multi-dimensional input vector; convert the multi-dimensional output vector into a corresponding target code; The matrix parameters of the target code generation model are adjusted in the following manner: Calculate the cross-entropy between the multi-dimensional output vector and a preset output vector; Perform backpropagation according to the gradient descent method to update each parameter in the specified parameter matrix; Loop through the steps of calculating the cross-entropy between the multi-dimensional output vector and the preset output vector to the step of performing backpropagation according to the gradient descent method until the multi-dimensional output vector actually output by the target code generation model and the preset output vector are basically fitted.

7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by a processor, it implements the steps of the method described in any one of claims 1-5.

8. An electronic device, characterized in that, Comprising: A memory having a computer program stored thereon; A processor for executing the computer program in the memory to implement the steps of the method described in any one of claims 1-5.

Citation Information

Patent Citations

  • Conversation generation method and device based on artificial intelligence, equipment and storage medium

    CN110457459A

  • Code generation method and device, storage medium and electronic equipment

    CN116166271A

  • Dialogue response method and device based on large language model

    CN117273067A