Code annotation generation method and system based on dual graph neural network
By constructing syntax dependency graphs and semantic dependency graphs, and combining hierarchical propagation mechanisms and graph propagation mechanisms, the problem that code annotation generation methods in the existing technology is difficult to capture deep semantic relationships and adapt to multiple programming languages, achieving more accurate and general Generate comments.
Patent Information
- Application Number
- CN202411583315.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-07
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-11-07
AI Technical Summary
Existing code annotation generation methods are difficult to effectively capture the deep semantic relationship between code and natural language, and cannot adapt to multiple programming languages, resulting in limited and inaccurate annotation information generated.
A code annotation generation method based on dual graph neural network is adopted to create a syntax dependency graph and a semantic dependency graph, and combine the hierarchical propagation mechanism and the graph propagation mechanism to generate more accurate and code semantic annotations.
Improve the accuracy of annotation generation and the generalization ability of the code processing model, making the generated annotations more in line with code semantics and are suitable for a variety of programming languages.
Smart Images

Figure CN119473383A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software engineering, and in particular to a method and system for generating code comments based on a dual graph neural network. Background Art
[0002] Software development and maintenance have become an indispensable part of human work and life, and various auxiliary technologies have emerged to facilitate project development and maintenance. In the process of software development and maintenance, code comments are an important means to ensure code readability and maintainability. However, writing high-quality code comments is a time-consuming and easily overlooked task. Therefore, automated code comment generation technology has received widespread attention. Code comment generation aims to automatically convert structured program code into comments that are easy for humans to understand. Code comments are essential to ensuring code readability and maintainability, and good code comment information is also essential for programmers to participate in the software development and maintenance process.
[0003] Existing code comment generation methods mainly include template-based, information retrieval (IR), sequence-to-sequence (Seq2Seq) and other methods. Although these methods can generate comments, they have limitations. Template-based methods are too rigid and cannot adapt to diverse programming environments; IR-based methods only perform keyword extraction and matching, and cannot fully capture the deep semantic relationship between code and natural language; although traditional Seq2Seq methods are widely used, they usually simply represent source code as a linear sequence, ignoring the inherent hierarchical and structural information of the code, and it is difficult to effectively model complex grammatical structural relationships. Currently, the most mainstream Struct2Seq in this field can be regarded as an improved Seq2Seq model, but existing methods are all encoding methods based on a single code representation (such as AST or graph), which makes it difficult to simultaneously model the complex grammatical and semantic dependencies of the code. In addition, existing structural encoders are usually not designed for source code in different programming languages, ignoring some unique dependency characteristics in the encoding stage, especially ignoring the type information of the node, resulting in limited and inaccurate generated annotation information. Summary of the invention
[0004] The primary purpose of the present invention is to solve at least one of the above-mentioned problems and to provide a code annotation generation method based on a dual graph neural network. The present invention can more effectively utilize code structure information, improve the accuracy of annotation generation, and improve the generalization ability of the code processing model, that is, it can adapt to multiple programming languages and obtain accurate annotations.
[0005] As another object of the present invention, a system adapted to the method based on the aforementioned object is provided.
[0006] As another object of the present invention, a non-volatile storage medium suitable for storing a computer program implemented according to the method described is provided.
[0007] In order to achieve the above object, the present invention provides a code annotation generation method based on a dual graph neural network, the method comprising the following steps: Obtaining source code and natural language annotations as the source code, preprocessing the source code, and constructing training data according to the preprocessed source code and the natural language annotations; Constructing a code processing model, training the code processing model using the training data to obtain a trained code processing model, wherein the code processing model includes a dual graph module, an encoder, an aggregator, and a decoder, wherein the dual graph module is used to obtain an abstract syntax tree according to the source code parsing after the preprocessing, and to construct a syntax dependency graph and a semantic dependency graph according to the abstract syntax tree; the encoder is used to obtain a first encoding representation according to the syntax dependency graph, and to obtain a second encoding representation according to the semantic dependency graph; the aggregator is used to obtain an aggregate graph representation according to the first encoding representation and the second encoding representation; the decoder is used to generate a natural language annotation according to the first encoding representation, the second encoding representation, and the aggregate graph representation; The code to be annotated is input into the trained code processing model to obtain natural language annotations.
[0008] Furthermore, the preprocessing includes performing unifying line breaks, parsing escape characters and / or standardizing indentation processing on the source code to obtain the source code after preprocessing.
[0009] Furthermore, the dual graph module is used to parse the source code after the preprocessing to obtain an abstract syntax tree, and construct a syntax dependency graph and a semantic dependency graph according to the abstract syntax tree, specifically including: Determining a code type of the source code after the preprocessing; Based on the code type, the preprocessed code is parsed in a corresponding parsing manner to obtain an abstract syntax tree; Adding a reverse edge to each edge in the abstract syntax tree to obtain a syntax dependency graph; In the grammatical dependency graph, a self-loop edge is added to each node, a grammatical edge is added, and a reverse edge is added to the grammatical edge to obtain a semantic dependency graph.
[0010] Furthermore, the grammatical edges include short-term dependency edges and long-term dependency edges, wherein the short-term dependency edges include first-order token edges and second-order token edges, and the long-term dependency edges include sibling node edges, same token edges and leaf node edges.
[0011] Furthermore, the encoder is used to obtain a first encoded representation according to the grammatical dependency graph and to obtain a second encoded representation according to the semantic dependency graph, wherein the encoder uses a hierarchical propagation mechanism to obtain the first encoded representation and a graph propagation mechanism to obtain the second encoded representation.
[0012] Further, the aggregator is used to obtain an aggregate graph representation according to the first encoded representation and the second encoded representation, specifically including: Input the first encoded representation into BiLSTM to obtain a first graph representation; Inputting the second encoded representation into a maximum pooling layer to obtain a second graph representation; The first graph representation and the second graph representation are aggregated to obtain an aggregated graph representation.
[0013] Furthermore, the decoder is based on LSTM.
[0014] Furthermore, the decoder integrates a dual attention mechanism.
[0015] In order to achieve another object of the present invention, the present invention also provides a code annotation generation system based on a dual graph neural network, the system comprising: Preprocessing module: used for obtaining source code and natural language annotations as the source code, preprocessing the source code, and constructing training data according to the preprocessed source code and the natural language annotations; Training module: used to construct a code processing model, train the code processing model using the training data, and obtain a trained code processing model, wherein the code processing model includes a dual graph module, an encoder, an aggregator, and a decoder, wherein the dual graph module is used to obtain an abstract syntax tree according to the source code parsing after the preprocessing, and to construct a syntax dependency graph and a semantic dependency graph according to the abstract syntax tree; the encoder is used to obtain a first encoding representation according to the syntax dependency graph, and to obtain a second encoding representation according to the semantic dependency graph; the aggregator is used to obtain an aggregate graph representation according to the first encoding representation and the second encoding representation; the decoder is used to generate natural language annotations according to the first encoding representation, the second encoding representation, and the aggregate graph representation; Generation module: used to input the code to be annotated into the trained code processing model to obtain natural language annotations.
[0016] In order to achieve another purpose of the present invention, the present invention also provides a computer-readable storage medium on which a computer program is stored. When the computer-stored program is executed by a processor, the method for generating code annotations based on a dual graph neural network is implemented.
[0017] Compared with the prior art, the present invention has the following beneficial effects: The present invention constructs and trains a code processing model, which includes: a dual graph module, an encoder, an aggregator and a decoder. The dual graph module is used to obtain an abstract syntax tree according to the source code analysis after preprocessing, and to construct a syntax dependency graph and a semantic dependency graph according to the abstract syntax tree; the encoder is used to obtain a first coding representation according to the syntax dependency graph and a second coding representation according to the semantic dependency graph; the aggregator is used to obtain an aggregate graph representation according to the first coding representation and the second coding representation; the decoder is used to generate natural language annotations according to the first coding representation, the second coding representation and the aggregate graph representation. The present invention captures the complex structure and semantic information in the source code by constructing a syntax dependency graph and a semantic dependency graph, and designs a hierarchical propagation mechanism and a graph propagation mechanism, which can efficiently learn in a diversified graph structure, and effectively ensure the generation of more accurate annotations that fit the code semantics. At the same time, the present invention can adapt to a variety of programming languages, avoiding the limitation of existing methods that can only generate specific types of code annotations. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 is a flowchart of a code annotation generation method based on a dual graph neural network according to embodiment 1 of the present invention; Figure 2 This is a block diagram of a code annotation generation system based on a dual graph neural network according to embodiment 2 of the present invention; Figure 3 is a flow chart of converting source code into a dual graph in Embodiment 1 of the present invention; Figure 4 It is a framework diagram of the code processing model in Example 1 of the present invention. DETAILED DESCRIPTION
[0019] The specific implementation of the present invention is further described in detail below in conjunction with the accompanying drawings and examples. The following examples are used to illustrate the present invention, but are not intended to limit the scope of the present invention.
[0020] Example 1 like Figure 1 As shown, a code annotation generation method based on a dual graph neural network according to a preferred embodiment of the present invention includes: S1: Obtain source code and natural language annotations as the source code, and pre-process the source code. Obtain source code and natural language annotations as the source code, and pre-process the source code, and construct training data according to the pre-processed source code and the natural language annotations; In an optional embodiment, preprocessing includes unifying line breaks, parsing escape characters and / or standardizing indentation processing on the source code. The purpose of preprocessing the source code is to avoid failure in subsequent acquisition of the abstract syntax tree (AST). Specifically, unifying line breaks includes: 1) different operating systems may use different line breaks (such as Windows uses \r\n, while Unix / Linux / macOS uses \n). In order to ensure the consistency of the code on different platforms, all line breaks can be unified. 2) Sometimes the source code may contain extra blank lines, which do not affect the logic of the code, but increase the size of the file and reduce readability. These extra blank lines can be deleted through the functions of scripts or IDEs; parsing escape characters includes: 1) identification and replacement. The escape characters in the source code (such as \n, \t, \\, etc.) may need to be identified and replaced with corresponding characters or other processing in the preprocessing stage. For example, in some cases, it may be necessary to replace \n with an actual line break character. 2) Processing escape characters in strings: In string literals, escape characters are used to represent characters that cannot be directly entered (such as line breaks, tabs, etc.). During the preprocessing phase, it is necessary to ensure that these escape characters are correctly parsed and replaced; standardized indentation includes: 1) unified indentation style: different developers may use different indentation styles (such as spaces or tabs, and different indentation widths). In order to maintain the consistency of the code, you can select an indentation style and apply it uniformly, 2) adjust the indentation level: during code editing or refactoring, the indentation level of certain code blocks may be changed. These indentation levels can be checked and adjusted during the preprocessing phase to ensure the correctness of the code structure, 3) delete unnecessary indentation: sometimes the source code may contain unnecessary indentation (such as after a blank line or comment line), which can be deleted through the preprocessing script or IDE function. Obtain the source code after preprocessing. The source code and corresponding comments selected in this embodiment are as follows. Figure 3 shown.
[0021] S2: used to construct a code processing model, train the code processing model using the training data, and obtain a trained code processing model, the code processing model includes a dual graph module, an encoder, an aggregator, and a decoder. The code processing model is as follows: Figure 4 , S2.1: The dual graph module is used to obtain an abstract syntax tree based on the source code after preprocessing, and to construct a syntax dependency graph and a semantic dependency graph based on the abstract syntax tree; In an optional embodiment, S2.1 includes: Determining a code type of the source code after the preprocessing; Based on the code type, the preprocessed code is parsed in a corresponding parsing method to obtain a syntax abstract tree. In order to parse the node types in the syntax abstract tree, different tools need to be used according to different programming languages. For example, for the Python programming language, it can be parsed with the help of the ast third-party library. In addition, in order to obtain rich and complete node type information, it is necessary to predefine the ASDL syntax rules of the node type information corresponding to the specific node value according to the definition of ASDL. In the process of parsing the code into AST, the node ASDL syntax rules are loaded, so that the AST after parsing not only contains the node value, but also has the key node type information. The AST obtained after parsing consists of non-terminal nodes and terminal nodes, where the non-terminal node is an abstract form for the syntax rule, and the terminal node represents a text tag, such as an identifier, a string, and a number; In the syntax abstract tree, a reverse edge is added to each edge to obtain a syntax dependency graph; considering the two propagation modes of the hierarchical propagation mechanism (HPM): adapting to the bottom-up and top-down aggregation modes, on the basis of the abstract syntax tree (AST) edge set, a reverse edge is added to represent the bidirectional connection between the hierarchical nodes, and finally a syntax dependency graph is constructed. ,in The set of nodes representing the grammatical dependency graph, represents the edge set of the grammatical dependency graph, and From the vocabulary Labels for nodes, edges, and node types; In the syntax dependency graph, a self-loop edge is added to each node, a syntax edge is added, and a reverse edge is added to the syntax edge to obtain a semantic dependency graph; AST is more of a representation of the code structure, and the source code contains not only structural information but also rich semantic information. In order to enable the code processing model to learn the semantic relationship within the code, the AST needs to be further processed, that is, syntax edges, self-loop edges and reverse edges are added, so as to enhance the flow relationship between code tokens, including data flow and control flow, so as to construct a semantic dependency graph. , grammatical edges include short-term dependency edges and long-term dependency edges, where short-term dependency edges include first-order token edges and second-order token edges, and long-term dependency edges include sibling node edges, same token edges, and leaf node edges; Specifically, the first-order token edge and the second-order token edge are used to connect the first-order and second-order, that is, the token distance is 1 and 2, respectively. Specifically, the first-order token edge is used to connect sub-tokens with a distance of 1, while the second-order token edge is used to connect sub-tokens with a distance of 2. For example, for a node "user_id", in order to enable the model to learn a more detailed word embedding representation, we split it into two sub-nodes "user" and "id". The sub-nodes "user" and "id" are directly connected through the first-order token edge because their distance is 1. The same logic applies to the second-order token edge. If there is a sub-token "user" and another sub-token "email" with a distance of 2, they will be connected through the second-order token edge. This connection method is particularly suitable for short-term dependency analysis of the split sub-tokens; NextNode: Connects the sibling nodes (a group of nodes with the same level under the same parent node) by adding NextNode edges, making the information flow between these sibling nodes closer; SameToken: The SameToken edge is used to connect all tokens that represent the same identifier. This is a data flow relationship that allows the model to locate the definition and use of the identifier. LeafNode: The abstract syntax tree (AST) contains rich structural information, but the tree structure leads to a long distance between leaf nodes, which may cause problems such as long-distance forgetting or relationship degradation. Therefore, adding data flow LeafNode edges between leaf nodes can enhance the connectivity and semantic representation information of AST. And adding self-loop edges is to enhance the node's ability to capture its own state and model self-dependence; And adding reverse edges to grammatical edges is to model reverse relations, thus obtaining a semantic dependency graph; S2.2: The encoder is used to obtain a first encoded representation according to the grammatical dependency graph and obtain a second encoded representation according to the semantic dependency graph; In an optional embodiment, the encoder uses a hierarchical propagation mechanism to obtain the first encoded representation and uses a graph propagation mechanism to obtain the second encoded representation; Specifically, the Hierarchical Propagation Mechanism (HPM) is used to learn the hierarchical grammatical information of the grammatical dependency graph. HPM is a HPM recursively updates node embeddings in a bottom-up and top-down manner in parallel, allowing grammatical structure information to flow in an orderly manner in the graph. for The maximum order of .
[0022] For the bottom-up approach, the original grammatical edge is shown on the tree, that is, the edge points from the parent node to the child node. Through this connection, the grammatical structure information is aggregated from the successor node to the graph in sequence through the edge. The current node, and finally aggregate the information to The 0th-order node (i.e., the root node) of Node , HPM from back to neighbor Aggregation gets backward representation .
[0023]
[0024]
[0025] For the top-down approach, the tree is represented by the reverse edge of the grammatical edge, that is, the edge points from the child node to the parent node. Therefore, the grammatical structure information will be propagated from the parent node to the current node. Node , HPM from front to neighbor Aggregation to get forward representation .
[0026]
[0027]
[0028] When the order is When the forward and backward representations of A similar update process will be used in two ways.
[0029]
[0030]
[0031]
[0032]
[0033] in The edge set Contains only grammatical edges and grammatical reverse edges, while Other edge relationships are also included.
[0034] Graphical Propagation Mechanism (GPM) learns semantic dependency graphs The semantic structure information of GPM is more concerned with the semantic dependency graph. The long-term dependency of the context information in . Node embedding (i.e., embedding of node values after AST is serialized through the hierarchical traversal algorithm) The update method is as follows:
[0035]
[0036]
[0037]
[0038]
[0039] in is the iteration index, For Node The set of neighbor nodes of is the sigmoid function, is the tanh function, for edge type Sets specific learnable parameters , , ; Similarly, for node type , and also set specific , , as a learnable parameter.
[0040] As shown in the above formula, in this embodiment, for each edge type Different learnable parameters are introduced so that different types of edges can be propagated with different weight matrices. In order to further distinguish the specific semantic information of different node types, this embodiment improves the original GGNN model and The same setting introduces different learnable parameters, which is expected to capture structural information more accurately.
[0041] S2.3: an aggregator is used to obtain an aggregate graph representation based on the first encoded representation and the second encoded representation; In an optional embodiment, S2.3 specifically includes: The first encoding representation is input into BiLSTM to obtain the first graph representation. For the grammatical dependency graph , the node representation obtained in the breadth-first traversal uses BiLSTM bidirectional LSTM to obtain the corresponding graph representation. This aggregation method supports capturing the dependencies between sibling nodes, which is an effective supplement to the node representation obtained after HPM. , using BiLSTM to update as follows:
[0042]
[0043]
[0044] in and is a single LSTM unit. Then, the graph representation is constructed by concatenating the final hidden states of the forward LSTM and the backward LSTM :
[0045] The second encoded representation is input into the maximum pooling layer to obtain the second graph representation. , using the Max-Pooling method to compute the graph representation Max-Pooling based clusterers can select more important features and are not affected by abnormal feature values, while Sum-Pooling or Mean-Pooling may collect the "essence" and "dregs" of the feature space. Graph representation obtained by the maximum pooling operation As shown below: ; Aggregating the first graph representation and the second graph representation to obtain an aggregated graph representation is as follows: .
[0046] S2.4: The decoder is used to generate a natural Language notes; In an optional embodiment, the decoder is based on LSTM and integrates a dual attention mechanism. Specifically, the decoder is based on (Aggregate graph representation of dual graph), (the first encoding representation of the semantic dependency graph, also known as the node representation), (the second encoding representation of the grammatical dependency graph, also known as the node representation) as input and generate the corresponding annotations The decoding state of the decoder is updated in the following two steps. First, the decoding state is initialized using the aggregation graph of the dual graph. ,Right now ; Then, an LSTM-based decoder is used to generate a decoding state for each time step .
[0047] Given the current decoding state , the following graph alignment-based method is used to generate annotations with the help of node representations of syntactic dependency graph and semantic dependency graph. First, the graph alignment-based attention score on the dual graph is calculated as follows:
[0048]
[0049]
[0050]
[0051]
[0052] in, and yes and The attention weights are based on Its corresponding node representation ( , ) Estimated. and are two different context vectors, is the context vector connecting the two, is a trainable parameter.
[0053] Secondly, the attention vector Input to a In the feedforward network, the following vocabulary distribution is obtained:
[0054] Finally, in order to solve the OOV problem, the present invention introduces an additional copy mechanism to selectively copy words from the dual graph with a certain probability. The whole process is optimized by maximizing the log-likelihood of the generated comments. According to the loss of the real code comment text and the predicted comment text generated by model decoding, the Adam gradient descent algorithm is used to update the network model parameters, thereby obtaining a trained code processing model.
[0055] S3: Input the code to be annotated into the trained code processing model to obtain natural language annotations.
[0056] You only need to input the code to be annotated into the trained code processing model to obtain the corresponding natural language annotations.
[0057] Example 2 like Figure 2As shown, a code annotation generation system based on a dual graph neural network according to an embodiment of the present invention includes: Preprocessing module: used for obtaining source code and natural language annotations as the source code, and preprocessing the source code; Training module: construct and train a code processing model to obtain a trained code processing model, wherein the code processing model includes a dual graph module, an encoder, an aggregator and a decoder, wherein the dual graph module is used to obtain an abstract syntax tree according to the source code analysis after the preprocessing, and to construct a syntax dependency graph and a semantic dependency graph according to the abstract syntax tree; the encoder is used to obtain a first encoding representation according to the syntax dependency graph and a second encoding representation according to the semantic dependency graph; the aggregator is used to obtain an aggregate graph representation according to the first encoding representation and the second encoding representation; the decoder is used to generate natural language annotations according to the first encoding representation, the second encoding representation and the aggregate graph representation; Generation module: used to input the code to be annotated into the trained code processing model to obtain natural language annotations.
[0058] The system provided in this embodiment is based on the method described in Embodiment 1. It can be understood that the optional items involved in Embodiment 1 are also applicable in this embodiment and will not be described in detail here.
[0059] Example 3 An embodiment of the present invention also provides a computer-readable storage medium having a computer program stored thereon. When the computer-stored program is executed by a processor, the method for generating code annotations based on a dual graph neural network is implemented.
[0060] In summary, an embodiment of the present invention provides a code comment generation method and system based on a dual graph neural network, which constructs and trains a code processing model, and the model includes: a dual graph module, an encoder, an aggregator and a decoder. The dual graph module is used to obtain an abstract syntax tree according to the source code analysis after preprocessing, and construct a syntax dependency graph and a semantic dependency graph according to the abstract syntax tree; the encoder is used to obtain a first coding representation according to the syntax dependency graph and a second coding representation according to the semantic dependency graph; the aggregator is used to obtain an aggregate graph representation according to the first coding representation and the second coding representation; the decoder is used to generate natural language comments according to the first coding representation, the second coding representation and the aggregate graph representation. The present invention captures the complex structure and semantic information in the source code by constructing a syntax dependency graph and a semantic dependency graph, and designs a hierarchical propagation mechanism and a graph propagation mechanism to efficiently learn in a diversified graph structure, effectively ensuring the generation of more accurate and code semantically appropriate comments. At the same time, the present invention can adapt to a variety of programming languages, avoiding the limitation of existing methods that can only generate specific types of code comments.
[0061] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and substitutions can be made without departing from the technical principles of the present invention. These improvements and substitutions should also be regarded as the scope of protection of the present invention.
Claims
1. A code comment generation method based on dual graph neural network, characterized in that: The method comprises the following steps: Obtaining source code and natural language annotations as the source code, preprocessing the source code, and constructing training data according to the preprocessed source code and the natural language annotations; Constructing a code processing model, training the code processing model using the training data to obtain a trained code processing model, wherein the code processing model includes a dual graph module, an encoder, an aggregator, and a decoder, wherein the dual graph module is used to obtain an abstract syntax tree according to the source code parsing after the preprocessing, and to construct a syntax dependency graph and a semantic dependency graph according to the abstract syntax tree; the encoder is used to obtain a first encoding representation according to the syntax dependency graph, and to obtain a second encoding representation according to the semantic dependency graph; the aggregator is used to obtain an aggregate graph representation according to the first encoding representation and the second encoding representation; the decoder is used to generate a natural language annotation according to the first encoding representation, the second encoding representation, and the aggregate graph representation; The code to be annotated is input into the trained code processing model to obtain natural language annotations.
2. According to claim 1, a code annotation generation method based on dual graph neural network is characterized in that: The preprocessing includes performing unifying line breaks, parsing escape characters and / or standardizing indentation processing on the source code to obtain the source code after preprocessing.
3. A code annotation generation method based on dual graph neural network according to claim 1, characterized in that: The dual graph module is used to parse the source code after the preprocessing to obtain an abstract syntax tree, and construct a syntax dependency graph and a semantic dependency graph according to the abstract syntax tree, specifically including: Determining a code type of the source code after the preprocessing; Based on the code type, the preprocessed code is parsed in a corresponding parsing manner to obtain an abstract syntax tree; Adding a reverse edge to each edge in the abstract syntax tree to obtain a syntax dependency graph; In the grammatical dependency graph, a self-loop edge is added to each node, a grammatical edge is added, and a reverse edge is added to the grammatical edge to obtain a semantic dependency graph.
4. A method for generating code annotations based on a dual graph neural network according to claim 3, characterized in that: The grammatical edges include short-term dependency edges and long-term dependency edges, wherein the short-term dependency edges include first-order token edges and second-order token edges, and the long-term dependency edges include sibling node edges, same token edges and leaf node edges.
5. The method for generating code annotations based on a dual graph neural network according to claim 1, characterized in that: The encoder is used to obtain a first encoded representation according to the grammatical dependency graph and a second encoded representation according to the semantic dependency graph, wherein the encoder uses a hierarchical propagation mechanism to obtain the first encoded representation and a graph propagation mechanism to obtain the second encoded representation.
6. A method for generating code annotations based on a dual graph neural network according to claim 1, characterized in that: The aggregator is used to obtain an aggregate graph representation according to the first encoded representation and the second encoded representation, specifically including: Input the first encoded representation into BiLSTM to obtain a first graph representation; Inputting the second encoded representation into a maximum pooling layer to obtain a second graph representation; The first graph representation and the second graph representation are aggregated to obtain an aggregated graph representation.
7. The method for generating code annotations based on a dual graph neural network according to claim 1, characterized in that: The decoder is based on LSTM.
8. A method for generating code annotations based on dual graph neural network according to claim 7, characterized in that: The decoder integrates a dual attention mechanism.
9. A code annotation generation system based on a dual graph neural network, the system is based on a code annotation generation method based on a dual graph neural network according to any one of claims 1 to 8, characterized in that: include: Preprocessing module: used for obtaining source code and natural language annotations as the source code, preprocessing the source code, and constructing training data according to the preprocessed source code and the natural language annotations; Training module: used to construct a code processing model, train the code processing model using the training data, and obtain a trained code processing model, wherein the code processing model includes a dual graph module, an encoder, an aggregator, and a decoder, wherein the dual graph module is used to obtain an abstract syntax tree according to the source code parsing after the preprocessing, and to construct a syntax dependency graph and a semantic dependency graph according to the abstract syntax tree; the encoder is used to obtain a first encoding representation according to the syntax dependency graph, and to obtain a second encoding representation according to the semantic dependency graph; the aggregator is used to obtain an aggregate graph representation according to the first encoding representation and the second encoding representation; the decoder is used to generate natural language annotations according to the first encoding representation, the second encoding representation, and the aggregate graph representation; Generation module: used to input the code to be annotated into the trained code processing model to obtain natural language annotations.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer stored program is executed by a processor, a code annotation generation method based on a dual graph neural network as described in any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Source code annotation automatic generation method
CN110399162A
Code abstract automatic generation method and system
CN113064633A
Fine-grained code automatic generation method and system based on multi-view code features
CN113342318A
Source code annotation generation method and device, storage medium and computer equipment
CN116755769A
Entity sentiment analysis method and system based on two-channel graph convolutional neural network
CN117708692A