CN110489110B - Code generation method and device based on deep learning - Google Patents

Code generation method and device based on deep learning Download PDF

Info

Publication number
CN110489110B
CN110489110B CN201910770155.6A CN201910770155A CN110489110B CN 110489110 B CN110489110 B CN 110489110B CN 201910770155 A CN201910770155 A CN 201910770155A CN 110489110 B CN110489110 B CN 110489110B
Authority
CN
China
Prior art keywords
neural network
code
word
code object
output
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910770155.6A
Other languages
Chinese (zh)
Other versions
CN110489110A (en
Inventor
赵旸
刘思凡
邱旻峰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201910770155.6A priority Critical patent/CN110489110B/en
Publication of CN110489110A publication Critical patent/CN110489110A/en
Application granted granted Critical
Publication of CN110489110B publication Critical patent/CN110489110B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/36Software reuse
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Machine Translation (AREA)

Abstract

The invention provides a code generation method and a device based on deep learning, which are used for obtaining word vectors of words in natural language description contents to be processed after the natural language description contents to be processed are obtained, calling a preset neural network model to obtain code objects corresponding to the word vectors output by the preset neural network model, and generating codes corresponding to the natural language description to be processed based on the code objects corresponding to the word vectors, wherein the preset neural network model indicates the mapping relation between the word vectors of the words in the natural language description contents to be processed and the code objects in the standard codes to be processed, so that the code objects matched with the natural language description contents to be processed can be obtained from the standard codes by calling the preset neural network model after the word vectors of the words in the natural language description contents to be processed are obtained, and multiplexing of the code objects in the standard codes to be processed is realized.

Description

Code generation method and device based on deep learning
Technical Field
The invention belongs to the technical field of software engineering, and particularly relates to a code generation method and device based on deep learning.
Background
In the Application (APP) development process, the user needs are changeable and the APP development scale is increased, so that the APP development period is prolonged and the cost is increased, codes with similar logic among APPs can be extracted and reused for different APPs to be developed, for example, the role check and the game prop shipment in the game type APP are of similar logic, and the codes with corresponding role check and game prop shipment are reusable.
However, at present, all codes of similar logic in different APP need to be independently developed by program developers, so that a deep learning-based code generation method and device capable of realizing code multiplexing are needed.
Disclosure of Invention
In view of the above, the present invention aims to provide a code generation method and device based on deep learning, which realize multiplexing of existing standard codes. The technical proposal is as follows:
the invention provides a code generation method based on deep learning, which comprises the following steps:
acquiring natural language description content to be processed;
obtaining word vectors of all words in the natural language description content to be processed;
calling a preset neural network model to obtain each code object corresponding to the word vector output by the preset neural network model, wherein the preset neural network model indicates the mapping relation between the word vector of each word in the existing natural language description content and each code object in the existing standard code;
And generating codes corresponding to the natural language description contents to be processed based on the code objects corresponding to the word vectors.
Preferably, the calling a preset neural network model to obtain each code object corresponding to the word vector output by the preset neural network model includes:
calling a first neural network layer of the preset neural network model to obtain words matched with the word vectors output by the first neural network layer;
taking the words matched with the word vectors as the input of the attention layer of the preset neural network model, and obtaining each code object vector output by the attention layer;
and calling a second neural network layer of the preset neural network model to obtain code objects matched with each code object vector output by the second neural network layer.
Preferably, the obtaining each code object vector output by the attention layer by using the word matched by each word vector as the input of the attention layer of the preset neural network model includes: after each word matched with the word vector is input into the attention layer, the following steps are executed to obtain a code object vector:
Acquiring a last code object output by the second neural network layer before the word is input;
inferring a relationship between a code object to be output by the second neural network layer and the word based on the last code object;
and obtaining a code object vector output by the second neural network layer currently based on the relation between the code object to be output by the second neural network layer and each word.
Preferably, said deducing, based on said last code object, a relationship between a code object to be output by said second neural network layer and each of said words comprises:
performing dot product on the last code object and each word to obtain dot product results of each word;
and obtaining weights of the words based on dot product results of the words, wherein the weights of the words represent the relation between the code objects to be output by the second neural network layer and the words.
Preferably, the training process of the preset neural network model includes:
taking word vectors of words in the existing natural language description content as a first input, and taking code objects in the existing standard codes corresponding to the existing natural language description content as a second input;
Obtaining a word matched with the first input and a code object vector of the second input;
training model parameters of a first neural network layer, an attention layer and a second neural network layer of the preset neural network model through the first input, the second input, the words matched by the first input and the code object vectors of the second input so as to obtain the preset neural network model.
Preferably, the first code object output by the preset neural network model is a code object indicating the start of the prediction code, and the last code object output by the preset neural network model is a code object indicating the end of the prediction code.
The invention also provides a code generation device based on deep learning, which comprises:
the acquisition unit is used for acquiring natural language description contents to be processed;
the obtaining unit is used for obtaining word vectors of all words in the natural language description content to be processed;
the calling unit is used for calling a preset neural network model to obtain each code object corresponding to the word vector output by the preset neural network model, wherein the preset neural network model indicates the mapping relation between the word vector of each word in the existing natural language description content and each code object in the existing standard code;
And the generating unit is used for generating codes corresponding to the natural language description contents to be processed based on the code objects corresponding to the word vectors.
Preferably, the apparatus further comprises: the training unit is used for taking word vectors of words in the existing natural language descriptive contents as first input, taking code objects in the existing standard codes corresponding to the existing natural language descriptive contents as second input and obtaining words matched with the first input and code object vectors of the second input; training model parameters of a first neural network layer, an attention layer and a second neural network layer of the preset neural network model through the first input, the second input, the words matched by the first input and the code object vectors of the second input so as to obtain the preset neural network model.
The invention also provides a terminal, which comprises a memory and a processor;
wherein the processor is configured to execute a program stored in the memory;
the memory is used for storing a program, and the program is used for at least:
acquiring natural language description content to be processed;
obtaining word vectors of all words in the natural language description content to be processed;
Calling a preset neural network model to obtain each code object corresponding to the word vector output by the preset neural network model, wherein the preset neural network model indicates the mapping relation between the word vector of each word in the existing natural language description content and each code object in the existing standard code;
and generating codes corresponding to the natural language description contents to be processed based on the code objects corresponding to the word vectors.
The invention also provides a storage medium, wherein the storage medium stores computer executable instructions, and the computer executable instructions realize the code generation method based on deep learning when being loaded and executed by a processor.
According to the technical scheme, after the to-be-processed natural language description content is obtained, the word vector of each word in the to-be-processed natural language description content is obtained, the preset neural network model is called, each code object corresponding to the word vector output by the preset neural network model is obtained, codes corresponding to the to-be-processed natural language description are generated based on each code object corresponding to the word vector, wherein the preset neural network model indicates the mapping relation between the word vector of each word in the existing natural language description content and each code object in the existing standard code, therefore, after the word vector of each word in the to-be-processed natural language description content is obtained, the code object matched with the to-be-processed natural language description content can be obtained from the existing standard code by calling the preset neural network model, multiplexing of the code objects in the existing standard code is achieved, and then the code objects in the existing standard code can be shared, the code development difficulty is reduced, and the code objects in the existing standard code objects are successfully compiled, so that when the codes corresponding to the to-be-processed natural language description content are generated based on the successfully compiled code objects, the probability of the to be poor quality is reduced, and the code quality is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a code generation method based on deep learning provided by an embodiment of the invention;
FIG. 2 is a schematic diagram of a resulting code object provided by an embodiment of the present invention;
FIG. 3 is a schematic diagram of a natural language description to be processed and words included in the natural language description provided in an embodiment of the present invention;
FIG. 4 is a schematic diagram of generating codes corresponding to the natural language description to be processed shown in FIG. 3;
FIG. 5 is a schematic diagram of another natural language description to be processed and words included therein provided by an embodiment of the present invention;
FIG. 6 is a schematic diagram of generating code corresponding to the natural language description to be processed shown in FIG. 5;
FIG. 7 is a flow chart of another method for generating code based on deep learning provided by an embodiment of the present invention;
Fig. 8 is a schematic diagram of a training process of a preset neural network model in a deep learning-based code generation method according to an embodiment of the present invention;
fig. 9 is a schematic structural diagram of a code generating device based on deep learning according to an embodiment of the present invention;
fig. 10 is a schematic structural diagram of another code generating device based on deep learning according to an embodiment of the present invention;
fig. 11 is a schematic structural diagram of a terminal according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Before explaining the present invention in further detail, terms and terminology involved in the embodiments of the present invention are explained, and the terms and terminology involved in the embodiments of the present invention are applicable to the following explanation.
Code object: also denoted token, is an object in code that has a specific meaning, and contains member variables such as type, value, etc. The types and values of common token are shown in Table 1 below, but are not limited to Table 1 below:
TABLE 1 type and value of token
Type(s) Value of
Variable $a,x
Operator ->,!=,+,-
Keyword for,in,while,return,continue
String “this is an example”
Comment //must be negative
Long-term memory network: the (LSTM) network is a time-loop neural network designed to solve the Long-Term dependence problem of the loop neural network (Recurrent Neural Network, RNN).
The Attention mechanism: also known as an attention mechanism, is used to analyze the importance of each word in the entire sentence (e.g., the natural language descriptive content to be processed and the existing natural language descriptive content in the present invention), and to assign a higher weight to the more important words in the sentence.
word2vec: vectors of words are generated through the probability model, and the distance between the vectors reflects the correlation between the words.
Jieba: the junction word segmentation device is a python word segmentation component.
Chinese Word Vectors: the word vector corpus provides words and word vectors corresponding to the words.
softmax function: mapping the outputs of a plurality of neurons to the (0, 1) interval can be understood as obtaining a probability distribution of the neuron outputs, with a larger value indicating a greater importance of the neuron outputs.
Referring to fig. 1, a flowchart of a code generation method based on deep learning according to an embodiment of the present invention is shown, and the method may include the following steps:
100: and acquiring the natural language description content to be processed. It will be appreciated that: the natural language description content to be processed is a piece of text or a sentence to be generated of the code and described in natural language, and the natural language description content to be processed is related to a function of the code to be generated. And what the natural language description content to be processed includes depends on the function of the code to be generated, this embodiment is not limited.
200: and obtaining word vectors of all words in the natural language description content to be processed. The term vector of each term is a vector representation of each term, and one way to obtain the term vector in this embodiment is as follows:
the method comprises the steps of word segmentation of natural language descriptive contents to be processed, and obtaining various words included in the natural language descriptive contents to be processed, for example, using jieba, snowNLP (which is a natural language processing Python library and supports word segmentation of the natural language descriptive contents), and word segmentation tools such as pynlpir and thulac to segment the natural language descriptive contents to be processed.
After each word included in the natural language description to be processed is obtained, a vector generation tool such as at least one algorithm of word2vec algorithm, one-hot coding, fastatex algorithm and glove algorithm can be adopted to generate a word vector of each word, or a word vector corpus such as Chinese Word Vectors is adopted to obtain the word vector of each word from the word vector corpus. If the word vector of the word is not obtained from the word vector corpus, the word vector of the word can be generated in combination with a vector generation tool.
The points to be described here are: if a vector generation tool is used to generate word vectors for each word, then each word included in the existing natural language description and the word vector (known) for each word included in the existing natural language description may be used to train the vector generation tool so that after the natural language description to be processed is obtained, the vector generation tool may be used to generate an accurate word vector.
300: and calling a preset neural network model to obtain each code object corresponding to the word vector output by the preset neural network model, wherein the preset neural network model is trained by the existing natural language description content and the existing standard codes corresponding to the existing natural language description content, so that the preset neural network model indicates the mapping relation between the word vector of each word in the existing natural language description content and each code object in the existing standard codes, and therefore, when the preset neural network model is called, the code objects in the existing standard codes can be output through the preset neural network model, and multiplexing of codes is realized.
In this embodiment, calling a preset neural network model to obtain each code object corresponding to a word vector output by the preset neural network model refers to: and taking each word vector as the input of a preset neural network model to obtain each code object output by the preset neural network model. It should be noted here that: the preset neural network model is to output each code object one by one, but each input is all word vectors.
One possible way in which to obtain the individual code objects is: calling a first neural network layer of a preset neural network model to obtain words matched with each word vector output by the first neural network layer; the words matched with the word vectors are used as the input of the attention layer of the preset neural network model, and each code object vector output by the attention layer is obtained; and calling a second neural network layer of the preset neural network model to obtain code objects matched with each code object vector output by the second neural network layer.
The following description is made with reference to the accompanying drawings, and as shown in fig. 2, the process of outputting code objects one by a preset neural network model is shown, in fig. 2, a bidirectional LSTM network layer is taken as an example of a first neural network layer and a second neural network layer, and of course, the first neural network layer and the second neural network layer may also adopt an RNN network, a GRU (Gated Recurrent Unit) network and a unidirectional LSTM network, but experiments prove that the prediction effect of the bidirectional LSTM network is optimal, because the bidirectional LSTM network can effectively capture the grammar relationship from front to back and from back to front in the natural language description content to be processed.
For the preset neural network model, the first code object set by the preset neural network model is the code object representing the START of the predicted code, and the last code object output by the preset neural network model is the code object representing the END of the predicted code, so that for the preset neural network model, the first code object can be directly output, the token < START > is a representation of the first code object, and the token < END > is a representation of the last code object.
Assume that word vectors c1, c2, …, and cn, whose words output after being spliced by the bi-directional LSTM network layer are denoted as h1, h2, …, hn. Assuming that the code object vectors of the code objects except the first code object and the last code object are code_c1, code_c2, …, code_cm, the outputs of these code object vectors after being spliced by the bidirectional LSTM network layer are denoted as code_h1, code_h2, …, code_hm. The code object vector of the first code object is code_c0, and the code object vector of the last code object is code_cm+1. In fig. 2, word vectors c1, c2 and c3 are taken as examples, and the respective words outputted after the splicing by the bidirectional LSTM network layer are h1, h2 and h 3.
The preset neural network model directly outputs a first code object token < START > (code_h0 in fig. 2, and < START > in fig. 2 is a code object vector thereof); c1, c2, c3 and code_h0 are respectively input into an attention layer to obtain code_c1 output by the attention layer, and code_c1 is input into a bidirectional LSTM network layer to obtain code object code_h1 output by the bidirectional LSTM network layer; then c1, c2, c3 and code_h1 are respectively input into the attention layer to obtain code_c2 output by the attention layer, and code_c2 is input into the bidirectional LSTM network layer to obtain code object code_h2 output by the bidirectional LSTM network layer; and so on until the last code object is obtained.
As can be summarized from the above-mentioned fig. 2, the process of obtaining the code object vector by the attention layer after inputting the word matched with each word vector to the attention layer at any time is: acquiring a last code object output by a second neural network layer before the word is input; based on the last code object, deducing the relation between the code object to be output by the current second neural network layer and the word; and obtaining a code object vector output by the current second neural network layer based on the relation between the code object to be output by the second neural network layer and each word.
For example, referring to fig. 2, after each word is input to the attention layer for the first time, the last code object is the code object output by the second neural network layer before the current input, namely token < START >, and then the relation between the code object (namely code_h1) to be output by the current second neural network layer and the word is deduced based on token < START >; after each word is input to the attention layer for the second time, the last code object is code_h1, and then the relation between the code object to be output by the second neural network layer (namely, code_h1) and the word is deduced based on the code_h1.
One way to infer the relationship between the code object to be output at the current second neural network layer and each word in this embodiment is: performing dot product on the last code object and each word to obtain dot product results of each word; and obtaining weights of the words based on dot product results of the words, wherein the weights of the words represent the relation between the code objects to be output by the second neural network layer and the words.
Wherein, for word vectors with higher relation with the code object to be output, the obtained weightThe word vector which has a lower relation with the code object to be output at present is larger, and the obtained weight is smaller, so that the code object to be output at present can be deduced more accurately. For example code hi is the last code object, e t E is a sequence consisting of dot product results obtained after dot products of code_hi and h1, h2, …, hn, respectively t =[code_hi·h1,code_hi·h2,...,code_hi·hn]Each dot product result is expressed asRepresents the ith dot product result, and +.>Then using the attention layer activation function, such as solving for the weight of each word (also called the term mechanism value) using the softmax function, the specific use of the softmax function can map each dot product result to a (0, 1) interval, equivalent to solving for e t Probability distribution of each dot product result of (a) which is then the weight of the corresponding word, e.g. weight +.>
After the weight of each word is obtained, the code object vector output by the current second neural network layer, such as the code object vector output by the current second neural network layer, can be obtained by using a weighted average method
The points to be described here are: the excitation functions used in the first neural network layer and the second neural network layer may be any one of a tanh function and a sigmoid function, and of course, other excitation functions may also be used, which is not limited to this embodiment. The same activation function used for the attention layer (also referred to as an attention layer) is not limited, and any one of a softmax function, an MLP function, a bilinear function, and the like may be used.
400: and generating codes corresponding to the natural language description contents to be processed based on the code objects corresponding to the word vectors, and if the code objects are spliced according to the output sequence, obtaining the codes corresponding to the natural language description contents to be processed.
As shown in fig. 3 to 6, fig. 3 is a natural language description content to be processed and each word included in the natural language description content to be processed, by calling a preset neural network model, each code object output by the preset neural network model is shown in fig. 4, and the code shown in fig. 4 is obtained by splicing each code object in fig. 4 according to the output sequence. Fig. 5 is another natural language description content to be processed and each word included in the natural language description content to be processed, the code objects output by the natural language description content to be processed are shown in fig. 6 by calling a preset neural network model, and the codes shown in fig. 6 are obtained by splicing the code objects in fig. 6 according to the output sequence.
According to the technical scheme, after the to-be-processed natural language description content is obtained, word vectors of words in the to-be-processed natural language description content are obtained, a preset neural network model is called to obtain code objects corresponding to the word vectors output by the preset neural network model, codes corresponding to the to-be-processed natural language description are generated based on the code objects corresponding to the word vectors, wherein the preset neural network model indicates mapping relations between the word vectors of the words in the existing natural language description content and the code objects in the existing standard codes, therefore, after the word vectors of the words in the to-be-processed natural language description content are obtained, the code objects matched with the to-be-processed natural language description content can be obtained from the existing standard codes through calling the preset neural network model, multiplexing of the code objects in the existing standard codes is achieved, and then the code objects in the existing standard codes can be shared, the code development difficulty is reduced, and the code objects in the existing standard codes are successfully compiled code objects, so that when codes corresponding to the to-be-processed natural language description content are generated based on the successfully compiled code objects, the probability of going out of the codes can be reduced, and the quality of the codes is improved.
Referring to fig. 7, a flowchart of another code generation method based on deep learning provided by the embodiment of the present invention illustrates a training process of a preset neural network model, which may include the following steps:
101: the word vector of each word in the existing natural language descriptive content is used as a first input, and the code object in the existing standard code corresponding to the existing natural language descriptive content is used as a second input. It should be pointed out here that: the embodiment of the programming language adopted by the existing standard codes is not limited, and when the existing standard codes of different programming languages are needed to be multiplexed, the existing standard codes of the programming language can be adopted to train the preset neural network model.
The word vector of each word in the existing natural language description content is obtained in the same manner as the word vector of each word in the natural language description content to be processed, and is not described in detail in this embodiment, but code objects in the existing standard codes are obtained by splitting the existing standard codes by professional program developers, which is not described in detail in this embodiment.
102: a word matching the first input (i.e., the word vector in step 101 described above) and a code object vector of the second input are obtained. The network may be a first neural network layer of a preset neural network model, and the second input code object vector may be obtained by training a word2vec algorithm by using a code object, so that the word2vec algorithm has a function of generating the code object vector, and thus the word2vec algorithm can be used to predict the code object vector, and of course, other algorithms may be trained, which is not described in this embodiment.
103: training model parameters of a first neural network layer, an attention layer and a second neural network layer of a preset neural network model through the first input, the second input, the words matched by the first input and the code object vectors of the second input so as to obtain the preset neural network model.
That is, the training stage of the preset neural network model uses the content of the existing natural language description and the content corresponding to the existing standard code as inputs, and the task is to optimize all unknown model parameters in the preset neural network model by minimizing the error between the code object predicted by the preset neural network model and the correct code object (namely the code object in the existing standard code), and to complete the training of the preset neural network model by continuously changing the values of the unknown model parameters so that the error between the code object predicted by the preset neural network model and the correct code object is minimum and the accuracy of the code object predicted by the preset neural network model is highest.
After the preset neural network model is obtained, each time a to-be-processed natural language description content is obtained, the following steps 104 to 107 are executed to obtain codes corresponding to the to-be-processed natural language description content, where the execution process of the steps 104 to 107 is the same as the execution process of the steps 100 to 400, and the description of this embodiment is omitted.
When the prediction of the preset neural network model is called, the input of the preset neural network model is only related to the natural language description content to be processed (such as word vectors of words in the natural language description content to be processed), the preset neural network model automatically inputs a token < START > as a starting representation of a predicted code, and then the preset neural network model is continuously called to output corresponding code objects until a token < END > is output, and the output is represented to finish all the code objects, so that codes corresponding to the natural language description content to be processed can be obtained based on all the code objects.
104: and acquiring the natural language description content to be processed.
105: and obtaining word vectors of all words in the natural language description content to be processed.
106: and calling a preset neural network model to obtain each code object corresponding to the word vector output by the preset neural network model, wherein the preset neural network model is trained by the existing natural language description content and the existing standard codes corresponding to the existing natural language description content, so that the preset neural network model indicates the mapping relation between the word vector of each word in the existing natural language description content and each code object in the existing standard codes, and therefore, when the preset neural network model is called, the code objects in the existing standard codes can be output through the preset neural network model, and multiplexing of codes is realized.
107: and generating codes corresponding to the natural language description contents to be processed based on the code objects corresponding to the word vectors, and if the code objects are spliced according to the output sequence, obtaining the codes corresponding to the natural language description contents to be processed.
According to the technical scheme, after the preset neural network model is obtained through training, only one section of natural language description to be processed is needed to be provided, and the code object of the corresponding code can be obtained through the preset neural network model, so that automatic generation of the code can be realized under the condition that other information is not needed to be provided, and the correct code object can be provided as a reference through the preset neural network model, so that unnecessary errors generated in autonomous code writing of a program developer are prevented.
The following will take a preset neural network model including a first neural network layer, an attention layer and a second neural network layer, where the first neural network layer and the second neural network layer are bidirectional LSTM networks, and the attention layer is an attention mechanism layer as an example, as shown in fig. 8.
After the existing natural language description content and the existing standard codes are obtained, the process of training the preset neural network model shown in fig. 8 is as follows:
1) Obtaining word vectors of words included in the existing natural language descriptive content;
2) Obtaining code object vectors of all code objects in the existing standard codes;
3) Through the bidirectional splicing of the first neural network layer, predicting words corresponding to each word vector;
4) Predicting code objects corresponding to the code object vectors through bidirectional splicing of the second neural network layer;
5) Calling the attention layer to obtain code object vectors of all the code objects predicted by the attention layer based on all the predicted words and all the predicted code objects, wherein the code object vectors have a one-to-one correspondence with the code objects, so that the code objects corresponding to the predicted code object vectors can be obtained based on the predicted code object vectors, then determining whether the code objects obtained through the predicted code object vectors are consistent with the code objects in the existing standard codes, if not, adjusting the values of model parameters in the first neural network layer, the attention layer and the second neural network layer, and if the values are consistent and the consistency reaches a preset threshold value, stopping adjusting, and completing training of the preset neural network model.
The points to be described here are: the process of the attention layer predicting the code object vectors of the respective code objects may refer to the relevant description in the above method embodiment, which is not described in detail in this embodiment.
For the foregoing method embodiments, for simplicity of explanation, the methodologies are shown as a series of acts, but one of ordinary skill in the art will appreciate that the present invention is not limited by the order of acts, as some steps may, in accordance with the present invention, occur in other orders or concurrently. Further, those skilled in the art will also appreciate that the embodiments described in the specification are all preferred embodiments, and that the acts and modules referred to are not necessarily required for the present invention.
Corresponding to the above method embodiment, the embodiment of the present invention further provides a code generating device based on deep learning, where the structure of the code generating device is shown in fig. 9, and the code generating device may include: acquisition unit 10, acquisition unit 20, calling unit 30 and generation unit 40.
An obtaining unit 10, configured to obtain the natural language description content to be processed. It will be appreciated that: the natural language description content to be processed is a piece of text or a sentence to be generated of the code and described in natural language, and the natural language description content to be processed is related to a function of the code to be generated. And what the natural language description content to be processed includes depends on the function of the code to be generated, this embodiment is not limited.
The obtaining unit 20 is configured to obtain word vectors of words in the natural language description to be processed.
One way to obtain a word vector is: the method comprises the steps of word segmentation of natural language descriptive contents to be processed, and obtaining various words included in the natural language descriptive contents to be processed, for example, using jieba, snowNLP (which is a natural language processing Python library and supports word segmentation of the natural language descriptive contents), and word segmentation tools such as pynlpir and thulac to segment the natural language descriptive contents to be processed. After each word included in the natural language description to be processed is obtained, a vector generation tool such as at least one algorithm of word2vec algorithm, one-hot coding, fastatex algorithm and glove algorithm can be adopted to generate a word vector of each word, or a word vector corpus such as Chinese Word Vectors is adopted to obtain the word vector of each word from the word vector corpus. If the word vector of the word cannot be obtained from the word vector corpus, the word vector of the word can be generated by combining a vector generation tool, and the related description in the method embodiment is specifically referred to.
The calling unit 30 is configured to call a preset neural network model to obtain each code object corresponding to the word vector output by the preset neural network model, where the preset neural network model is obtained by training the existing natural language description content and the existing standard code corresponding to the existing natural language description content, so that the preset neural network model indicates a mapping relationship between the word vector of each word in the existing natural language description content and each code object in the existing standard code, and thus when the preset neural network model is called, the code objects in the existing standard code can be output through the preset neural network model, and code multiplexing is achieved.
In this embodiment, calling a preset neural network model to obtain each code object corresponding to a word vector output by the preset neural network model refers to: and taking each word vector as the input of a preset neural network model to obtain each code object output by the preset neural network model. It should be noted here that: the preset neural network model is to output each code object one by one, but each input is all word vectors.
One possible way in which to obtain the individual code objects is: calling a first neural network layer of a preset neural network model to obtain words matched with each word vector output by the first neural network layer; the words matched with the word vectors are used as the input of the attention layer of the preset neural network model, and each code object vector output by the attention layer is obtained; and calling a second neural network layer of the preset neural network model to obtain code objects matched with each code object vector output by the second neural network layer.
And the respective code object vector process for deriving the attention layer output includes: after each word vector matched word is input to the attention layer at any time, the last code object output by the second neural network layer before the word is input is obtained; based on the last code object, deducing the relation between the code object to be output by the current second neural network layer and the word; and obtaining a code object vector output by the current second neural network layer based on the relation between the code object to be output by the second neural network layer and each word.
The method comprises the following steps of obtaining the weight of a word, wherein the weight of the word is one expression form of the relation between a code object to be output and the word in the current second neural network layer, and the obtaining process comprises the following steps: performing dot product on the last code object and each word to obtain dot product results of each word; and obtaining the weight of each word based on the dot product result of each word.
For a detailed description of the calling unit 30, reference is made to the above-described method embodiment. The points to be described here are: for the preset neural network model, the first code object set by the preset neural network model is the code object representing the start of the prediction code, and the last code object output by the preset neural network model is the code object representing the end of the prediction code.
The generating unit 40 is configured to generate a code corresponding to the natural language description content to be processed based on each code object corresponding to the word vector, and if each code object is spliced according to the output order, the code corresponding to the natural language description content to be processed can be obtained.
According to the technical scheme, after the to-be-processed natural language description content is obtained, word vectors of words in the to-be-processed natural language description content are obtained, a preset neural network model is called to obtain code objects corresponding to the word vectors output by the preset neural network model, codes corresponding to the to-be-processed natural language description are generated based on the code objects corresponding to the word vectors, wherein the preset neural network model indicates mapping relations between the word vectors of the words in the existing natural language description content and the code objects in the existing standard codes, therefore, after the word vectors of the words in the to-be-processed natural language description content are obtained, the code objects matched with the to-be-processed natural language description content can be obtained from the existing standard codes through calling the preset neural network model, multiplexing of the code objects in the existing standard codes is achieved, and then the code objects in the existing standard codes can be shared, the code development difficulty is reduced, and the code objects in the existing standard codes are successfully compiled code objects, so that when codes corresponding to the to-be-processed natural language description content are generated based on the successfully compiled code objects, the probability of going out of the codes can be reduced, and the quality of the codes is improved.
Referring to fig. 10, another code generating apparatus based on deep learning according to an embodiment of the present invention may further include, based on fig. 9, the following steps: a training unit 50, configured to take a word vector of each word in the existing natural language description content as a first input, take a code object in an existing standard code corresponding to the existing natural language description content as a second input, and obtain a word matched with the first input and a code object vector of the second input; training model parameters of a first neural network layer, an attention layer and a second neural network layer of a preset neural network model through the first input, the second input, the words matched by the first input and the code object vectors of the second input so as to obtain the preset neural network model.
The word vector of each word in the existing natural language description content is obtained in the same manner as the word vector of each word in the natural language description content to be processed, and is not described in detail in this embodiment, but code objects in the existing standard codes are obtained by splitting the existing standard codes by professional program developers, which is not described in detail in this embodiment.
The word matched by the first input may be obtained through an LSTM neural network, an RNN network and a GRU network, where these networks may be a first neural network layer of a preset neural network model, and the code object vector of the second input may be obtained by training a word2vec algorithm by using a code object, so that the word2vec algorithm has a function of generating the code object vector, and thus, the word2vec algorithm may be used to predict the code object vector, and of course, other algorithms may also be trained, which will not be described in this embodiment.
According to the technical scheme, after the preset neural network model is obtained through training, only one section of natural language description to be processed is needed to be provided, and the code object of the corresponding code can be obtained through the preset neural network model, so that automatic generation of the code can be realized under the condition that other information is not needed to be provided, and the correct code object can be provided as a reference through the preset neural network model, so that unnecessary errors generated in autonomous code writing of a program developer are prevented.
Referring to fig. 11, an embodiment of the present invention provides a model interpretation device based on importance of input features, which may include: a processor 1000 and a memory 2000.
Optionally, the device may further comprise a communication interface 3000, an input unit 4000, a display 5000 and a communication bus 6000.
The processor 1000, the memory 2000, the communication interface 3000, the input unit 4000, the display 5000, and all accomplish communication with each other through the communication bus 6000.
In this embodiment, the processor 1000 may be a central processing unit (Central Processing Unit, CPU), an asic, a dsp, an off-the-shelf programmable gate array, or other programmable logic device.
The processor may call a program stored in the memory 2000. The memory 2000 stores one or more programs, which may include program code including computer operation instructions, and in this embodiment, at least the programs for implementing the following functions are stored in the memory:
acquiring natural language description content to be processed;
obtaining word vectors of all words in natural language description contents to be processed;
calling a preset neural network model to obtain each code object corresponding to the word vector output by the preset neural network model, wherein the preset neural network model indicates the mapping relation between the word vector of each word in the existing natural language description content and each code object in the existing standard code;
And generating codes corresponding to the natural language description contents to be processed based on the code objects corresponding to the word vectors.
In one possible implementation, the memory 2000 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, and at least one application program required for functions (such as code output, etc.), and the like; the store data area may store data involved in the use of the device, such as word vectors and code objects, among others.
In addition, the memory 2000 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device or other volatile solid-state storage device.
The communication interface 3000 may be an interface of a communication module, such as an interface of a GSM module.
Of course, the structure of the terminal shown in fig. 11 does not constitute a limitation of the apparatus in the present embodiment, and the terminal may include more or less components than those shown in fig. 11 or may combine some components in practical applications.
The embodiment of the invention also provides a storage medium, wherein the storage medium stores computer executable instructions, and when the computer executable instructions are loaded and executed by a processor, the code generation method based on deep learning is realized.
It should be noted that, in the present specification, each embodiment is described in a progressive manner, and each embodiment is mainly described as different from other embodiments, and identical and similar parts between the embodiments are all enough to be referred to each other. For the apparatus class embodiments, the description is relatively simple as it is substantially similar to the method embodiments, and reference is made to the description of the method embodiments for relevant points.
Finally, it is further noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
The foregoing is merely a preferred embodiment of the present invention and it should be noted that modifications and adaptations to those skilled in the art may be made without departing from the principles of the present invention, which are intended to be comprehended within the scope of the present invention.

Claims (10)

1. A method for generating code based on deep learning, the method comprising:
acquiring natural language description content to be processed;
obtaining word vectors of all words in the natural language description content to be processed;
calling a first neural network layer of a preset neural network model to obtain words matched with each word vector output by the first neural network layer;
Taking the words matched with the word vectors as the input of the attention layer of the preset neural network model, and obtaining each code object vector output by the attention layer;
invoking a second neural network layer of the preset neural network model to obtain code objects matched with each code object vector output by the second neural network layer, and obtaining each code object corresponding to the word vector, wherein the preset neural network model indicates the mapping relation between the word vector of each word in the existing natural language description content and each code object in the existing standard code;
generating codes corresponding to the natural language description contents to be processed based on the code objects corresponding to the word vectors;
the step of obtaining each code object vector output by the attention layer by using the words matched with each word vector as the input of the attention layer of the preset neural network model comprises the following steps: after each word matched with the word vector is input into the attention layer, the following steps are executed to obtain a code object vector:
acquiring a last code object output by the second neural network layer before the word is input;
Inferring a relationship between a code object to be output by the second neural network layer and the word based on the last code object;
and obtaining a code object vector output by the second neural network layer currently based on the relation between the code object to be output by the second neural network layer and each word.
2. The method of claim 1, wherein the inferring, based on the last code object, a relationship between a code object currently to be output by the second neural network layer and the word comprises:
performing dot product on the last code object and each word to obtain dot product results of each word;
and obtaining weights of the words based on dot product results of the words, wherein the weights of the words represent the relation between the code objects to be output by the second neural network layer and the words.
3. The method of claim 1, wherein the training process of the pre-set neural network model comprises:
taking word vectors of words in the existing natural language description content as a first input, and taking code objects in the existing standard codes corresponding to the existing natural language description content as a second input;
Obtaining a word matched with the first input and a code object vector of the second input;
training model parameters of a first neural network layer, an attention layer and a second neural network layer of the preset neural network model through the first input, the second input, the words matched by the first input and the code object vectors of the second input so as to obtain the preset neural network model.
4. A method according to claim 1 or 3, wherein the first code object of the output of the predetermined neural network model is a code object representing the start of the predictive code, and the last code object of the output of the predetermined neural network model is a code object representing the end of the predictive code.
5. A deep learning-based code generation apparatus, the apparatus comprising:
the acquisition unit is used for acquiring natural language description contents to be processed;
the obtaining unit is used for obtaining word vectors of all words in the natural language description content to be processed;
the calling unit is used for calling a first neural network layer of a preset neural network model to obtain words matched with each word vector output by the first neural network layer; taking the words matched with the word vectors as the input of the attention layer of the preset neural network model, and obtaining each code object vector output by the attention layer; invoking a second neural network layer of the preset neural network model to obtain code objects matched with each code object vector output by the second neural network layer, and obtaining each code object corresponding to the word vector, wherein the preset neural network model indicates the mapping relation between the word vector of each word in the existing natural language description content and each code object in the existing standard code;
The generating unit is used for generating codes corresponding to the natural language description contents to be processed based on the code objects corresponding to the word vectors;
the invoking unit is specifically configured to, when the word matched with each word vector is used as an input of an attention layer of the preset neural network model to obtain each code object vector output by the attention layer: after each word matched with the word vector is input into the attention layer, the following steps are executed to obtain a code object vector:
acquiring a last code object output by the second neural network layer before the word is input;
inferring a relationship between a code object to be output by the second neural network layer and the word based on the last code object;
and obtaining a code object vector output by the second neural network layer currently based on the relation between the code object to be output by the second neural network layer and each word.
6. The apparatus according to claim 5, wherein the invoking unit, when deducing, based on the last code object, a relation between a code object to be output by the second neural network layer and the word, is specifically configured to:
Performing dot product on the last code object and each word to obtain dot product results of each word;
and obtaining weights of the words based on dot product results of the words, wherein the weights of the words represent the relation between the code objects to be output by the second neural network layer and the words.
7. The apparatus of claim 5, wherein the apparatus further comprises: the training unit is used for taking word vectors of words in the existing natural language descriptive contents as first input, taking code objects in the existing standard codes corresponding to the existing natural language descriptive contents as second input and obtaining words matched with the first input and code object vectors of the second input; training model parameters of a first neural network layer, an attention layer and a second neural network layer of the preset neural network model through the first input, the second input, the words matched by the first input and the code object vectors of the second input so as to obtain the preset neural network model.
8. The apparatus according to claim 5 or 7, wherein a first code object of the preset neural network model output is a code object representing a start of a predicted code, and a last code object of the preset neural network model output is a code object representing an end of the predicted code.
9. A terminal comprising a memory and a processor;
wherein the processor is configured to execute a program stored in the memory;
the memory is used for storing a program, and the program is used for at least:
acquiring natural language description content to be processed;
obtaining word vectors of all words in the natural language description content to be processed;
calling a first neural network layer of a preset neural network model to obtain words matched with each word vector output by the first neural network layer;
taking the words matched with the word vectors as the input of the attention layer of the preset neural network model, and obtaining each code object vector output by the attention layer;
invoking a second neural network layer of the preset neural network model to obtain code objects matched with each code object vector output by the second neural network layer, and obtaining each code object corresponding to the word vector, wherein the preset neural network model indicates the mapping relation between the word vector of each word in the existing natural language description content and each code object in the existing standard code;
generating codes corresponding to the natural language description contents to be processed based on the code objects corresponding to the word vectors;
The step of obtaining each code object vector output by the attention layer by using the words matched with each word vector as the input of the attention layer of the preset neural network model comprises the following steps: after each word matched with the word vector is input into the attention layer, the following steps are executed to obtain a code object vector:
acquiring a last code object output by the second neural network layer before the word is input;
inferring a relationship between a code object to be output by the second neural network layer and the word based on the last code object;
and obtaining a code object vector output by the second neural network layer currently based on the relation between the code object to be output by the second neural network layer and each word.
10. A storage medium having stored therein computer executable instructions which when loaded and executed by a processor implement the deep learning based code generation method of any of the preceding claims 1 to 4.
CN201910770155.6A 2019-08-20 2019-08-20 Code generation method and device based on deep learning Active CN110489110B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910770155.6A CN110489110B (en) 2019-08-20 2019-08-20 Code generation method and device based on deep learning

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910770155.6A CN110489110B (en) 2019-08-20 2019-08-20 Code generation method and device based on deep learning

Publications (2)

Publication Number Publication Date
CN110489110A CN110489110A (en) 2019-11-22
CN110489110B true CN110489110B (en) 2023-10-03

Family

ID=68552308

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910770155.6A Active CN110489110B (en) 2019-08-20 2019-08-20 Code generation method and device based on deep learning

Country Status (1)

Country Link
CN (1) CN110489110B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111142857B (en) * 2019-12-17 2023-04-25 华东师范大学 Function type program automatic synthesis method based on offline supervised learning
US11150880B1 (en) 2020-06-11 2021-10-19 International Business Machines Corporation Automating an adoption of cloud services
CN112329467B (en) * 2020-11-03 2022-09-30 腾讯科技(深圳)有限公司 Address recognition method and device, electronic equipment and storage medium
CN113342318B (en) * 2021-04-19 2022-06-10 山东师范大学 Fine-grained code automatic generation method and system based on multi-view code characteristics
CN113741864B (en) * 2021-08-16 2024-04-05 广州木链云科技有限公司 Automatic semantic service interface design method and system based on natural language processing
CN113849162B (en) * 2021-09-28 2024-04-02 哈尔滨工业大学 Code generation method combining model driving and deep neural network
CN114579111B (en) * 2022-05-09 2022-07-29 中国联合重型燃气轮机技术有限公司 Code generation method and device of gas turbine protection system and electronic equipment
CN116700727B (en) * 2023-06-21 2024-02-13 广州洋葱时尚集团有限公司 Cross-platform data processing method and system
CN116501306B (en) * 2023-06-29 2024-03-26 深圳市银云信息技术有限公司 Method for generating interface document code based on natural language description

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109086273A (en) * 2018-08-14 2018-12-25 北京粉笔未来科技有限公司 Method, apparatus and terminal device based on neural network answer grammer gap-filling questions
CN110110086A (en) * 2019-05-13 2019-08-09 湖南星汉数智科技有限公司 A kind of Chinese Semantic Role Labeling method, apparatus, computer installation and computer readable storage medium

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109086273A (en) * 2018-08-14 2018-12-25 北京粉笔未来科技有限公司 Method, apparatus and terminal device based on neural network answer grammer gap-filling questions
CN110110086A (en) * 2019-05-13 2019-08-09 湖南星汉数智科技有限公司 A kind of Chinese Semantic Role Labeling method, apparatus, computer installation and computer readable storage medium

Also Published As

Publication number Publication date
CN110489110A (en) 2019-11-22

Similar Documents

Publication Publication Date Title
CN110489110B (en) Code generation method and device based on deep learning
US10545733B2 (en) Code reusability
KR102304673B1 (en) Keyword extraction method, computer device, and storage medium
US11869485B2 (en) Method for generating style statement, method and apparatus for training model, and computer device
US11941366B2 (en) Context-based multi-turn dialogue method and storage medium
US20230244704A1 (en) Sequenced data processing method and device, and text processing method and device
KR20190101567A (en) Apparatus for answering a question based on maching reading comprehension and method for answering a question using thereof
KR20180091850A (en) Augmenting neural networks with external memory
CN111783993A (en) Intelligent labeling method and device, intelligent platform and storage medium
US11194968B2 (en) Automatized text analysis
US20200272435A1 (en) Systems and methods for virtual programming by artificial intelligence
CN115599901B (en) Machine question-answering method, device, equipment and storage medium based on semantic prompt
CN110807335A (en) Translation method, device, equipment and storage medium based on machine learning
Huang et al. Length adaptive recurrent model for text classification
WO2021001517A1 (en) Question answering systems
CN116166236A (en) Code recommendation method, device, computer equipment and storage medium
CN113343711A (en) Work order generation method, device, equipment and storage medium
CN111859937A (en) Entity identification method and device
CN110851600A (en) Text data processing method and device based on deep learning
Rahman et al. Evaluation of source codes using bidirectional lstm neural network
Wakchaure et al. A scheme of answer selection in community question answering using machine learning techniques
CN113656669B (en) Label updating method and device
CN111090886A (en) Desensitization data determination method and device, readable medium and electronic equipment
US11461399B2 (en) Method and apparatus for responding to question, and storage medium
CN115081402B (en) Storyline expansion method, device, equipment and medium based on traceability reasoning

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant