Code summary generation method and system based on multi-scale AST and feature fusion

Through the multi-scale AST and feature fusion method, the structural information of the code is extracted and high-quality abstracts are generated, which solves the problem of low quality of abstracts in traditional technology and improves the work efficiency of developers.

CN112764807BActive Publication Date: 2024-11-26SHANDONG NORMAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110038872.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-01-12
Publication Date
2024-11-26
Estimated Expiration
2041-01-12

AI Technical Summary

Technical Problem

Traditional code summary generation technology cannot effectively extract the structural information of the code, resulting in the low quality of the generated summary and spending a lot of time understanding the code by developers.

Method used

Using a multi-scale abstract syntax tree (AST) and feature fusion method, by constructing an abstract syntax tree, extracting node embedding vectors and feature vectors, and using graph convolution neural networks and attention mechanisms to fuse, the input decoder finally generates high Quality code summary.

Benefits of technology

Through the fusion of multi-scale AST structural feature fusion and the fusion of node feature vectors, the structural information of the code can be better extracted, and more accurate and high-quality code summary can be generated, thereby improving the work efficiency of developers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112764807B_ABST
    Figure CN112764807B_ABST
Patent Text Reader

Abstract

The present invention discloses a code summary generation method and system based on multi-scale AST and feature fusion, comprising: obtaining a target code; constructing an abstract syntax tree AST for the target code; extracting a node embedding vector of the entire abstract syntax tree AST for the abstract syntax tree AST; at the same time, extracting a feature vector of each node for the abstract syntax tree AST; inputting the node embedding vector of the entire abstract syntax tree AST and the feature vector of each node into a decoder, and outputting the generated code summary.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of automatic code summary generation, and in particular to a code summary generation method and system based on multi-scale AST and feature fusion. Background Art

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

[0003] With the rapid development of modern technology, many types of application software have emerged, which cover all aspects of people's lives and play an increasingly important role. In order to improve the quality of these software, developers usually perform regular maintenance on the application software. However, during software development and maintenance, due to the large size of the code, developers spend about 60% of their time viewing and reading the source code, which takes a lot of time and energy. In response to the above problems, programmers generally understand the meaning of a piece of code through the comments in the code, but due to the long software development cycle, some comments are easily lost or outdated. Another method is to use code summary technology. Using this method to automatically generate summaries can save programmers time reading the code. However, due to the strong structure of the code, it is impossible to obtain high-quality code summaries using traditional summary generation technology, so how to obtain quality code summaries is still a thorny problem.

[0004] High-quality code summaries can greatly improve the efficiency of programmers and reduce the time it takes for programmers to understand the code. Therefore, it is of great practical significance to express the structural information of the code more completely to obtain high-quality code summaries and speed up the development and maintenance of software by developers. Summary of the invention

[0005] In order to solve the deficiencies of the prior art, this application provides a code summary generation method and system based on multi-scale AST and feature fusion;

[0006] In the first aspect, the present application provides a code summary generation method based on multi-scale AST and feature fusion;

[0007] The code summary generation method based on multi-scale AST and feature fusion includes:

[0008] Get the object code;

[0009] Build an abstract syntax tree AST for the target code;

[0010] Extract the node embedding vector of the entire abstract syntax tree AST for the abstract syntax tree AST; at the same time, extract the feature vector of each node for the abstract syntax tree AST;

[0011] The node embedding vector of the entire abstract syntax tree AST and the feature vector of each node are input into the decoder, and the generated code summary is output.

[0012] In the second aspect, the present application provides a code summary generation system based on multi-scale AST and feature fusion;

[0013] A code summary generation system based on multi-scale AST and feature fusion, including:

[0014] An acquisition module is configured to: acquire target code;

[0015] An abstract syntax tree construction module is configured to: construct an abstract syntax tree AST for the target code;

[0016] A vector extraction module is configured to: extract a node embedding vector of the entire abstract syntax tree AST for the abstract syntax tree AST; and extract a feature vector of each node of the abstract syntax tree AST;

[0017] The code summary generation module is configured to: input the node embedding vector of the entire abstract syntax tree AST and the feature vector of each node into the decoder, and output the generated code summary.

[0018] In a third aspect, the present application also 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.

[0019] In a fourth aspect, the present application further provides a computer-readable storage medium for storing computer instructions, which, when executed by a processor, completes the method described in the first aspect.

[0020] In a fifth aspect, the present application also provides a computer program (product), including a computer program, which is used to implement any method of the aforementioned first aspect when running on one or more processors.

[0021] Compared with the prior art, the beneficial effects of this application are:

[0022] (1) A method for fusion of multi-scale AST structural features is proposed. This method generates an adjacency matrix (A) by taking the AST obtained from the code snippet, and then obtains the quadratic power of the adjacency matrix (A) by dot multiplication. 2 ) and the third power (A 3) form (that is, obtaining adjacency matrices of three scales), and inputting these three matrices into a two-layer graph convolutional neural network (GCN) to obtain three feature matrices, which are then fused by adding them together to finally obtain the feature vector of the AST node, which can better extract the feature information of the edge in the abstract syntax tree (AST).

[0023] (2) A method for fusing the feature vector of an AST node with the AST node embedding vector is proposed. This method uses the AST node embedding vector as the initial background vector and the feature vector of the AST node assigned weights by an attention mechanism (e.g., assigning a larger weight to nodes with more connected edges) as input into the decoder for fusion, and finally outputs the target code summary. The summary information generated by this method is more accurate.

[0024] 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

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

[0026] Figure 1 This is a general framework diagram used in Example 1 of the present application;

[0027] Figure 2 This is a schematic diagram of a multi-scale fusion process of Embodiment 1 of the present application;

[0028] Figure 3 This is a schematic diagram of AST node embedding in Example 1 of the present application;

[0029] Figure 4 AST schematic diagram generated for Example 1 of this application;

[0030] Figure 5 This is a schematic diagram of a decoder module according to an embodiment of the present application;

[0031] Figure 6 This is a schematic diagram of the two-layer graph convolutional neural network structure of Example 1 of the present application. DETAILED DESCRIPTION

[0032] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present application. 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 application belongs.

[0033] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. 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 "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

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

[0035] Embodiment 1

[0036] This embodiment provides a code summary generation method based on multi-scale AST and feature fusion;

[0037] like Figure 1 As shown in FIG. 1 , a code summary generation method based on multi-scale AST and feature fusion includes:

[0038] S101: Obtain target code;

[0039] S102: Construct an abstract syntax tree AST for the target code; Figure 4 As shown;

[0040] S103: extracting a node embedding vector of the entire abstract syntax tree AST; at the same time, extracting a feature vector of each node of the abstract syntax tree AST;

[0041] S104: Input the node embedding vector of the entire abstract syntax tree AST and the feature vector of each node into the decoder, and output the generated code summary, such as Figure 5 shown.

[0042] As one or more embodiments, Figure 3 As shown, the S103: extracting the node embedding vector of the entire abstract syntax tree AST for the abstract syntax tree AST; the specific steps include:

[0043] First, for the abstract syntax tree AST, extract the word vector of each node of AST;

[0044] Secondly, perform a maximum pooling operation on all nodes of the AST to obtain the node embedding vector of the entire abstract syntax tree AST.

[0045] Furthermore, for the abstract syntax tree AST, extracting the word vector of each node of the AST; the specific steps include:

[0046] For the abstract syntax tree AST, word2vec is used to extract the word vector of each node of AST.

[0047] Furthermore, the maximum pooling operation is performed on all nodes of the AST to obtain the node embedding vector of the entire abstract syntax tree AST; specifically, the maximum pooling operation is implemented by using a maximum pooling layer.

[0048] As one or more embodiments, Figure 2 As shown, the S103: extracting the feature vector of each node from the abstract syntax tree AST; the specific steps include:

[0049] Generate an initial adjacency matrix for the abstract syntax tree AST;

[0050] Perform scaled dot multiplication on the initial adjacency matrix to obtain a quadratic adjacency matrix;

[0051] Perform scaled dot multiplication on the initial adjacency matrix to obtain a cubic adjacency matrix;

[0052] For each node of the abstract syntax tree AST, perform initialization vector representation to obtain the feature matrix of each node;

[0053] Perform feature extraction on the initial adjacency matrix and the feature matrix of each node to obtain the initial feature vector matrix of each node;

[0054] Perform feature extraction on the quadratic adjacency matrix and the feature matrix of each node to obtain the quadratic feature vector matrix of each node;

[0055] Perform feature extraction on the cubic adjacency matrix and the feature matrix of each node to obtain the cubic feature vector matrix of each node;

[0056] Perform feature fusion on the initial eigenvector matrix, quadratic eigenvector matrix and cubic eigenvector matrix of each node to obtain the eigenvector matrix of each node;

[0057] Transpose the eigenvector matrix of each node to obtain the eigenvector of each node.

[0058] Furthermore, the feature extraction is performed on the initial adjacency matrix and the feature matrix of each node to obtain the initial feature vector matrix of each node; and the feature extraction is performed on the quadratic adjacency matrix and the feature matrix of each node to obtain the quadratic feature vector matrix of each node; and the feature extraction is performed on the cubic adjacency matrix and the feature matrix of each node to obtain the cubic feature vector matrix of each node; the feature extraction method used is the same.

[0059] Furthermore, the feature extraction is implemented by using a two-layer graph convolutional neural network. The two-layer graph convolutional neural network uses a serial method to connect the two layers of graph convolutional neural networks, and uses the output of the first layer of graph convolution as the input of the second layer of graph convolution. The use of a two-layer graph convolutional neural network here can better extract the feature vector of the AST node. The schematic diagram of the two-layer graph convolutional neural network structure is shown in Figure 6 shown.

[0060] As one or more embodiments, the S104: inputting the node embedding vector of the entire abstract syntax tree AST and the feature vector of each AST node into the decoder, and outputting the generated code summary; the specific steps include:

[0061] The attention mechanism is used to assign weights to the feature vectors of each AST node;

[0062] The node embedding vector of the entire abstract syntax tree AST is merged with the feature vector of each AST node after the weight is assigned to obtain a fusion vector;

[0063] The fused vector is fed into the trained GRU decoder unit and the generated code summary is output.

[0064] Furthermore, the training steps of the trained GRU decoder unit include:

[0065] Constructing a training set, wherein the training set includes: a known code summary and a code corresponding to the known code summary;

[0066] Preprocess the code corresponding to the known code summary to obtain the node embedding vector of the entire abstract syntax tree AST and the feature vector of each AST node after assigning weights;

[0067] Preprocessing the known code summary to obtain a vector sequence of the known code summary;

[0068] The node embedding vector of the entire abstract syntax tree AST of the known code and the feature vector of each AST node after weight assignment are used as input values ​​of the GRU decoder unit, and the vector sequence of the known code summary is used as the output value of the GRU decoder unit, and the GRU decoder unit is trained to obtain the trained GRU decoder unit.

[0069] First, a code snippet is converted into the corresponding abstract syntax tree (AST). Then, the word vector of each AST node is obtained through the word2vec word embedding method, and then the node embedding vector of the entire AST is obtained through a maximum pooling layer (Max Pooling). In order to better extract the feature information of the edges in the AST, the adjacency matrix generated by the AST is obtained in its quadratic and cubic forms by dot multiplication (i.e., adjacency matrices of multiple scales are generated). These three matrices reflect the AST structural information of different scales. They are respectively input into a two-layer graph convolutional neural network (GCN) to obtain the feature vectors of the AST nodes.

[0070] In order to fuse the node embedding vector of AST and the feature vector of AST node, an attention mechanism is used to assign different weights to the feature vector of each node in AST, which is input into the decoder together with the AST node embedding vector to output the corresponding code summary.

[0071] The method for automatically generating code summaries based on multi-scale AST structural feature fusion includes the following steps:

[0072] The source code dataset used in the present invention is obtained from GitHub.

[0073] Get the code snippets of the source code dataset, parse them into the corresponding abstract syntax tree (AST) using the JDT editor (Abstract Syntax Tree Generator), and extract the node information and edge information of the AST respectively.

[0074] The AST is embedded with word2vec to generate the word vector of each node, and then a maximum pooling layer is used to generate the node embedding vector of the AST to extract the node information of the AST.

[0075] The adjacency matrix (A) generated by AST is multiplied by its quadratic power (A 2 ), cubic power (A 3 ) (i.e., obtaining adjacency matrices of multiple scales) are input into a two-layer graph convolutional neural network (GCN) to obtain the feature vector of the AST node. Here A 2 A represents the number of ways to reach any two nodes through two edges. 3 It means that there are multiple ways to reach any two nodes through three edges. This method can extract feature information of more edges in AST.

[0076] By using the attention mechanism to assign different weights to the feature vector of each node of the AST and input it into the gated recurrent unit (GRU) of the decoder together with the AST node embedding vector, the summary information of the code snippet is output.

[0077] Since the adjacency matrix represents the structural information of AST, different powers of the adjacency matrix represent the structural information of AST at multiple scales. By fusing the structural features of multi-scale AST through the method we proposed, we can better represent the relationship between the nodes in AST, so that in subsequent tasks, we can judge the importance of a node in AST.

[0078] An implementation method for automatically generating code summaries based on multi-scale AST structural feature fusion mainly includes three modules: a multi-scale AST fusion module, an AST node embedding module and a decoder module.

[0079] The multi-scale AST fusion module generates an adjacency matrix and its quadratic and cubic forms from the abstract syntax tree (AST) of the code, and then inputs the three matrices into a two-layer graph convolutional neural network (GCN) to obtain the feature vectors of the AST nodes; the AST node embedding module generates the word vector of each node of the AST of the code snippet by word embedding (word2vec), and then generates the node embedding vector of the entire AST through a maximum pooling layer; the decoder module fuses the feature vector of the AST node generated by the multi-scale AST fusion module with the AST node embedding vector, and adopts an attention mechanism to assign different weights to the feature vector of each AST node, so that the decoder pays more attention to the information related to itself when outputting, which can improve the quality of the output summary.

[0080] The data set used by the method is code data obtained on GitHub. This method is targeted at the Python language and is also applicable to other code languages.

[0081] The multi-scale AST fusion module generates feature vectors of nodes from the abstract syntax tree (AST) of the source code fragment. The specific steps are as follows:

[0082] 1) Get the source code dataset from GitHub.

[0083] 2) Generate the corresponding abstract syntax tree (AST) from the code snippet through the JDT tool.

[0084] 3) Since the generated AST can be regarded as an undirected graph, the corresponding adjacency matrix A (A∈R NxN ), initialize each node of AST with vector representation to obtain the feature matrix H of AST node (0) (H (0) ∈R NxF ), where N represents the number of nodes in AST and F represents the dimension of each node vector. (0) Input into a two-layer graph convolutional neural network (GCN), each layer of GCN graph convolution uses the following formula:

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

[0086] Here l represents the number of layers, H (l) Represents the eigenvector matrix of the previous layer output. For example, the calculation formula for the first layer graph convolution is:

[0087] H (1) =g(H (0) , A)

[0088] Where g(H (l) , A) can be calculated by the following formula:

[0089]

[0090] here The purpose of adding a unit matrix is ​​to take into account the information of its own nodes. for The degree matrix σ is a nonlinear activation function (ReLu function is used here), W (l) is the weight matrix. After performing two-layer graph convolution operations through the above formula, we get a feature vector matrix M1 (M1∈R NxF ).

[0091] 4) The adjacency matrix A can be obtained by dot multiplication to obtain its quadratic power A 2 (A 2 ∈R NxN ), which can be regarded as the second scale, which means the total number of solutions that can be reached between any two nodes through two edges. 2 Combined with the eigenvector matrix M1 generated in step 3) (replace it with H in step 3) 0 )) Input the two-layer graph convolutional neural network (GCN) in the same way as step 3) to obtain a feature vector matrix M2 (M2∈R NxF ).

[0092] 5) Get the cubic power A of the adjacency matrix again by dot multiplication 3 (A 3 ∈R NxN ), which can be regarded as the third scale, which means the total number of solutions that can be reached between any two nodes through three edges. Using the same method as steps 3 and 4), we can get a eigenvector matrix M3 (M3∈R NxF ).

[0093] 6) The feature matrices of different scales obtained in steps 3), 4), and 5) are combined by adding them together to extract feature information of more edges. As the adjacency matrix A increases exponentially, the feature information of an edge may be extracted multiple times. Therefore, the feature vector matrices obtained in the above steps are given different weights and added together, which can be calculated by the following formula:

[0094] M=δ1M1+δ2M2+δ3M3

[0095] Here δ1, δ2, δ3 are weight matrices.

[0096] 7) The feature vector matrix M (M∈R NxF ), and then transpose M to get the feature vector of the AST node (the feature vector of each node is represented by Z1, Z2, ..., Z N ).

[0097] The AST node embedding module generates an AST node embedding vector from the abstract syntax tree of the code snippet in the source code dataset. The specific steps are as follows:

[0098] 1) Obtain the abstract syntax tree (AST) constructed by the multi-scale AST fusion module.

[0099] 2) Use word2vec to embed the AST into word vectors for each node (k1, ..., k N ), where the dimension of each node word vector is set to F.

[0100] 3) Through a max pooling layer, the word vector of each node of the AST is represented as the node embedding vector of the entire AST, calculated using the following formula:

[0101]

[0102] Where (i = 1, 2, ..., F), we can get the vector S ([x1, ..., x F ] T ). Here S is the node embedding vector of the entire AST.

[0103] The decoder module combines the feature vector of the AST node generated by the multi-scale AST fusion module, the AST node embedding vector generated by the AST node embedding module, and the target summary vector sequence (v1, ..., v t ) is input into the decoder unit GRU and outputs the corresponding summary information. The fusion formula is as follows:

[0104] h1=GRU(c1,y0,S)

[0105] Where c1 is the context vector, y0 is the initial input of the target vector sequence, which can be set to SOS, and S is the node embedding vector of AST.

[0106] After that, the hidden layer vector calculation formula for each time step is as follows:

[0107] h i =GRU(y i-1 , c i ,h i-1 )

[0108] where y i-1 is the output of the decoder at the previous moment, c i is the context vector at the current moment, h i-1 is the hidden layer vector of the previous time step.

[0109] In this process, an attention mechanism is used for the feature vector of each node of the AST. At each time step, the feature vector of each node is weighted and summed, and weights are assigned, so that the decoder pays more attention to the information related to itself when outputting, thereby generating the context vector ci of the current time step and inputting it into the decoder. The calculation process is as follows:

[0110]

[0111] Here α ij The weight assigned to the feature vector of each node represents the attention allocation coefficient of the jth node at the input end when the i-th word is output at the output end. j Represents the feature vector of the jth node.

[0112] α ij Calculated by the following formula:

[0113]

[0114] Here ij Based on the hidden state h of the decoder at the previous moment i-1 and AST node embedding vectors. ij Calculated by the following formula:

[0115] e ij =a(h i-1 , Z j )

[0116] Here a represents the score value of the match between the jth input node and the ith output sequence. There are three ways to calculate a, and here we use the following formula:

[0117]

[0118] Here W is a trainable parameter matrix.

[0119] Model training process:

[0120] At the decoder side, the target code summary is generated into a vector sequence (v1, ..., v t ), and compare it with the feature vector (Z1, ..., Z N ), AST node embedding vector (S) for joint training. Training is performed by back propagation, using a custom output layer and softmax operation to calculate the probability distribution of the current time step and obtain the loss of the sequence. The calculation formula is as follows:

[0121] p(y i |y1,...,y i-1 , c i )=f(y i-1 ,h i , c i )

[0122] Where f uses the softmax function to evaluate the generated word y i probability.

[0123] The loss calculation formula is as follows:

[0124]

[0125] Embodiment 2

[0126] This embodiment provides a code summary generation system based on multi-scale AST and feature fusion;

[0127] A code summary generation system based on multi-scale AST and feature fusion, including:

[0128] An acquisition module is configured to: acquire target code;

[0129] An abstract syntax tree construction module is configured to: construct an abstract syntax tree AST for the target code;

[0130] A vector extraction module is configured to: extract a node embedding vector of the entire abstract syntax tree AST for the abstract syntax tree AST; and extract a feature vector of each node of the abstract syntax tree AST;

[0131] The code summary generation module is configured to: input the node embedding vector of the entire abstract syntax tree AST and the feature vector of each node into the decoder, and output the generated code summary.

[0132] It should be noted that the acquisition module, abstract syntax tree construction module, vector extraction module and code summary generation module correspond to steps S101 to S104 in Embodiment 1, and the examples and application scenarios implemented by the modules are the same as those of the corresponding steps, 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.

[0133] 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.

[0134] 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.

[0135] Embodiment 3

[0136] 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.

[0137] 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.

[0138] 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.

[0139] 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.

[0140] 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.

[0141] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the present 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 this application.

[0142] Embodiment 4

[0143] 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.

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

Claims

1. A code summary generation method based on multi-scale AST and feature fusion, characterized by: include: Get the object code; Build an abstract syntax tree AST for the target code; Extract the node embedding vector of the entire abstract syntax tree AST for the abstract syntax tree AST; At the same time, the feature vector of each node is extracted from the abstract syntax tree AST; Among them, the feature vector of each node is extracted from the abstract syntax tree AST respectively, and the specific steps include: generating an initial adjacency matrix for the abstract syntax tree AST; performing scaled dot multiplication processing on the initial adjacency matrix to obtain a quadratic adjacency matrix; performing scaled dot multiplication processing on the initial adjacency matrix to obtain a cubic adjacency matrix; performing initialization vector representation on each node of the abstract syntax tree AST to obtain a feature matrix of each node; performing feature extraction on the initial adjacency matrix and the feature matrix of each node to obtain an initial feature vector matrix of each node; performing feature extraction on the quadratic adjacency matrix and the feature matrix of each node to obtain a quadratic feature vector matrix of each node; performing feature extraction on the cubic adjacency matrix and the feature matrix of each node to obtain a cubic feature vector matrix of each node; performing feature fusion on the initial feature vector matrix, the quadratic feature vector matrix and the cubic feature vector matrix of each node to obtain a feature vector matrix of each node; transposing the feature vector matrix of each node to obtain a feature vector of each node; The node embedding vector of the entire abstract syntax tree AST and the feature vector of each node are input into the decoder, and the generated code summary is output.

2. The code summary generation method based on multi-scale AST and feature fusion as claimed in claim 1, characterized in that: Extract the node embedding vector of the entire abstract syntax tree AST for the abstract syntax tree AST; The specific steps include: First, for the abstract syntax tree AST, extract the word vector of each node of AST; Secondly, perform a maximum pooling operation on all nodes of the AST to obtain the node embedding vector of the entire abstract syntax tree AST.

3. The code summary generation method based on multi-scale AST and feature fusion as claimed in claim 2, characterized in that: For the abstract syntax tree AST, extract the word vector of each node of the AST; The specific steps include: For the abstract syntax tree AST, word2vec is used to extract the word vector of each node of AST.

4. The code summary generation method based on multi-scale AST and feature fusion as claimed in claim 2, characterized in that: The maximum pooling operation is performed on all nodes of the AST to obtain the node embedding vector of the entire abstract syntax tree AST; specifically, the maximum pooling operation is implemented by using a maximum pooling layer.

5. The code summary generation method based on multi-scale AST and feature fusion as claimed in claim 1, characterized in that: The node embedding vector of the entire abstract syntax tree AST and the feature vector of each AST node are input into the decoder, and the generated code summary is output; The specific steps include: The attention mechanism is used to assign weights to the feature vectors of each AST node; The node embedding vector of the entire abstract syntax tree AST is merged with the feature vector of each AST node after the weight is assigned to obtain a fusion vector; The fused vector is fed into the trained GRU decoder unit and the generated code summary is output.

6. The code summary generation method based on multi-scale AST and feature fusion as claimed in claim 5, characterized in that: The training steps of the trained GRU decoder unit include: Constructing a training set, wherein the training set includes: a known code summary and a code corresponding to the known code summary; Preprocess the code corresponding to the known code summary to obtain the node embedding vector of the entire abstract syntax tree AST and the feature vector of each AST node after assigning weights; Preprocessing the known code summary to obtain a vector sequence of the known code summary; The node embedding vector of the entire abstract syntax tree AST of the known code and the feature vector of each AST node after weight assignment are used as input values ​​of the GRU decoder unit, and the vector sequence of the known code summary is used as the output value of the GRU decoder unit, and the GRU decoder unit is trained to obtain the trained GRU decoder unit.

7. A code summary generation system based on multi-scale AST and feature fusion using the code summary generation method based on multi-scale AST and feature fusion as claimed in claim 5, characterized in that: include: An acquisition module is configured to: acquire target code; An abstract syntax tree construction module is configured to: construct an abstract syntax tree AST for the target code; A vector extraction module is configured to: extract a node embedding vector of the entire abstract syntax tree AST for the abstract syntax tree AST; and extract a feature vector of each node of the abstract syntax tree AST; The code summary generation module is configured to: input the node embedding vector of the entire abstract syntax tree AST and the feature vector of each node into the decoder, and output the generated code summary.

8. 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 6.

9. 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 6.