A method and system for generating code annotations based on dual graph neural networks
By constructing a syntactic and semantic dependency graph of a dual graph neural network and combining hierarchical propagation and graph propagation mechanisms, the problems of accuracy and multilingual adaptability in code annotation generation in existing technologies are solved, and more accurate annotation generation is achieved.
Patent Information
- Application Number
- CN202411583315.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-07
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2044-11-07
AI Technical Summary
Existing code comment generation methods struggle to effectively model complex syntactic and semantic dependencies in code and are not adaptable to multiple programming languages, resulting in limited and inaccurate generated comment information.
We employ a dual graph neural network approach, which constructs syntactic dependency graphs and semantic dependency graphs, combines hierarchical propagation mechanisms and graph propagation mechanisms, and utilizes encoders, aggregators, and decoders to generate natural language annotations, capturing the complex structure and semantic information of source code.
It improves the accuracy of annotation generation and the generalization ability of the model, and can adapt to multiple programming languages to generate more accurate annotations that fit the semantics of the code.
Smart Images

Figure CN119473383B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software engineering technology, and in particular to a method and system for generating code annotations based on dual graph neural networks. Background Technology
[0002] Software development and maintenance have become an indispensable part of human work and life, giving rise to various auxiliary technologies to facilitate project development and maintenance. In the software development and maintenance process, code comments are a crucial means of ensuring 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 easily understood by humans. Code comments are essential for ensuring code readability and maintainability, and good code comment information is also crucial for programmers' participation in the software development and maintenance process.
[0003] Existing code annotation generation methods mainly include template-based, information retrieval (IR), and sequence-to-sequence (Seq2Seq) methods. While these methods can generate annotations, they have limitations. Template-based methods are too rigid and cannot adapt to diverse programming environments; IR-based methods only extract and match keywords, failing to fully capture the deep semantic relationships between code and natural language; traditional Seq2Seq methods, although widely used, typically represent source code as a simple linear sequence, ignoring the inherent hierarchical and structural information of the code, making it difficult to effectively model complex syntactic structural relationships. Currently, the most mainstream Struct2Seq in this field can be considered an improved Seq2Seq model, but existing methods are all based on single code representations (such as ASTs or graphs), making it difficult to simultaneously model complex syntactic and semantic dependencies of the code. Furthermore, existing structural encoders are usually not designed for source code in different programming languages, ignoring some unique dependency characteristics of the encoding stage, especially the type information of nodes, resulting in limited and inaccurate generated annotation information. Summary of the Invention
[0004] The primary objective of this invention is to at least solve one of the aforementioned problems by providing a code annotation generation method based on dual graph neural networks. This invention can more effectively utilize code structure information, improve the accuracy of annotation generation, and enhance the generalization ability of the code processing model, i.e., it can adapt to multiple programming languages and obtain accurate annotations.
[0005] As another objective of the present invention, a system adapted to the method based on the aforementioned objective is also 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 is provided.
[0007] To achieve the above objectives, this invention provides a code annotation generation method based on a dual graph neural network, the method comprising the following steps:
[0008] Obtain the source code and natural language annotations as the source code, preprocess the source code, and construct training data based on the preprocessed source code and the natural language annotations;
[0009] A code processing model is constructed, and the training data is used to train the code processing model to obtain a trained code processing model. The code processing 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 based on the preprocessed source code parsing, and to construct a syntax dependency graph and a semantic dependency graph based on the abstract syntax tree. Specifically, this includes: determining the code type of the preprocessed source code; parsing the preprocessed code using a corresponding parsing method based on the code type to obtain an abstract syntax tree; adding a reverse edge to each edge in the abstract syntax tree to obtain a syntax dependency graph; and adding a reverse edge to each edge in the syntax dependency graph. Each node is given a self-loop edge, a syntax edge, and a reverse edge, to obtain a semantic dependency graph. The syntax edges include short-term dependency edges and long-term dependency edges. 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, edges with the same token, and leaf node edges. The encoder is used to obtain a first encoded representation based on the syntax dependency graph and a second encoded representation based on the semantic dependency graph. The aggregator is used to obtain an aggregated graph representation based on the first encoded representation and the second encoded representation. The decoder is used to generate natural language annotations based on the first encoded representation, the second encoded representation, and the aggregated graph representation.
[0010] Input the code to be annotated into the trained code processing model to obtain natural language annotations.
[0011] Furthermore, the preprocessing includes standardizing newline characters, parsing escape characters, and / or standardizing indentation in the source code to obtain preprocessed source code.
[0012] Furthermore, the encoder is used to obtain a first encoded representation based on the syntactic dependency graph and a second encoded representation based on the semantic dependency graph, specifically including: 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.
[0013] Further, the aggregator is used to obtain an aggregated graph representation based on the first encoded representation and the second encoded representation, specifically including:
[0014] Input the first encoded representation into BiLSTM to obtain the first image representation;
[0015] The second encoded representation is input into the max pooling layer to obtain the second graph representation;
[0016] By aggregating the first graph representation and the second graph representation, a composite graph representation is obtained.
[0017] Furthermore, the decoder is based on LSTM and incorporates a dual attention mechanism.
[0018] To achieve another objective of the present invention, the present invention also provides a code annotation generation system based on a dual graph neural network, the system comprising:
[0019] Preprocessing module: used to acquire source code and natural language annotations as source code, preprocess the source code, and construct training data based on the preprocessed source code and the natural language annotations;
[0020] 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. The code processing 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 based on the preprocessed source code parsing, and construct a syntax dependency graph and a semantic dependency graph based on the abstract syntax tree. The encoder is used to obtain a first encoded representation based on the syntax dependency graph and a second encoded representation based on the semantic dependency graph. The aggregator is used to obtain an aggregated graph representation based on the first encoded representation and the second encoded representation. The decoder is used to generate natural language annotations based on the first encoded representation, the second encoded representation, and the aggregated graph representation.
[0021] Generation module: Used to input the code to be annotated into the trained code processing model to obtain natural language annotations.
[0022] To achieve another objective of the present invention, the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, it implements the code annotation generation method based on a dual graph neural network.
[0023] Compared with the prior art, the advantages of this invention are as follows:
[0024] This 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 from the preprocessed source code and construct a syntax dependency graph and a semantic dependency graph based on the abstract syntax tree. The encoder is used to obtain a first encoded representation based on the syntax dependency graph and a second encoded representation based on the semantic dependency graph. The aggregator is used to obtain an aggregated graph representation based on the first and second encoded representations. The decoder is used to generate natural language annotations based on the first, second, and aggregated graph representations. This invention captures complex structural and semantic information in the source code by constructing syntax dependency graphs and semantic dependency graphs, and designs hierarchical propagation and graph propagation mechanisms to learn efficiently in diverse graph structures, effectively ensuring the generation of more accurate annotations that fit the semantics of the code. At the same time, this invention can adapt to multiple programming languages, avoiding the limitation of existing methods that can only generate specific types of code annotations. Attached Figure Description
[0025] Figure 1 This is a flowchart of a code annotation generation method based on a dual graph neural network according to Embodiment 1 of the present invention;
[0026] 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;
[0027] Figure 3 This is a flowchart of the source code conversion into a dual graph in Embodiment 1 of the present invention;
[0028] Figure 4 This is a framework diagram of the code processing model in Embodiment 1 of the present invention. Detailed Implementation
[0029] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to limit the scope of the invention.
[0030] Example 1
[0031] like Figure 1 As shown, a preferred embodiment of the present invention provides a code annotation generation method based on a dual graph neural network, comprising:
[0032] S1: Obtain source code and natural language annotations as source code, and preprocess the source code. Obtain source code and natural language annotations as source code, and preprocess the source code. Construct training data based on the preprocessed source code and the natural language annotations.
[0033] In an optional embodiment, preprocessing includes standardizing newline characters, parsing escape characters, and / or standardizing indentation in the source code. The purpose of preprocessing the source code is to avoid failures in subsequent abstract syntax tree (AST) acquisition. Specifically, standardizing newline characters includes: 1) Different operating systems may use different newline characters (e.g., Windows uses \r\n, while Unix / Linux / macOS uses \n). To ensure code consistency across different platforms, all newline characters can be standardized; 2) Sometimes the source code may contain redundant blank lines. These blank lines do not affect the logic of the code but increase the file size and reduce readability. These redundant blank lines can be removed using scripts or IDE functions. Parsing escape characters includes: 1) Identifying and replacing escape characters (such as \n, \t, \\, etc.) in the source code may need to be identified and replaced with corresponding characters or subjected to other processing during the preprocessing stage. For example, in some cases, \n may need to be replaced with an actual newline character; 2) Processing escape characters in strings: In string literals, escape characters are used to represent characters that cannot be directly entered (such as newline characters, tab characters, etc.). During the preprocessing stage, it is necessary to ensure that these escape characters are correctly parsed and replaced. Standardized indentation includes: 1) Unifying indentation styles: Different developers may use different indentation styles (such as spaces or tabs, and different indentation widths). To maintain code consistency, an indentation style can be selected and applied uniformly; 2) Adjusting indentation levels: During code editing or refactoring, the indentation level of some code blocks may be changed. The preprocessing stage can check and adjust these indentation levels to ensure the correctness of the code structure; 3) Removing unnecessary indentation: Sometimes the source code may contain unnecessary indentation (such as after blank lines or comment lines). This indentation can be removed through preprocessing scripts or IDE functions. The preprocessed source code is obtained. In this embodiment, the selected source code and corresponding comments are as follows: Figure 3 As shown.
[0034] S2: Used to construct a code processing model. The training data is used to train the code processing model to 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 ,
[0035] S2.1: The dual graph module is used to obtain the abstract syntax tree from the preprocessed source code and to construct the syntax dependency graph and semantic dependency graph based on the abstract syntax tree;
[0036] In an optional embodiment, S2.1 includes:
[0037] Determine the code type of the preprocessed source code;
[0038] Based on the code type, the preprocessed code is parsed using a corresponding parsing method to obtain a syntax abstraction tree (AST). To parse the node types within the AST, different tools are needed depending on the programming language. For example, for Python, the AST third-party library can be used. Furthermore, to obtain rich and complete node type information, ASDL syntax rules corresponding to specific node values need to be predefined according to the ASDL definition. During the code parsing process, these node ASDL syntax rules are loaded, ensuring that the parsed AST contains not only node values but also crucial node type information. The parsed AST consists of non-terminal nodes and terminal nodes. Non-terminal nodes are an abstract form used for syntax rules, while terminal nodes represent text tags such as identifiers, strings, and numbers.
[0039] In the abstract syntax tree (AST), reverse edges are added to each edge to obtain a syntax dependency graph. Considering the two propagation modes of hierarchical propagation mechanism (HPM): bottom-up and top-down aggregation, reverse edges are added to the edge set of the abstract syntax tree (AST) to represent bidirectional connections between hierarchical nodes, ultimately constructing the syntax dependency graph. ,in The set of nodes representing the syntax dependency graph. This represents the edge set of the syntax dependency graph, while It comes from the vocabulary list The labels for nodes, edges, and node types;
[0040] In the syntax dependency graph, self-looping edges, syntax edges, and reverse edges are added to each node to obtain a semantic dependency graph. The AST (Abstract Syntax Tree) primarily represents the code structure, but the source code contains not only structural information but also rich semantic information. To enable the code processing model to learn the semantic relationships within the code, further processing of the AST is needed, namely, adding syntax edges, self-looping edges, and reverse edges. This enhances the flow relationships between code tokens, including data flow and control flow, thereby constructing a semantic dependency graph. Syntax edges include short-term dependency edges and long-term dependency edges. Short-term dependency edges include first-order token edges and second-order token edges, while long-term dependency edges include sibling node edges, same token edges, and leaf node edges.
[0041] Specifically, first-order token edges and second-order token edges are used to connect first-order and second-order tokens, respectively, with token distances of 1 and 2. More specifically, first-order token edges connect sub-tokens with a distance of 1, while second-order token edges connect sub-tokens with a distance of 2. For example, for a node "user_id", to enable the model to learn more refined word embeddings, we split it into two sub-nodes "user" and "id". The sub-nodes "user" and "id" are directly connected by a first-order token edge because their distance is 1. The same logic applies to second-order token edges; if there is a sub-token "user" and another sub-token "email" with a distance of 2, they will be connected by a second-order token edge. This connection method is particularly suitable for short-term dependency analysis of the split sub-tokens.
[0042] Sibling edge (NextNode): Adding a NextNode edge connects sibling nodes (a group of nodes at the same level under the same parent node), making the information flow between these sibling nodes closer.
[0043] SameToken Edge: The SameToken edge is used to connect all tokens representing the same identifier. This is a data flow relationship that allows the model to locate the definition and usage of the identifier.
[0044] Leaf Node Edges: Abstract Syntax Trees (ASTs) contain rich structural information, but the tree structure leads to long distances between leaf nodes, which may cause problems such as long-distance forgetting or reduced relationships. Therefore, adding data flow LeafNode edges between leaf nodes can enhance the connectivity and semantic representation information of the AST.
[0045] Adding self-looping edges is to enhance the node's ability to capture its own state and to model self-dependencies;
[0046] Adding reverse edges to the syntax edges is to model reverse relationships, thereby obtaining a semantic dependency graph;
[0047] S2.2: The encoder is used to obtain a first encoded representation based on the syntax dependency graph and a second encoded representation based on the semantic dependency graph;
[0048] In an optional embodiment, the encoder uses a hierarchical propagation mechanism to obtain a first encoded representation and a graph propagation mechanism to obtain a second encoded representation;
[0049] Specifically, the Hierarchical Propagation Mechanism (HPM) is used to learn hierarchical syntactic information from the syntactic dependency graph. HPM is a mechanism designed to learn hierarchical syntactic information from the syntactic dependency graph. The propagation mechanism for obtaining syntactic structure information in the graph is crucial, but GPM alone cannot fully utilize this mechanism. HPM updates node embeddings in parallel recursively in both bottom-up and top-down directions, ensuring the orderly flow of syntactic structure information within the graph. Definition for The maximum order.
[0050] For a bottom-up approach, this is represented in the tree as primitive syntactic edges, where edges point from parent nodes to child nodes. Through this connection, syntactic structure information is sequentially aggregated from successor nodes to the graph via edges. The current node, and finally aggregate the information to The 0th order node (i.e., the root node). For the node of order... nodes HPM from back to neighbor Backward characterization is obtained from aggregation .
[0051]
[0052]
[0053] In a top-down approach, this is represented in the tree as the reverse edge of a syntactic edge, meaning the edge points from the child node to the parent node. Therefore, syntactic structure information propagates from the parent node to the current node. For nodes of order... nodes HPM from the front to the neighbor Aggregation yields forward characterization .
[0054]
[0055]
[0056] When the order is obtained When representing forward and backward, the embedded The following similar update process will be used in two ways.
[0057]
[0058]
[0059]
[0060]
[0061] in edge set It only contains syntax edges and syntax reverse edges, while It also includes other edge relationships.
[0062] The Graph Propagation Mechanism (GPM) learns semantic dependency graphs. Of the semantic structural information, GPM focuses more on semantic dependency graphs. The length dependency of contextual information within the time step. At this point, node embedding (i.e., the embedding of node values after AST is serialized by a level-order traversal algorithm). The update method is as follows:
[0063]
[0064]
[0065]
[0066]
[0067]
[0068] in For iterative index, For nodes The set of neighboring nodes, For the sigmoid function, For the tanh function, for edge type Specific learnable parameters were set. , , Similarly, for node types Specific settings have also been set , , As a learnable parameter.
[0069] As shown in the formula above, this embodiment provides each edge type with... Different learnable parameters are introduced so that different types of edges can be propagated using different weight matrices. To further distinguish the specific semantic information of different node types, this embodiment improves the original GGNN model by assigning different weight matrices to each node type. By introducing different learnable parameters with the same settings, this approach is expected to capture structural information more accurately.
[0070] S2.3: The aggregator is used to obtain the aggregated graph representation based on the first encoded representation and the second encoded representation;
[0071] In an optional embodiment, S2.3 specifically includes:
[0072] Inputting the first encoded representation into BiLSTM yields the first graph representation, which is the syntax dependency graph. The node representations obtained from breadth-first traversal are then processed using a Bi-LSTM (Bidirectional LSTM) to obtain the corresponding graph representation. This aggregation method supports capturing dependencies between sibling nodes, which is an effective supplement to the node representations obtained after HPM (Hidden State). For node hidden states... The following update is performed using BiLSTM:
[0073]
[0074]
[0075]
[0076] in and It is a single LSTM unit. Then, a graph representation is constructed by connecting the final hidden states of the forward and backward LSTMs. :
[0077]
[0078] The second encoded representation is input into the max pooling layer to obtain the second graph representation, which is the semantic dependency graph. The Max-Pooling method is used to compute the graph representation. Max-Pooling-based clusterers can select more important features and are unaffected by outlier features, while Sum-Pooling or Mean-Pooling may collect both the "essence" and "dross" of the feature space. The graph representation obtained through max-pooling operation... As shown below:
[0079] ;
[0080] By aggregating the first graph representation and the second graph representation, a composite graph representation is obtained, as follows:
[0081] .
[0082] S2.4: The decoder is used to generate natural graph representations based on the first coded representation, the second coded representation, and the aggregate graph representation.
[0083] Language annotations;
[0084] In an optional embodiment, the decoder is based on LSTM and incorporates a dual attention mechanism, specifically the decoder uses... (Aggregation graph representation of dual graphs) (The first encoded representation of the semantic dependency graph, also known as the node representation) (The second encoded representation of the syntax dependency graph, also known as the node representation) is used as input to generate corresponding annotations. The decoder's decoding state is updated in 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 the decoding state for each time step. .
[0085] Given the current decoding state Annotations are generated using a graph alignment-based method with the help of node representations in both the syntactic dependency graph and the semantic dependency graph. First, the graph alignment-based attention score on the dual graph is calculated as follows:
[0086]
[0087]
[0088]
[0089]
[0090]
[0091] in, and yes and Attention weights are based on Its corresponding node representation ( , Interactive scoring function between ) It was estimated. and These are two different context vectors. It is the context vector that connects the two. It is a trainable parameter.
[0092] Secondly, the attention vector Input to a set of learnable parameters In the feedforward network, the following vocabulary distribution is obtained:
[0093]
[0094] Finally, to address the OOV (out-of-vocabulary) problem, this invention introduces an additional copying mechanism, selectively copying words from the dual graph with a certain probability. The entire process is optimized by maximizing the log-likelihood of the generated annotations. Based on the loss between the actual code annotation text and the predicted annotation text generated by the model decoding, the network model parameters are updated using the Adam gradient descent algorithm, thereby obtaining a well-trained code processing model.
[0095] S3: Input the code to be annotated into the trained code processing model to obtain natural language annotations.
[0096] Simply input the code to be annotated into the trained code processing model to obtain the corresponding natural language annotation.
[0097] Example 2
[0098] like Figure 2 As shown, an embodiment of the present invention provides a code annotation generation system based on a dual graph neural network, comprising:
[0099] Preprocessing module: used to acquire source code and natural language comments as source code, and to preprocess the source code;
[0100] Training Module: Constructs and trains a code processing model to obtain a trained code processing model. The code processing 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 based on the preprocessed source code parsing, and to construct a syntax dependency graph and a semantic dependency graph based on the abstract syntax tree. The encoder is used to obtain a first encoded representation based on the syntax dependency graph and a second encoded representation based on the semantic dependency graph. The aggregator is used to obtain an aggregated graph representation based on the first encoded representation and the second encoded representation. The decoder is used to generate natural language annotations based on the first encoded representation, the second encoded representation, and the aggregated graph representation.
[0101] Generation module: Used to input the code to be annotated into the trained code processing model to obtain natural language annotations.
[0102] The system provided in this embodiment is based on the method described in Embodiment 1. It is understood that the options involved in Embodiment 1 are also applicable in this embodiment, and will not be repeated here.
[0103] Example 3
[0104] This invention also provides a computer-readable storage medium storing a computer program thereon, wherein when the computer program is executed by a processor, it implements the code annotation generation method based on a dual graph neural network.
[0105] In summary, this invention provides a code annotation generation method and system based on a dual graph neural network. It constructs and trains a code processing model, which includes a dual graph module, an encoder, an aggregator, and a decoder. The dual graph module obtains an abstract syntax tree (AST) from the preprocessed source code and constructs a syntax dependency graph and a semantic dependency graph based on the AST. The encoder obtains a first encoded representation from the syntax dependency graph and a second encoded representation from the semantic dependency graph. The aggregator obtains an aggregated graph representation from the first and second encoded representations. The decoder generates natural language annotations based on the first, second, and aggregated graph representations. This invention captures complex structures and semantic information in the source code by constructing syntax dependency graphs and semantic dependency graphs. It also designs hierarchical propagation and graph propagation mechanisms to efficiently learn in diverse graph structures, effectively ensuring the generation of more accurate annotations that fit the code semantics. Furthermore, this invention is adaptable to multiple programming languages, avoiding the limitations of existing methods that can only generate specific types of code annotations.
[0106] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and substitutions can be made without departing from the technical principles of the present invention, and these improvements and substitutions should also be considered within the scope of protection of the present invention.
Claims
1. A code annotation generation method based on dual graph neural networks, characterized in that, The method includes the following steps: Obtain the source code and natural language annotations as the source code, preprocess the source code, and construct training data based on the preprocessed source code and the natural language annotations; A code processing model is constructed, and the training data is used to train the code processing model to obtain a trained code processing model. The code processing 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 based on the preprocessed source code parsing, and to construct a syntax dependency graph and a semantic dependency graph based on the abstract syntax tree. Specifically, this includes: determining the code type of the preprocessed source code; parsing the preprocessed code using a corresponding parsing method based on the code type to obtain an abstract syntax tree; adding a reverse edge to each edge in the abstract syntax tree to obtain a syntax dependency graph; and adding a reverse edge to each edge in the syntax dependency graph. Each node is given a self-loop edge, a syntax edge, and a reverse edge, to obtain a semantic dependency graph. The syntax edges include short-term dependency edges and long-term dependency edges. 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, edges with the same token, and leaf node edges. The encoder is used to obtain a first encoded representation based on the syntax dependency graph and a second encoded representation based on the semantic dependency graph. The aggregator is used to obtain an aggregated graph representation based on the first encoded representation and the second encoded representation. The decoder is used to generate natural language annotations based on the first encoded representation, the second encoded representation, and the aggregated graph representation. Input the code to be annotated into the trained code processing model to obtain natural language annotations.
2. The code annotation generation method based on dual graph neural networks according to claim 1, characterized in that, The preprocessing includes standardizing newline characters, parsing escape characters, and / or standardizing indentation in the source code to obtain preprocessed source code.
3. The code annotation generation method based on dual graph neural networks according to claim 1, characterized in that, The encoder is used to obtain a first encoded representation based on the syntax dependency graph and a second encoded representation based on the semantic dependency graph. Specifically, the encoder uses a hierarchical propagation mechanism to obtain the first encoded representation and a graph propagation mechanism to obtain the second encoded representation.
4. The code annotation generation method based on dual graph neural networks according to claim 1, characterized in that, The aggregator is used to obtain an aggregated graph representation based on the first encoded representation and the second encoded representation, specifically including: Input the first encoded representation into BiLSTM to obtain the first image representation; The second encoded representation is input into the max pooling layer to obtain the second graph representation; By aggregating the first graph representation and the second graph representation, a composite graph representation is obtained.
5. The code annotation generation method based on dual graph neural networks according to claim 1, characterized in that, The decoder is based on LSTM and incorporates a dual attention mechanism.
6. A code annotation generation system based on a dual graph neural network, said system being implemented based on the code annotation generation method based on a dual graph neural network as described in any one of claims 1 to 5, characterized in that, include: Preprocessing module: used to acquire source code and natural language annotations as source code, preprocess the source code, and construct training data based on 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. The code processing 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 based on the preprocessed source code parsing, and construct a syntax dependency graph and a semantic dependency graph based on the abstract syntax tree. The encoder is used to obtain a first encoded representation based on the syntax dependency graph and a second encoded representation based on the semantic dependency graph. The aggregator is used to obtain an aggregated graph representation based on the first encoded representation and the second encoded representation. The decoder is used to generate natural language annotations based on the first encoded representation, the second encoded representation, and the aggregated graph representation. Generation module: Used to input the code to be annotated into the trained code processing model to obtain natural language annotations.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the code annotation generation method based on dual graph neural networks as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Source code annotation automatic generation method
CN110399162A
Code abstract automatic generation method and system
CN113064633A