Code summary generation method, system, device and storage medium

By parsing the code into an abstract syntax tree, extracting and integrating syntax and semantic information, and using graph convolutional neural networks and Transformer models to generate code summaries, the problem of insufficient code summary quality in the existing technology is solved and development efficiency is improved.

CN113238798BActive Publication Date: 2024-09-06SHANDONG NORMAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110418823.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-19
Publication Date
2024-09-06
Estimated Expiration
2041-04-19

AI Technical Summary

Technical Problem

It is difficult for existing technologies to generate high-quality code summaries, causing developers to spend a lot of time reading code during software development and maintenance, and manually added comments are easily lost or outdated.

Method used

By parsing the code into an abstract syntax tree, embedding hierarchical information, using graph convolutional neural networks and bidirectional gated recurrent units to extract node feature vectors and semantic information, and integrating them into the Transformer model to generate code summaries.

Benefits of technology

It achieves high-quality code summary generation, reduces the time developers spend reading code, improves software development efficiency, and fully extracts the grammatical structure and semantic features of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113238798B
    Figure CN113238798B
Patent Text Reader

Abstract

The present invention discloses a code summary generation method, system, device and storage medium, including: parsing the acquired target code into an abstract syntax tree, embedding hierarchical information into each node of the abstract syntax tree; obtaining the word vector of each node based on the nodes of the abstract syntax tree embedded with hierarchical information; inputting the adjacency matrix of the abstract syntax tree and the word vector of each node into a trained graph convolutional neural network to obtain the feature vector of each node; processing the acquired target code into a tag sequence, inputting the tag sequence into a trained bidirectional gated recurrent unit to obtain an output vector corresponding to each tag; fusing the feature vectors of all nodes with the output vectors corresponding to the tag sequence, and inputting the fused vector into a trained transformer model to obtain a generated code summary. The grammatical structure features of the code are fully extracted, and the generated summary has better quality.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of intersectional technology of artificial intelligence and software engineering, and in particular to a code summary generation method, system, device and storage medium. Background Art

[0002] The statements in this section merely mention background art related to the present invention and do not necessarily constitute prior art.

[0003] In the process of software development and maintenance, developers have to invest a lot of energy to understand the meaning of the code. To address this problem, developers generally use comments to understand the code. These comments are added manually by developers, but as the software development cycle lengthens, some comments are easily lost or outdated. Another way to solve this problem is to use code summarization methods, which can generate corresponding natural language descriptions for a piece of code, greatly saving programmers' time reading the code and freeing developers from handwritten comments. However, since the code contains rich semantic and grammatical information, the traditional code summarization method is not enough to generate high-quality code summaries. Therefore, choosing which method to obtain high-quality code summaries is still an urgent problem to be solved. Summary of the invention

[0004] In order to address the deficiencies of the prior art, the present invention provides a code summary generation method, system, device and storage medium; the semantic and grammatical information of the code is accurately extracted to generate a high-quality summary, which reduces the time developers spend reading the code, thereby improving software development efficiency.

[0005] In a first aspect, the present invention provides a code summary generation method;

[0006] The code summary generation method includes:

[0007] Parse the acquired target code into an abstract syntax tree, embed hierarchical information into each node of the abstract syntax tree; obtain the word vector of each node based on the nodes of the abstract syntax tree embedded with hierarchical information; input the adjacency matrix of the abstract syntax tree and the word vector of each node into the trained graph convolutional neural network to obtain the feature vector of each node;

[0008] Processing the acquired target code into a tag sequence, inputting the tag sequence into a trained bidirectional gated recurrent unit to obtain an output vector corresponding to each tag;

[0009] The feature vectors of all nodes are fused with the output vectors corresponding to the tag sequence, and the fused vectors are input into the trained transformer model to obtain the generated code summary.

[0010] In a second aspect, the present invention provides a code summary generation system;

[0011] Code summary generation system, including:

[0012] A node feature vector extraction module is configured to: parse the acquired target code into an abstract syntax tree, embed hierarchical information into each node of the abstract syntax tree; obtain a word vector of each node based on the nodes of the abstract syntax tree embedded with hierarchical information; input the adjacency matrix of the abstract syntax tree and the word vector of each node into the trained graph convolutional neural network to obtain a feature vector of each node;

[0013] A sequence output vector acquisition module is configured to: process the acquired target code into a tag sequence, input the tag sequence into a trained bidirectional gated recurrent unit, and obtain an output vector corresponding to each tag;

[0014] The code summary generation module is configured to: fuse the feature vectors of all nodes with the output vectors corresponding to the tag sequence, input the fused vectors into the trained transformer model, and obtain the generated code summary.

[0015] In a third aspect, the present invention further provides an electronic device comprising: one or more processors, one or more memories, and one or more computer programs; wherein the processor is connected to the memory, and the one or more computer programs are stored in the memory, and when the electronic device is running, the processor executes the one or more computer programs stored in the memory so that the electronic device executes the method described in the first aspect above.

[0016] In a fourth aspect, the present invention further provides a computer-readable storage medium for storing computer instructions, wherein when the computer instructions are executed by a processor, the method described in the first aspect is completed.

[0017] Compared with the prior art, the present invention has the following beneficial effects:

[0018] (1) A grammatical feature extraction method that integrates AST neighbor and hierarchical node information is proposed. This method adds a layer number mark to the node by traversing the AST obtained from the code snippet through a breadth-first search, and then uses the word embedding method to obtain the word vector of the node. These are input into the two-layer GCN as the initial feature vector to obtain a feature vector matrix, in which each node vector contains not only the information of its neighbor nodes, but also the hierarchical information of the node. This method can more fully extract the grammatical structure features of the code.

[0019] (2) A method for fusing code semantics and grammatical feature information is proposed. This method inputs the token sequence corresponding to the source code into the Bi-GRU to obtain the output vector of each token. These vectors contain the semantic information of the code. These vectors are fused with the node feature vectors of the abstract syntax tree and input into the transformer model. By assigning different weights to each fused vector, the model pays more attention to the relatively important parts of the code snippet, which can improve the quality of the generated summary.

[0020] Advantages of additional aspects of the present invention will be given in part in the following description, and in part will become obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.

[0022] Figure 1 The general framework diagram used in the present invention;

[0023] Figure 2 A schematic diagram of the Bi-GRU used in the present invention;

[0024] Figure 3 Schematic diagram of the transformer model used in the present invention. DETAILED DESCRIPTION

[0025] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.

[0026] It should be noted that the terms used herein are only for describing specific embodiments, and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that the terms "include" and "have" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0027] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.

[0028] Terminology explanation: abstract syntax tree (abstract syntax tree or abbreviated as AST);

[0029] Graph Convolutional Network (GCN);

[0030] Bi-directional Gated Recurrent Unit (Bi-GRU);

[0031] Tokens sequence, translated into tag sequence.

[0032] Embodiment 1

[0033] This embodiment provides a code summary generation method;

[0034] like Figure 1 As shown, the code summary generation method includes:

[0035] S101: Parse the acquired target code into an abstract syntax tree, embed hierarchical information into each node of the abstract syntax tree; obtain a word vector for each node based on the nodes of the abstract syntax tree embedded with the hierarchical information;

[0036] Input the adjacency matrix of the abstract syntax tree and the word vector of each node into the trained graph convolutional neural network to obtain the feature vector of each node;

[0037] S102: Processing the acquired target code into a tag sequence, inputting the tag sequence into a trained bidirectional gated recurrent unit, and obtaining an output vector corresponding to each tag;

[0038] S103: Fuse the feature vectors of all nodes with the output vectors corresponding to the tag sequence, and input the fused vectors into the trained transformer model to obtain a generated code summary.

[0039] Furthermore, the graph convolutional neural network, the bidirectional gated recurrent unit, and the transformer model together constitute a deep learning model; the specific connection relationship of the deep learning model includes:

[0040] The output end of the graph convolutional neural network is connected to the input end of the fusion unit; the output end of the bidirectional gated recurrent unit is also connected to the input end of the fusion unit, and the output end of the fusion unit is connected to the input end of the transformer model.

[0041] The fusion unit is a splicing unit that realizes the serial splicing of input data.

[0042] Furthermore, the trained graph convolutional neural network, the trained bidirectional gated recurrent unit, and the trained transformer model are obtained by joint training, and the joint training specifically refers to:

[0043] Constructing a training set; the training set is a code of a known summary;

[0044] Build deep learning models;

[0045] Parse the code in the training set into an abstract syntax tree, embed hierarchical information into each node of the abstract syntax tree; obtain the word vector of each node based on the nodes of the abstract syntax tree with embedded hierarchical information; use the adjacency matrix of the abstract syntax tree and the word vector of each node as the input value of the graph convolutional neural network of the deep learning model;

[0046] Processing the codes in the training set into a labeled sequence, and using the labeled sequence as an input value of a bidirectional gated recurrent unit of a deep learning model;

[0047] Use the summary in the training set as the output value of the transformer model;

[0048] The deep learning model is trained. When the loss function reaches the minimum value or the training reaches the set number of iterations, the iteration is stopped to obtain the trained deep learning model.

[0049] The trained deep learning model is obtained, that is, the trained graph convolutional neural network, the trained bidirectional gated recurrent unit and the trained transformer model are obtained.

[0050] Model training process:

[0051] The target summary is generated into a word vector using the word embedding method, and is input into the decoder together with the output of the transformer encoder. Since the model used in the present invention uses two layers of GCN and Bi-GRU in addition to the transformer, the model needs to be jointly trained. The present invention uses the back propagation method for training, uses the softmax layer to calculate the probability distribution of the current time step, and uses the cross entropy loss function to calculate the loss, which is calculated by comparing the target summary with the generated summary. The formula used to calculate the loss is as follows:

[0052]

[0053] Where p(y t ) is used to generate y for the current time step t The probability of , T is the length of the target summary.

[0054] Exemplarily, in the training phase, the code data set used in the present invention is obtained from GitHub. 2 million pairs of Java method-summary data pairs are obtained from GitHub as the training set of the present invention.

[0055] Exemplarily, the code in the training set is parsed into an abstract syntax tree, and hierarchical information is embedded into each node of the abstract syntax tree; specifically, the method includes:

[0056] Assume that the first layer is represented by 0. For example, if the root node has a layer number of 1, its layer number is marked as 0. The first-layer child nodes are marked as 1, the second-layer child nodes are marked as 2, and so on. The M-th-layer child nodes are marked as M.

[0057] Furthermore, the S101: parsing the acquired target code into an abstract syntax tree specifically includes:

[0058] Use the JDT compiler to parse the obtained target code into an abstract syntax tree.

[0059] Furthermore, the step S101 embeds hierarchical information into each node of the abstract syntax tree; specifically includes:

[0060] For the abstract syntax tree, a breadth-first search traversal method is adopted, and a layer number mark is added to each layer of nodes, so that the hierarchical information is included when the node is embedded.

[0061] Furthermore, the S101 obtains a word vector of each node based on the node of the abstract syntax tree in which the hierarchical information is embedded; specifically includes:

[0062] The nodes of the abstract syntax tree with embedded hierarchical information are processed using word embedding to obtain the word vector of each node.

[0063] It should be understood that the S101: parses a section of source code into an abstract syntax tree (AST), adds a layer number mark to each layer node of the AST through a breadth-first search traversal method, and then uses the word embedding method to obtain the word embedding vector of each node, which is combined with the adjacency matrix corresponding to the AST and input into the graph convolutional neural network (GCN), so as to obtain the feature vector of the node of the abstract syntax tree.

[0064] It should be understood that the S101: inputting the obtained initial feature vector into the two-layer graph convolutional neural network (GCN) with the adjacency matrix corresponding to the AST can obtain the feature vector matrix of the node of the abstract syntax tree. Since the core idea of ​​GCN is to aggregate the information of the node itself and the neighboring nodes, each vector in the feature vector matrix contains the neighbor information and hierarchical information of the node. Using this method, the grammatical structure features of the code can be fully extracted.

[0065] Exemplarily, the S101: regard the AST generated by the code as an undirected graph, so an adjacency matrix A (A∈R NxN ), where N represents the number of nodes. The word vector generated by the word embedding method is used as the initial feature vector H (0) (H (0) ∈R NxF ) combined with the adjacency matrix A and input into the two-layer GCN.

[0066] Before input, the adjacency matrix A needs to be normalized to solve the problem of information loss due to two nodes being too far apart. Each layer of graph convolution is calculated using the following formula:

[0067] H (l+1) =g(H (l) ,A)

[0068] Here l represents the number of layers, H (l) Represents the feature matrix of the previous layer output. The first layer of graph convolution uses the initial feature vector H (0) .

[0069] Expanding the above formula, we can get the following formula:

[0070]

[0071] here The purpose of this calculation is to take into account the node's own information. yes The degree matrix of is the normalization of A, σ represents an activation function (here both layers of GCN use ReLu function), W (l) is a weight matrix.

[0072] After two layers of GCN, we can get a node feature vector matrix S (S∈R NxD ), D is the dimension of the obtained vector, where the feature vector of each node is represented by S1, S2, …, S N This module can accurately represent the grammatical structure information of the code by extracting the hierarchical information and neighbor node information of the nodes of the abstract syntax tree.

[0073] Further, S102: processing the acquired target code into a tag sequence; specifically including:

[0074] The acquired target code is subjected to word segmentation operation to obtain a tag sequence.

[0075] The token sequence refers to a sequence of words, characters or symbols contained in the code snippet.

[0076] Exemplarily, the word segmentation operation of the acquired target code specifically refers to:

[0077] Split the code snippet into words based on spaces, for example:

[0078] The statement "length = 10" can be divided into three tokens.

[0079] That is, ['length', '=', '10']. This step can be implemented by directly calling the nltk package (a common toolkit for word segmentation).

[0080] Furthermore, after the step of S102: processing the acquired target code into a tag sequence, the method further includes:

[0081] The tag sequence is processed using word embedding to obtain the word vector of each tag (x1, x2, ···, x t ), where t represents the length of the tag sequence.

[0082] It should be understood that S102: for a source code fragment, it is processed into a tag sequence and input into a bidirectional gated recurrent unit Bi-GRU to obtain an output vector corresponding to each tag, and these vectors contain semantic information of the code.

[0083] It should be understood that the S102: processing a source code segment into a tag sequence and inputting them into a bidirectional gated recurrent unit Bi-GRU can obtain an output vector for each time step.

[0084] For example, Figure 2 As shown in Figure 1, the word vector of each tag is input into the bidirectional gated recurrent unit Bi-GRU in sequence, where the output of each time step is determined by the hidden layer vectors in the forward and backward directions. In the forward GRU, a hidden layer vector is obtained at each time step. and the current output The hidden layer vector is calculated by the following formula:

[0085]

[0086] Here f represents a nonlinear activation function (such as Sigmoid, ReLu function, etc.), 1 represents forward GRU, Represents the hidden layer vector of the previous time step. Similarly, in the backward GRU, the hidden layer vector of each time step can be obtained And the current output The formula is not listed here. Finally, the output z of each time step is obtained by adding the forward GRU output and the backward GRU output. i . That is, the following formula:

[0087]

[0088] Thus, we can get the output vector (z1,z2,···,z t ). This method combines the forward tokens information and the backward tokens information to better extract the semantic feature information of the code.

[0089] Further, S103: merging the feature vectors of all nodes with the output vectors corresponding to the tag sequence; specifically including:

[0090] The feature vectors of all nodes are concatenated and fused with the output vectors corresponding to the tag sequence.

[0091] It should be understood that S103: fusing the obtained AST feature vector with the output vector of the source code token sequence and inputting them into the transformer model to output the corresponding code summary.

[0092] It should be understood that S103: Figure 3 As shown in the figure, the fused vector is input into the transformer model. The self-attention mechanism in the transformer model applies different weights to different parts of the code, making the generated summary more accurate. The multi-head attention mechanism it contains can focus on each input vector and assign different weights to them, which can improve the quality of the generated summary at the output.

[0093] The Transformer model fuses the semantic and grammatical feature information obtained, and gives greater weight to relatively important parts, making the generated summary more accurate. The specific steps are as follows:

[0094] 1) The node feature vector of the abstract syntax tree is concatenated with the tag sequence vector to obtain a feature vector (k1, k2, ···, k j ), where j = t + N.

[0095] 2) Input the obtained feature vector that integrates semantics and syntax into the transformer model. The transformer model consists of two parts, including multiple encoders and multiple decoders.

[0096] Before inputting the feature vector into the encoder, the feature vector needs to be positionally encoded (Positional Encoding), where the position encoding formula is:

[0097]

[0098]

[0099] Among them, pos represents the absolute position of the feature vector, d model It represents the dimension of the eigenvector, 2i and 2i+1 represent parity, and i represents the dimension of the eigenvector.

[0100] The position vector obtained by the above formula is added to the feature vector and input into the Encoder.

[0101] 3) Encoder consists of two parts: multi-attention mechanism and fully connected layer. The position-encoded feature vector (l1, l2, ..., l j )Use three weight matrices W Q ,W K ,W V You can get the Q, K, V vectors required to calculate Attention. Multi-Attention uses multiple sets of W Q ,W K ,W V Multiple groups of Q, K, V vectors can be obtained, and a matrix Z is calculated for each group i Finally, the multiple matrices are concatenated to obtain the vector matrix Z after multi-attention calculation.

[0102] The calculation formula of Attention is as follows:

[0103]

[0104] This formula is to share a set of W in the single-head attention mechanism Q ,W K ,W V To calculate attention.

[0105] MultiHead(Q,K,V)=Concat(head1,...,head h )W O

[0106]

[0107] The above two formulas are the multi-head attention mechanism used in transformer, using multiple groups of WQ ,W K ,W V Here h represents the number of heads, W O Represents a weight matrix for dimensionality reduction, reducing the dimension of the matrix obtained after concatenation to the dimension of the matrix before concatenation.

[0108] Before inputting to the fully connected layer, ADD and Normalize are required. The purpose of using ADD (that is, adding a residual block) is to prevent degradation problems during deep neural network training, and normalization is to speed up training and improve training stability. After these two steps, it is input into a two-layer fully connected network. The calculation formula for the two-layer fully connected layer is as follows:

[0109] FFN(l)=max(0,lW1+b1)W2+b2

[0110] Here l represents the output of Multi-Attention. After two layers of fully connected networks, ADD and Normalize are performed again to output a vector matrix, which is used as the input of the next round of Encoder. This process can be repeated N times. In the present invention, N is set to 6, and the vector matrix obtained after 6 Encoders is input into the Decoder.

[0111] 4) The Decoder end consists of three parts, including Masked Multi-Attention, Encoder-based Multi-Attention and two-layer fully connected network layers. In Masked Multi-Attention, mask means mask, which covers certain values ​​so that it has no effect when the parameters are updated. The rest of the calculation principle is the same as that of the Multi-Attention in the Encoder. ADD and Normalize are also required after this part. In the Encoder-based Multi-Attention part, the Q vector in its input comes from the output of Masked Multi-Attention, and K and V come from the output of the Encoder. The vector matrix obtained after inputting them is ADDed and Normalized again, and then a vector matrix is ​​obtained after passing through the same two layers of fully connected layers as the Encoder, which is used as the input of the next Decoder. This process can also be repeated N times. The present invention is arranged to enter the final output layer after passing through 6 layers of Decoder.

[0112] 5) In the output part of the transformer, the output of the last decoder is first subjected to a linear transformation, and then the probability distribution of the output is obtained through the softmax layer, and then the word corresponding to the value with the largest probability is used as the predicted output.

[0113] Embodiment 2

[0114] This embodiment provides a code summary generation system;

[0115] Code summary generation system, including:

[0116] A node feature vector extraction module is configured to: parse the acquired target code into an abstract syntax tree, embed hierarchical information into each node of the abstract syntax tree; obtain a word vector of each node based on the nodes of the abstract syntax tree embedded with hierarchical information; input the adjacency matrix of the abstract syntax tree and the word vector of each node into the trained graph convolutional neural network to obtain a feature vector of each node;

[0117] A sequence output vector acquisition module is configured to: process the acquired target code into a tag sequence, input the tag sequence into a trained bidirectional gated recurrent unit, and obtain an output vector corresponding to each tag;

[0118] The code summary generation module is configured to: fuse the feature vectors of all nodes with the output vectors corresponding to the tag sequence, input the fused vectors into the trained transformer model, and obtain the generated code summary.

[0119] It should be noted that the node feature vector extraction module, sequence output vector acquisition module and code summary generation module correspond to steps S101 to S103 in Embodiment 1, and the examples and application scenarios implemented by the modules and the corresponding steps are the same, but are not limited to the contents disclosed in Embodiment 1. It should be noted that the modules as part of the system can be executed in a computer system such as a set of computer executable instructions.

[0120] The description of each embodiment in the above embodiments has different emphases. For parts not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0121] The proposed system can be implemented in other ways. For example, the system embodiment described above is only illustrative, and the division of the modules is only a logical function division. In actual implementation, there may be other division methods, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed.

[0122] Embodiment 3

[0123] This embodiment also provides an electronic device, including: one or more processors, one or more memories, and one or more computer programs; wherein the processor is connected to the memory, and the one or more computer programs are stored in the memory. When the electronic device is running, the processor executes the one or more computer programs stored in the memory so that the electronic device executes the method described in the above embodiment one.

[0124] It should be understood that in this embodiment, the processor may be a central processing unit CPU, and the processor may also be other general-purpose processors, digital signal processors DSP, application-specific integrated circuits ASIC, off-the-shelf programmable gate arrays FPGA or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0125] The memory may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory. For example, the memory may also store information about the device type.

[0126] In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in a processor or an instruction in the form of software.

[0127] The method in the first embodiment can be directly embodied as a hardware processor, or a combination of hardware and software modules in the processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware. To avoid repetition, it will not be described in detail here.

[0128] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with this embodiment can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0129] Embodiment 4

[0130] This embodiment further provides a computer-readable storage medium for storing computer instructions. When the computer instructions are executed by a processor, the method described in the first embodiment is completed.

[0131] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A code summary generation method, characterized in that: include: Parse the acquired target code into an abstract syntax tree. Use breadth-first search to traverse the abstract syntax tree and add a layer number tag to each layer of nodes so that the layer information is included when the node is embedded. Use word embedding to process the nodes of the abstract syntax tree with embedded layer information and obtain the word vector of each node. Input the adjacency matrix of the abstract syntax tree and the word vector of each node into the trained graph convolutional neural network to obtain the feature vector of each node; Processing the acquired target code into a tag sequence, inputting the tag sequence into a trained bidirectional gated recurrent unit to obtain an output vector corresponding to each tag; wherein the tag sequence refers to a sequence of words, characters or symbols contained in the code snippet; The feature vectors of all nodes are fused with the output vectors corresponding to the tag sequence, and the fused vectors are input into the trained transformer model to obtain the generated code summary.

2. The code summary generation method according to claim 1, characterized in that: Parse the acquired target code into an abstract syntax tree; specifically including: Use the JDT compiler to parse the obtained target code into an abstract syntax tree.

3. The code summary generation method according to claim 1, characterized in that: Process the acquired target code into a tag sequence; specifically including: The acquired target code is subjected to word segmentation operation to obtain a tag sequence.

4. The code summary generation method according to claim 1, characterized in that: After the step of processing the acquired target code into a tag sequence, it also includes: The tag sequence is processed using word embedding to obtain the word vector of each tag (x1, x2, ..., x t ), where t represents the length of the tag sequence.

5. The code summary generation method according to claim 1, characterized in that: The fused vector is input into the transformer model. The self-attention mechanism in the transformer model applies different weights to different parts of the code.

6. A code summary generation system, characterized in that: include: The node feature vector extraction module is configured to: parse the acquired target code into an abstract syntax tree, use a breadth-first search traversal method for the abstract syntax tree, add a layer number mark to each layer of nodes, so that the node contains hierarchical information when it is embedded; based on the nodes of the abstract syntax tree with embedded hierarchical information, use word embedding to process them and obtain the word vector of each node; input the adjacency matrix of the abstract syntax tree and the word vector of each node into the trained graph convolutional neural network to obtain the feature vector of each node; A sequence output vector acquisition module is configured to: process the acquired target code into a tag sequence, input the tag sequence into a trained bidirectional gated recurrent unit, and obtain an output vector corresponding to each tag; wherein the tag sequence refers to a sequence of words, characters or symbols contained in the code snippet; The code summary generation module is configured to: fuse the feature vectors of all nodes with the output vectors corresponding to the tag sequence, input the fused vectors into the trained transformer model, and obtain the generated code summary.

7. An electronic device, characterized in that: include: One or more processors, one or more memories, and one or more computer programs; wherein the processor is connected to the memory, and the one or more computer programs are stored in the memory, and when the electronic device is running, the processor executes the one or more computer programs stored in the memory to enable the electronic device to execute the method described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that: Used to store computer instructions, which, when executed by a processor, complete the method described in any one of claims 1 to 5.