A code snippet function description method based on tree-shaped neural network machine learning

By using a tree-based neural network method to describe the functions of code snippets, the problem of high code learning costs in software reuse is solved, enabling rapid parsing and improving software quality.

CN117270844BActive Publication Date: 2026-07-03UNIV OF ELECTRONICS SCI & TECH OF CHINA

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
UNIV OF ELECTRONICS SCI & TECH OF CHINA
Filing Date
2023-11-01
Publication Date
2026-07-03

AI Technical Summary

Technical Problem

In existing technologies, the lack of standardized code comments and chaotic project management during software reuse cause developers to spend a lot of time learning and speculating on the functionality of early code, increasing reuse costs.

Method used

By employing a tree-based neural network machine learning approach, a logical description model of code fragments is constructed by preprocessing the abstract syntax tree of code fragments, identifying subtrees, converting it into a binary tree, and embedding feature vectors, thereby generating a concise code function description.

Benefits of technology

It improves software reuse efficiency, reduces the cost of learning and applying non-standard code, and improves software quality and development speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117270844B_ABST
    Figure CN117270844B_ABST
Patent Text Reader

Abstract

This invention discloses a method for describing the functionality of code snippets based on tree-structured neural network machine learning. First, a code dataset is selected for preprocessing, and an abstract syntax tree (AST) is extracted from the code snippet. The descriptive text of the code is then preprocessed, and subtrees within the AST are identified. Irregular trees are transformed into binary trees, and the AST is embedded to obtain its feature vector set. Finally, a logical description model of the code snippet is constructed and trained. A code snippet without comments is input to generate a functional description. This method can quickly parse irregular code snippets, improving reuse efficiency, software quality, and reliability. It also reduces resource investment during reuse, lowers development costs, and enables faster development and launch of new products to meet market demands and competitive pressures through low-cost software reuse.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of software reuse technology, specifically relating to a method for describing the functionality of code snippets based on tree neural network machine learning. Background Technology

[0002] In the software development process, software reuse is considered an important way to reduce software development costs and is now widely used by various software development companies to improve development efficiency, reduce costs, and improve software quality. For developers to efficiently reuse previous software code, they need a thorough understanding of the company's or open-source software codebase, such as the location of the code implementing the functionality, the implementation method, and the input and output of the code snippets. In a complete software development process, ample documentation, code comments, and project management can help developers reuse code more efficiently.

[0003] However, the software production process is often accompanied by a great deal of chaos—undocumented early features, non-standard code comments, and disorganized project management. These factors significantly increase the cost of later reuse, requiring developers to spend considerable time learning and speculating on the functionality of early code, or even abandoning software reuse altogether. All of this runs counter to the purpose of software engineering.

[0004] To address the high cost of software reuse, an automated method is needed to summarize and generalize large amounts of irregular code, generating concise and comprehensive descriptions—specifically, functional descriptions—that enable developers to easily find similar code for target tasks, thereby facilitating rapid software reuse and improving software development efficiency. Summary of the Invention

[0005] To address the aforementioned technical problems, this invention provides a method for describing the functionality of code snippets based on tree neural network machine learning.

[0006] The technical solution adopted in this invention is: a method for describing the function of code snippets based on tree neural network machine learning, the specific steps of which are as follows:

[0007] S1. Select the code dataset for preprocessing, extract the abstract syntax tree of the code snippets, and preprocess the description text of the code.

[0008] S2. Based on step S1, identify the subtrees in the abstract syntax tree, transform the irregular tree into a binary tree, and then embed the abstract syntax tree to obtain the feature vector set of the abstract syntax tree.

[0009] S3. Construct a logical description model of the code snippets and train it;

[0010] S4. Based on steps S1-S3, generate code function descriptions.

[0011] Furthermore, step S1 is specifically as follows:

[0012] S11. Code dataset selection;

[0013] For a given programming language and corresponding domain project code, select the code sets for the business layer and functional implementation layer, including: the Controller layer and Service layer of internet software.

[0014] S12. Preprocess the code dataset selected in step S11;

[0015] The source code is obfuscated by encrypting variable names, reducing the impact of variable name tokens on the description of code snippets.

[0016] S13. Extract the abstract syntax tree from the code set;

[0017] F i To represent a code snippet after code obfuscation, use F. i The AST parsing tool in the parser of the language used extracts its abstract syntax tree and uses a depth-first traversal of the node set AST. i The expression is as follows:

[0018] AST i ={node i,1 node i,2 node i3 ...node i,n}

[0019] Among them, node i,n This represents the nth node of the i-th code segment. The node includes the node's text feature (token), type feature (type), and its corresponding parent node (parent). When parent is 0, it means that the node is the root node of the entire AST.

[0020] Each node should satisfy the format node i,j = (token, type, parent) i,j ;AST i The set is the set of abstract syntax trees (ASTs) in the codebase: ASTs = {AST1, AST2, ..., AST3} i}

[0021] S14. Preprocess the description text of the code;

[0022] The descriptions corresponding to the selected code snippets exist in different places, including: interface comments at the beginning of the code, implementation comments inside the code, functional descriptions in the requirements document, and method descriptions in the interface document.

[0023] The description of the selected code segment is summarized into a triple, which includes: the name of the method (caption), the input (input), and the output (output).

[0024] The method description for each code snippet should meet the following format: description i = (caption, input, output) i .

[0025] Finally, the description will be obtained. i With the AST abstracted in step S13 i By bundling, the following set is obtained:

[0026] codes={(AST1, description1), (AST2, description2),..., (AST i description i )}

[0027] Here, codes represents the processed dataset, AST. i The abstract syntax tree representing the i-th code snippet, description i The method description triple for the i-th code snippet.

[0028] Furthermore, step S2 is specifically as follows:

[0029] S21. Identify subtrees in the abstract syntax tree;

[0030] Select a node with the type of expression statement (expr), declarative statement (decl), or conditional statement (condition) as the root node of the subtree to obtain the corresponding subtree T. i,j .

[0031] Among them, T i,j This represents the j-th subtree under the i-th abstract syntax tree; keywords such as if, while, and for are treated as a separate subtree with a size of 1.

[0032] Then we obtain the set of all subtrees of the abstract syntax tree after the above processing: subtrees = {T} 1,1 T 1,2 , ...};Ti,j The specific format is as follows:

[0033] T i,j ={(token, type, parent)} i,j,1 (token, type, parent) i,j,2 ,..., (token, type, parent) i,j,n}

[0034] S22. Convert the irregular tree into a binary tree;

[0035] Since all the trees in the extracted ASTs and subtrees sets are irregular trees, we first use the rules for converting trees to binary trees to transform them.

[0036] The process involves connecting all sibling nodes, keeping only the leftmost connection between parent and child nodes, then using the sibling nodes of the original tree as right children and the byte nodes of the original tree as left children. Finally, the preorder traversal of the tree yields the binary tree sets ASTs_bin and subtree_bin that can be used for embedding.

[0037] S23. Embed the abstract syntax tree to obtain the feature vector set of the abstract syntax tree;

[0038] After transforming the irregular tree in step S22, TBCNN is used for tree embedding. TBCNN employs a fixed sliding window and attention mechanism to extract the representation of the binary tree, obtaining the feature vector set of the abstract syntax tree.

[0039]

[0040] in, Let i represent the i-th eigenvector.

[0041] First, regarding AST i The token and type are embedded to form the encoding vector of each node. or For these vectors, feature extraction and fusion are performed using TBCNN convolutional forward propagation. Finally, an attention mechanism is used to generate encoded vectors, and the AST is calculated using softmax. i Encoded vector and predicted subtree T i,j The cross-entropy of the encoded vector is calculated, and then the parameters are updated by backpropagation.

[0042] Finally, we obtain the feature vector set of the abstract syntax tree:

[0043] Furthermore, step S3 is specifically as follows:

[0044] S31. Construct a dataset describing the logic of code snippets;

[0045] The sets `codes` obtained in step S14 and `AST_vectors` obtained in step S23 are merged, and each element `code` in set `codes` is... i Replaced with

[0046] S32. Construct the association between code snippet vectors and code descriptions;

[0047] For the set of codes obtained in step S31, based on its... corresponding description i Decode the target. Obtain the context representation of the target description. The corresponding probability is then calculated using softmax.

[0048] For the generated And the description obtained previously i Calculate the cross-entropy, then backpropagate to update the parameters.

[0049] S33. Train the description generation model;

[0050] Based on steps S31-S32, an attention model is established from the abstract syntax tree of code snippets to the code description. The dataset `codes` obtained in step S31 is used for training, and the corresponding cross-entropy loss function L during training is:

[0051]

[0052] Where N represents the number of subsets in the dataset codes.

[0053] Furthermore, step S4 is specifically as follows:

[0054] S41. Enter a code snippet that does not contain code comments;

[0055] The code snippet is preprocessed using the method in step S13 to obtain its corresponding Abstract Syntax Tree (AST).

[0056] S42. Embed the abstract syntax tree of the code snippet;

[0057] Using the method in step S2, the abstract syntax tree (AST) of the code snippet is transformed and embedded to obtain the feature vector of the abstract syntax tree.

[0058] S43. Input the feature representation of the abstract syntax tree into the model;

[0059] Using the attention mechanism model described in step S3, the feature vectors of the abstract syntax tree are decoded to obtain the code snippet description. t .

[0060] The beneficial effects of this invention are as follows: The method of this invention first selects a code dataset for preprocessing and extracts an abstract syntax tree (AST) for the code snippets. It then preprocesses the code description text, identifies subtrees within the AST, transforms irregular trees into binary trees, embeds the AST to obtain its feature vector set, and finally constructs and trains a logical description model for the code snippets. Inputting a code snippet without code comments generates a code function description. This method can quickly parse some non-standard code snippets, improving reuse efficiency and software quality and reliability. Currently, the biggest cost of software reuse is the learning and application cost of non-standard code. This method can reduce resource investment during the reuse process and lower development costs. Through low-cost software reuse, this method enables faster development and launch of new products to meet market demands and competitive pressures. Attached Figure Description

[0061] Figure 1 This is a flowchart illustrating a code snippet function description method based on tree neural network machine learning according to the present invention.

[0062] Figure 2 This is a schematic diagram of a method for converting an irregular tree into a binary tree in an embodiment of the present invention.

[0063] Figure 3 This is a flowchart of the encoder of the abstract syntax tree in an embodiment of the present invention. Detailed Implementation

[0064] The method of the present invention will be further described below with reference to the accompanying drawings and embodiments.

[0065] like Figure 1 The flowchart shown is a method for describing the function of code snippets based on tree neural network machine learning according to the present invention. The specific steps are as follows:

[0066] S1. Select the code dataset for preprocessing, extract the abstract syntax tree of the code snippets, and preprocess the description text of the code.

[0067] S2. Based on step S1, identify the subtrees in the abstract syntax tree, transform the irregular tree into a binary tree, and then embed the abstract syntax tree to obtain the feature vector set of the abstract syntax tree.

[0068] S3. Construct a logical description model of the code snippets and train it;

[0069] S4. Based on steps S1-S3, generate code function descriptions.

[0070] In this embodiment, step S1 is specifically as follows:

[0071] S11. Code dataset selection;

[0072] For a given programming language and corresponding domain project code, select the code sets for the business layer and functional implementation layer, including: the Controller layer and Service layer of internet software.

[0073] The reasons for selecting this code set include:

[0074] (1) This part of the code contains most of the project's implementation logic, and the proportion of reusable code snippets is higher;

[0075] (2) The complete output of a project is often accompanied by a lot of framework content, while the core code used to implement the functions generally only exists in these places;

[0076] (3) This type of code is the core code of the business. In order to facilitate the management of software assets, various organizations often provide rich code comments and functional documentation for this type of code.

[0077] S12. Preprocess the code dataset selected in step S11;

[0078] For the code dataset selected in S11, preprocessing is required because during software development, even with the same logic, code snippets from different projects, programmers, and development stages may have different variable names. Therefore, it is necessary to reduce the impact of variable name tokens on the code logic description. Before further processing, code snippets should be obfuscated to weaken the impact of variable name tokens on the final code embedding and subsequent model training.

[0079] This embodiment only uses variable name encryption to obfuscate the source code, while ignoring obfuscation methods such as layout obfuscation and control obfuscation that can affect the code logic. By reducing the impact of variable name tokens on the description of code snippets, the logic of the code is the part that needs to be emphasized.

[0080] S13. Extract the abstract syntax tree from the code set;

[0081] For the code snippet F after code obfuscation i , use F i The AST parsing tool in the parser of the language used extracts its abstract syntax tree and uses a depth-first traversal of the node set AST. i The expression is as follows:

[0082] AST i ={node i,1 node i,2 node i,3 ...node i,n}

[0083] Among them, node i,n This represents the nth node of the i-th code segment. The node includes the node's text feature (token), type feature (type), and its corresponding parent node (parent). When parent is 0, it means that the node is the root node of the entire AST.

[0084] The process of extracting nodes from an abstract syntax tree through depth-first traversal can be represented in C language code, as shown in Table 1:

[0085] Table 1

[0086]

[0087] Each node should satisfy the format node i,j = (token, type, parent) i,j ;AST i The set is the set of abstract syntax trees (ASTs) in the codebase: ASTs = {AST1, AST2, ..., AST3} i}

[0088] S14. Preprocess the description text of the code;

[0089] The descriptions corresponding to the selected code snippets exist in different places, including: interface comments at the beginning of the code, implementation comments inside the code, functional descriptions in the requirements document, and method descriptions in the interface document.

[0090] The code description format, content, and location will differ for different code snippets. In this embodiment, the description content corresponding to the selected code snippet is summarized into a triple, including: the method name (caption), input, and output.

[0091] Here, caption is not the method name of the code snippet, but a highly descriptive statement summarizing the method; while input and output may be empty depending on the actual situation, and when organizing these two elements, it is necessary to pay attention to the encapsulation methods of different languages. For example, in C++, the program may pass parameters by modifying external variables through pointers.

[0092] The method description for each code snippet should meet the following format: description i = (caption, input, output) i .

[0093] Finally, the description will be obtained. i With the AST abstracted in step S13 i By bundling, the following set is obtained:

[0094] codes={(AST1, description1), (AST2, description2),..., (AST i description i )}

[0095] Here, codes represents the processed dataset, AST. i The abstract syntax tree representing the i-th code snippet, description i The method description triple for the i-th code snippet.

[0096] In this embodiment, step S2 is specifically as follows:

[0097] In order to obtain the feature vector of the code snippet, the preprocessed abstract syntax tree in step S1 needs to be embedded. In this embodiment, TBCNN is used to embed the abstract syntax tree information of the code snippet.

[0098] S21. Identify subtrees in the abstract syntax tree;

[0099] In this embodiment, the TBCNN method is required to train the abstract syntax tree, so it is necessary to first obtain the subtrees in each abstract syntax tree.

[0100] Select a node with the type of expression statement (expr), declarative statement (decl), or conditional statement (condition) as the root node of the subtree to obtain the corresponding subtree T. i,j .

[0101] Among them, T i,j This represents the j-th subtree under the i-th abstract syntax tree.

[0102] For keywords like if, while, and for, because the subsequent code blocks usually contain a large number of code snippets, making it extremely difficult to identify the representation of their subtrees, these keywords are processed separately into a subtree of size 1 (with only one root node and its content is itself).

[0103] Then we obtain the set of all subtrees of the abstract syntax tree after the above processing: subtrees = {T} 1,1 T 1,2 , ...};T i,j The specific format is as follows:

[0104] T i,j ={(token, type, parent)} i,j,1 (token, type, parent) i,j,2 ,..., (token, type, parent) i,j,n}

[0105] S22. Convert the irregular tree into a binary tree;

[0106] Since all the trees in the extracted ASTs and subtrees sets are irregular trees, we first use the rules for converting trees to binary trees to transform them.

[0107] like Figure 2 As shown, all sibling nodes are connected, and only the leftmost connection between parent and child nodes is retained. Then, the sibling nodes of the original tree are taken as the right child nodes, and the byte nodes of the original tree are taken as the left child nodes. Finally, the binary tree sets ASTs_bin and subtree_bin that can be used for embedding are obtained according to the preorder traversal of the tree.

[0108] in, Figure 2 (a) shows a schematic diagram of the original tree. Figure 2 (b) indicates a line addition operation, where the dashed line represents the line to be deleted. Figure 2 (c) indicates the line erasure operation. Figure 2 (d) indicates a rotation operation.

[0109] The process is represented by C language code as shown in Table 2:

[0110] Table 2

[0111]

[0112] S23. Embed the abstract syntax tree to obtain the feature vector set of the abstract syntax tree;

[0113] After transforming the irregular tree in step S22, TBCNN is used for tree embedding. TBCNN employs a fixed sliding window and attention mechanism to extract the representation of the binary tree, thereby obtaining the feature vector set of the abstract syntax tree.

[0114]

[0115] in, Let i represent the i-th eigenvector.

[0116] First, regarding AST i The token and type are embedded to form the encoding vector of each node. or For these vectors, feature extraction and fusion are performed using TBCNN convolutional forward propagation. Finally, an attention mechanism is used to generate encoded vectors, and the AST is calculated using softmax. i Encoded vector and predicted subtree T i,j The cross-entropy of the encoded vector is calculated, and then the parameters are updated by backpropagation.

[0117] The process of using TBCNN as the encoder is as follows: Figure 3 As shown, the final feature vector set of the abstract syntax tree is obtained:

[0118]

[0119] In this embodiment, step S3 is specifically as follows:

[0120] To generate a logical description of a code snippet, it is necessary to map the abstract syntax book feature vector obtained in step S2 to the code logic description content obtained in step S1, and construct an Encoder-Decoder model for logical description of code snippets.

[0121] S31. Construct a dataset describing the logic of code snippets;

[0122] The sets `codes` obtained in step S14 and `AST_vectors` obtained in step S23 are merged, and each element `code` in set `codes` is... i Replaced with

[0123] S32. Construct the association between code snippet vectors and code descriptions;

[0124] For the set of codes obtained in step S31, based on its... The corresponding description is decoded. A two-layer transformer decoder structure is constructed, in which the masked self-attention layer uses an upper triangular weight matrix to mask the words following each word in the target sequence, so that each word intelligently notices the preceding sequence, that is, it can only be predicted by the preceding words. The contextual representation of the target description is obtained through this layer. The corresponding probability is then calculated using softmax.

[0125] For the generated Calculate the cross-entropy with the previously obtained descriptioni, and then backpropagate to update the parameters.

[0126] S33. Train the description generation model;

[0127] Based on steps S31-S32, an attention model is established from the abstract syntax tree of code snippets to the code description. The dataset `codes` obtained in step S31 is used for training, and the corresponding cross-entropy loss function L during training is:

[0128]

[0129] Where N represents the number of subsets in the dataset codes.

[0130] In this embodiment, step S4 is specifically as follows:

[0131] S41. Enter a code snippet that does not contain code comments;

[0132] The code snippet is preprocessed using the method in step S13 to obtain its corresponding Abstract Syntax Tree (AST).

[0133] S42. Embed the abstract syntax tree of the code snippet;

[0134] Using the method in step S2, the abstract syntax tree (AST) of the code snippet is transformed and embedded to obtain the feature vector of the abstract syntax tree.

[0135] S43. Input the feature representation of the abstract syntax tree into the model;

[0136] Using the attention mechanism model described in step S3, the feature vector of the abstract syntax tree is decoded to obtain the code snippet description. t .

[0137] The description generated in this embodiment t As shown in Table 3:

[0138] Table 3

[0139]

[0140] In summary, the method of this invention can quickly parse non-standard code snippets and reduce the learning and guesswork required by developers through the generated code function descriptions. It increases the capacity of existing reusable component libraries, allowing direct reference and invocation of components, accelerating the development of new systems and improving reuse efficiency. Many well-tested and verified software components, previously abandoned due to high reuse costs, can be reused with the help of this invention, improving the quality and reliability of new systems. These components have already been verified and optimized in other projects, thus using them in new systems reduces the risk of errors and defects, improving software quality. Currently, the biggest cost of software reuse is the learning and application cost of non-standard code. This invention reduces resource investment during the reuse process, including developers' time and effort, thereby lowering development costs. Through low-cost software reuse, developers can focus on the core functions and innovative points of the system without having to write all the code from scratch, enabling them to develop and launch new products more quickly to meet market demands and competitive pressures.

[0141] Those skilled in the art will recognize that the embodiments described herein are intended to help the reader understand the principles of the invention, and should be understood that the scope of protection of the invention is not limited to such specific statements and embodiments. Various modifications and variations can be made to the invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the invention should be included within the scope of the claims of the invention.

Claims

1. A method for describing the functionality of code snippets based on tree-structured neural network machine learning, the specific steps of which are as follows: S1. Select the code dataset for preprocessing, extract the abstract syntax tree of the code snippets, and preprocess the description text of the code. The preprocessing involves obfuscating the source code by encrypting variable names, thereby reducing the impact of variable name tokens on the description of code snippets. S2. Based on step S1, identify the subtrees in the abstract syntax tree, transform the irregular tree into a binary tree, and then embed the abstract syntax tree to obtain the feature vector set of the abstract syntax tree. S21. Identify subtrees in the abstract syntax tree; Select statements with expressions Declarative statements or conditional statement A node of type is used as the root node of a subtree to obtain the corresponding subtree. ; in, Indicates the first The first syntax tree under the syntax tree Each subtree; keywords like if, while, and for are processed into a separate subtree of size 1; Then we obtain the set of all subtrees of the abstract syntax tree after the above processing. ; The specific format is as follows: ; S22. Convert the irregular tree into a binary tree; Due to the extracted and All trees in the set are irregular trees. We first use the rules for converting trees to binary trees to transform them. This involves connecting all sibling nodes, keeping only the leftmost connection between parent and child nodes, then using the original tree's sibling nodes as right children and the original tree's byte nodes as left children. Finally, a set of binary trees suitable for embedding is obtained by performing a preorder traversal of the tree. and ; S23. Embed the abstract syntax tree to obtain the feature vector set of the abstract syntax tree; After transforming the irregular tree in step S22, use Perform tree embedding; A fixed sliding window and attention mechanism are used to extract the representation of the binary tree, resulting in the feature vector set of the abstract syntax tree. ; in, Indicates the first 1 eigenvector; First of all of and Embedding is performed to form the encoding vector for each node. or For these vectors, by using Convolutional forward propagation extracts and fuses features, and finally, an attention mechanism generates an encoding vector. To calculate Encoded vector and predicted subtree The cross-entropy of the encoded vector is then used to update the parameters via backpropagation; Finally, we obtain the feature vector set of the abstract syntax tree: ; S3. Construct a logical description model of the code snippets and train it; S31. Construct a dataset describing the logic of code snippets; For the set obtained in step S14 and the set obtained in step S23 Merge, set Each element Replaced with ; S32. Construct the association between code snippet vectors and code descriptions; For the set obtained in step S31 According to it corresponding Decode; obtain the context representation of the target description. and through The corresponding probability is calculated; For the generated and what was obtained before Calculate the cross-entropy, then backpropagate to update the parameters; S33. Train the description generation model; Based on steps S31-S32, an attention model is built from the abstract syntax tree of the code snippet to the code description; the dataset obtained in step S31 is used. Training is performed, and the corresponding cross-entropy loss function is used during training. for: ; in, Represents the dataset The number of subsets in; S4. Based on steps S1-S3, generate code function descriptions; S41. Enter a code snippet that does not contain code comments; S42. Embed the abstract syntax tree of the code snippet; S43. Input the feature representation of the abstract syntax tree into the model.

2. The method for describing the function of code snippets based on tree neural network machine learning according to claim 1, characterized in that, The specific steps of S1 are as follows: S11, Code Dataset Selection; For the specified programming language and corresponding domain project code, select the code set for the business layer and functional implementation layer, including: the Controller layer and Service layer of Internet software; S12. Preprocess the code dataset selected in step S11; The source code is obfuscated by encrypting variable names, reducing the impact of variable name tokens on the description of code snippets; S13. Extract the abstract syntax tree from the code set; This represents a code snippet after code obfuscation, using... The AST parsing tool in the parser of the language used extracts its abstract syntax tree and uses a depth-first traversal of the node set. The expression is as follows: ; in, Indicates the first The first code snippet 1 node This includes: text features of nodes. Type characteristics and its corresponding parent node ,when for When the value is 0, it indicates that the node is the root node of the entire AST; Each node should then satisfy the format. The set is the collection of abstract syntax trees in the codebase. ; S14. Preprocess the description text of the code; The descriptions corresponding to the selected code snippets exist in different places, including: interface comments at the beginning of the code, implementation comments inside the code, functional descriptions in the requirements document, and method descriptions in the interface document; The description of the selected code snippet is summarized into a triple, which includes: the name of the method. ,enter and output results ; The method description for each code snippet should meet the following format: ; Finally, what will be obtained Abstracted in step S13 By bundling, the following set is obtained: ; in, This represents the processed dataset. Indicates the first An abstract syntax tree for a code snippet. Indicates the first The code snippet describes the method of the triplet.

3. The method for describing the function of code snippets based on tree neural network machine learning according to claim 1, characterized in that, Step S4 is as follows: S41. Enter a code snippet that does not contain code comments; The code snippet is preprocessed using the method in step S13 to obtain its corresponding abstract syntax tree. ; S42. Embed the abstract syntax tree of the code snippet; Using the method in step S2, an abstract syntax tree for the code snippet is generated. The feature vectors of the abstract syntax tree are obtained through transformation and embedding. ; S43. Input the feature representation of the abstract syntax tree into the model; Using the attention mechanism model described in step S3, the feature vectors of the abstract syntax tree are decoded to obtain the code snippet description. .