A code summary generation method and system based on multimodal feature fusion

The code summary generation model through multi-modal feature fusion uses the tokens, statements and CFG data of the code to extract multi-scale matrix and global structural features, which solves the problem of the existing technology being unable to understand the code semantics and structure, and generates more accurate and Comprehensive code summary.

CN118550580BActive Publication Date: 2024-10-08SHANDONG NORMAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411025297.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-30
Publication Date
2024-10-08
Estimated Expiration
2044-07-30

AI Technical Summary

Technical Problem

Existing code summary methods cannot fully understand the overall code semantic information, obtain important structural features of the code, and closely integrate the feature information of each modality, resulting in inaccurate and incomplete code summaries generated by the model.

Method used

A code summary generation model based on multi-modal feature fusion is used to obtain the tokens, statements and CFG data of the code, perform pre-processing and embedding processing, extract multi-scale matrix and global structural features, and combine cross-features to enhance the fusion module and attention mechanism. ,generate high-quality code summaries.

Benefits of technology

It achieves a more accurate and comprehensive semantic understanding of the code, generates higher-quality code summaries, can better capture the context and structural relationships of the code, and improves the readability and maintainability of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118550580B_ABST
    Figure CN118550580B_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of software maintenance, and specifically relates to a code summary generation method and system based on multimodal feature fusion; the method comprises: obtaining code and performing preprocessing and embedding processing on the code to obtain three embeddings of tokens, sentences and CFG; extracting a multiscale matrix of CFG and performing weighted fusion on the code to obtain a multiscale fusion matrix; processing the three embeddings and the multiscale fusion matrix to obtain tokens features, sentence features and multimodal features; processing the tokens features and sentence features to obtain a cross-fusion feature vector; processing a natural language description and its word position information to obtain a code description feature; inputting the code description feature, the cross-fusion feature vector and the multimodal feature into a decoder for processing to obtain a decoding feature; using an FNF module to process the decoding feature to obtain a prediction summary result; the method can generate a high-quality code summary.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of software maintenance, and in particular relates to a code summary generation method and system based on multimodal feature fusion. Background Art

[0002] With the rapid development of the software industry, code bases are becoming increasingly large and complex. Developers often face the challenge of understanding and maintaining code written by others, especially in the absence of proper documentation. Therefore, high-quality code documentation is essential for maintaining and reusing code. However, in the actual development process, documentation is often missing, outdated, or of poor quality. In addition, understanding existing code has become a very time-consuming process, especially when dealing with large projects or joining new development teams. The emergence of code summary technology effectively alleviates these problems. It can automatically generate concise code descriptions, help developers quickly grasp the functions and structure of the code, and provide timely documentation support, thereby improving the readability and maintainability of the code. Accurate code summaries enable developers to understand and use existing code more quickly, speed up the development process, and promote collaboration between teams. In addition, code summaries also play an important role in code review and quality assurance processes.

[0003] However, although existing code summarization methods provide effective solutions for code summarization tasks and have shown certain effects in some cases, they still have many limitations. For example, they cannot fully understand the overall code semantic information, cannot fully obtain the important structural features of the code, and cannot closely integrate the feature information of each modality. These limitations will affect the model's ability to generate accurate and complete code summaries. Summary of the invention

[0004] In view of the shortcomings of the prior art, the present invention proposes a code summary generation method and system based on multimodal feature fusion, the method comprising: obtaining the code and preprocessing the code, inputting the preprocessed data into a trained code summary generation model based on multimodal feature fusion, and obtaining a code summary generation result;

[0005] The training process of the code summary generation model based on multimodal feature fusion includes the following steps:

[0006] S1: Get the training source code and preprocess it to get three modal data of the code, namely, code tokens, statements and CFG;

[0007] S2: Add corresponding position index information to the three modal data of the code respectively, embed the three modal data and their corresponding position index information to obtain tokens embedding, sentence embedding and CFG embedding;

[0008] S3: Extract the multi-scale matrix of CFG and perform weighted fusion on it to obtain the multi-scale fusion matrix; use GAT to process the CFG embedding and the multi-scale matrix of CFG to obtain the global structural features of CFG;

[0009] S4: Encode the tokens embedding and sentence embedding respectively to obtain the tokens features and sentence features; use the CFG encoder to process the multi-scale fusion matrix and CFG global structure features to obtain the multimodal feature M;

[0010] S5: Three cross-feature enhancement fusion modules are used to process tokens features and sentence features to obtain a cross-fusion feature vector;

[0011] S6: Obtain the natural language description of the code and its word position information, and embed the natural language description and its word position information to obtain the code description embedding; use the Masked attention mechanism to process the code description embedding to obtain the code description feature;

[0012] S7: input the code description feature, the cross-fusion feature vector and the multimodal feature into the decoder for processing to obtain a decoding feature;

[0013] S8: Use the FFN module to process the decoded features and obtain the prediction summary result;

[0014] S9: Calculate the total model loss based on the prediction summary results and adjust the model parameters based on the total model loss to obtain a trained code summary generation model based on multimodal feature fusion.

[0015] Preferably, the process of preprocessing the code includes:

[0016] Screen the code, delete the duplicate code in the code, and obtain the screened code;

[0017] Split the CamelCase and Snake_case code tokens in the filtered code to get the code tokens;

[0018] The filtered code statements are truncated or padded according to a preset maximum length to obtain code statements;

[0019] Use a third-party tool to represent the code as CFG.

[0020] Preferably, the formula for obtaining the multi-scale fusion matrix is:

[0021] A + =αA+βA 2 +γA 3+…+(1-α-β-γ-…)A n

[0022] Among them, A + represents the multi-scale fusion matrix, α, β, and γ represent the first, second, and third weight coefficients respectively; A represents the adjacency matrix of CFG, A n Represents the nth-power matrix of CFG.

[0023] Preferably, in step S4, the formula for obtaining tokens features and sentence features is:

[0024]

[0025]

[0026] Among them, z c-i represents the tokens features obtained after i tokens are embedded and encoded, z s-i represents the sentence features obtained after embedding encoding of the i-th sentence, α c-jj represents the token attention weights of the i-th token and the j-th token, α s-i represents the sentence attention weights of the i-th sentence and the j-th sentence, x j represents the embedding vector of the jth token, y j represents the embedding vector of the jth sentence, W V represents the trainable parameter matrix, Indicates the relative position information between the i-th and j-th tokens. It represents the relative position information between the i-th and j-th statements; n represents the number of token embeddings, and m represents the number of sentence embeddings.

[0027] Preferably, in step S4, the formula for obtaining the multimodal feature is:

[0028]

[0029] Among them, M represents multimodal features, A + Indicates; Q c , K c 、V c Represents the query, key and value of the CFG encoder input respectively; d k Represents the dimension of the attention mechanism output.

[0030] Preferably, step S5 comprises:

[0031] The tokens feature is used as the first Q vector, and the sentence feature is used as the first K vector and the first V vector; the first cross feature enhancement fusion module is used to perform self-attention mechanism processing on the first Q vector, the first K vector and the first V vector to obtain the first fusion feature;

[0032] The tokens feature is used as the second K vector and the second V vector, and the sentence feature is used as the second Q vector. The second cross-feature enhancement fusion module is used to perform self-attention mechanism processing on the second Q vector, the second K vector and the second V vector to obtain the second fusion feature;

[0033] The first fusion feature and the second fusion feature are input into the third cross-feature enhancement fusion module for processing to obtain a cross-fusion feature vector.

[0034] Preferably, in step S6, the process of using the Masked attention mechanism to process the code description embedding includes: embedding the code description as Q, K, V vectors, performing self-attention mechanism processing according to the Q, K, V vectors, and obtaining code description features.

[0035] Preferably, in step S7, the process of obtaining the decoding feature includes:

[0036] The code description feature is used as the Q vector, the cross-fusion feature vector is used as the K vector and the V vector, and the first FAF attention module is used to perform self-attention mechanism processing according to the Q, K and V vectors to obtain the initial decoding vector;

[0037] The initial decoding vector is taken as the Q vector, and the multimodal features are taken as the K vector and the V vector. The second FAF attention module is used to perform self-attention mechanism processing according to the Q, K and V vectors to obtain the decoding features.

[0038] A code summary generation system based on multimodal feature fusion, comprising: a preprocessing module, an embedding module, an encoder module, a fusion module and a joint decoder module;

[0039] The preprocessing module is used to generate three modal data of the code, namely tokens, statements and CFG;

[0040] The embedding module is used to embed the three modal data of the code to generate tokens embedding, sentence embedding and CFG embedding;

[0041] The encoder module is used to encode tokens embedding, sentence embedding and CFG embedding to generate tokens features, sentence features and multimodal features;

[0042] The fusion module is used to fuse tokens features and sentence features to generate a cross-fusion feature vector;

[0043] The joint decoder module is used to process the natural language description and its word position information, multimodal features, and cross-fusion feature vectors, and output a prediction summary result.

[0044] The beneficial effects of the present invention are as follows: in order to address the problem that the information provided by a single token is too one-sided and limits the comprehensive understanding of the overall code semantics, the present invention uses three modes of source code: tokens, statements and CFG to characterize the source code. This method of comprehensive utilization of sequence and structural information aims to provide a more accurate and comprehensive semantic understanding for the code summary task, and ultimately generate a higher quality summary. In response to the problem that the AST of the source code is large, complex and redundant, the present invention proposes to use CFG to represent the code. CFG represents each node as a code statement, obtains the local structural information of the code from the statement level, and the understanding of the model is more intuitive and easy to handle. In addition, in order to more comprehensively capture the context and structural relationships in the code, the present invention uses a multi-scale matrix. This method can effectively capture the dependencies between long-distance sentences, and provides a more comprehensive perspective for understanding complex code structures and logic. Through these strategies, the present invention can more accurately understand and express the essence of the code, and then generate high-quality code summaries. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 It is a flowchart of a code summary generation method based on multimodal feature fusion in the present invention;

[0046] Figure 2 Schematic diagram of the Transformer encoder structure in the present invention;

[0047] Figure 3 It is a schematic diagram of the structure of the CFG encoder in the present invention;

[0048] Figure 4 Schematic diagram of the structure of the cross-feature enhancement fusion module in the present invention. DETAILED DESCRIPTION

[0049] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0050] The present invention proposes a code summary generation method and system based on multimodal feature fusion, the method comprising:

[0051] First, the relevant technical terms involved in the present invention are explained:

[0052] Source code tokens: The words of the source code in a programming language. Sometimes a compound word needs to be split into two common words, that is, split a word into two tokens.

[0053] Multi-scale matrix: This matrix refers to the adjacency matrix and power matrix of CFG, which represents the positional structural relationship between nodes.

[0054] The present invention is based on the deep learning mechanism of multimodal feature fusion based on information sharing, such as Figure 1 As shown, the implementation process is as follows:

[0055] The code is obtained and preprocessed, and the preprocessed data is input into a trained code summary generation model based on multimodal feature fusion to obtain the code summary generation result.

[0056] The training process of the code summary generation model based on multimodal feature fusion includes:

[0057] S1: Get the training code and preprocess it to get three modal data of the code, namely, the tokens, statements and CFG of the code.

[0058] The training code is obtained, and the entire training source code data set is divided into a training set, a validation set, and a test set according to a certain ratio. Preferably, the Java data set is divided in a ratio of 8:1:1, and the Python data set is divided in a ratio of 6:2:2.

[0059] The process of preprocessing the training code includes:

[0060] The codes are filtered and duplicate codes are removed to ensure that they do not intersect, and the codes are obtained as filtered codes.

[0061] Since source code tokens are the basic building blocks of code, they include keywords, operators, variable names, and other elements. Therefore, by analyzing tokens, the model can understand the specific meaning of each word or symbol in the code, and thus have an accurate grasp of the basic syntax and purpose of the code. The CamelCase and Snake_case code tokens in the filtered code are split. After the split operation, all tokens are simple tokens, and the tokens of the code are obtained; the split operation can avoid the OOV (Out-Of-Vocabulary) problem and improve the quality of the generated summary.

[0062] The statements of the filtered code are truncated or filled according to the preset maximum length to obtain the code statements; specifically: the maximum length of each data is set. If it exceeds this length range, the following code sequence needs to be truncated and represented by UNK; if the sequence length is insufficient, a special symbol is used <pad>Pad to maximize the length.

[0063] Use a third-party tool to represent the code as a CFG (Control Flow Graph).

[0064] S2: Add corresponding position index information to the three modal data of the code respectively, embed the three modal data and their corresponding position index information to obtain tokens embedding, sentence embedding and CFG embedding.

[0065] Tokens embedding:

[0066] The present invention uses word embedding to embed the code token sequence. Compared with the traditional word embedding method, this method not only embeds the tokens, but also embeds the absolute position information of the tokens and the index of the sentence. The formula for calculating the token embedding of the source code is as follows:

[0067] Embedd c (t) = W c (t)+P c (t)+L c (t)

[0068] Among them, Embedd c (t) represents the tth token embedding of the code; W c (t) represents the embedding of the tth word in the code sequence, which represents the word token with a vector; P c (t) means embedding the absolute position of the tth token in the code; L c (t) represents the index embedding of the sentence where the t-th tokens is located.

[0069] Statement embedding:

[0070] The present invention performs statement-level processing based on the statement information of the source code to capture the local context information in the code. The formula for calculating the source code statement embedding is as follows:

[0071] Embedd s (l) = W s (l)+P s (l)

[0072] Among them, Embedd s (l) represents the embedding of the lth statement of the code; W s (l) represents the embedding representation of the lth sentence; P s (l) indicates the absolute position of the lth statement in the code snippet, which can also be called the statement index.

[0073] CFG Embedding:

[0074] In the present invention, CFG is used to represent the structural features of the code. In CFG, each node represents a sentence. By encoding a single node, the comprehensive semantic and structural information of the entire sentence can be obtained, thereby obtaining a relatively comprehensive insight. This method uses the BERT pre-training method to embed the nodes of CFG. The formula for calculating the CFG node feature embedding of the code is as follows:

[0075] Embedd g (n) = W g (n)+P g (n)

[0076] Among them, Embedd g (n) represents the nth CFG embedding; W g (n) represents the embedding of the nth CFG node; P g (n) represents the embedding of the node position index.

[0077] It should be noted that during the embedding process, L c (t), P s (l), P g (n) indicates that three index positions are shared, representing the index of the sentence in the code.

[0078] S3: Extract the multi-scale matrix of CFG and perform weighted fusion on it to obtain the multi-scale fusion matrix; use GAT to process the CFG embedding and the multi-scale matrix of CFG to obtain the global structural features of CFG.

[0079] Extracting the multi-scale matrix of CFG represents the adjacency matrix and power matrix, and then performing weighted summation to fuse the structural information of different scales together to accurately capture the relationship between nodes, the hierarchy and dependency of the code. The formula for weighted summation of multi-scale matrices is as follows:

[0080] A + =αA+βA 2 +γA 3 +…+(1-α-β-γ-…)A n

[0081] Among them, A + represents the multi-scale fusion matrix, α, β, and γ represent the first, second, and third weight coefficients respectively; A represents the adjacency matrix of CFG, A n Represents the nth-power matrix of CFG.

[0082] GAT (graph attention model) is used to process CFG embedding and CFG adjacency matrix to obtain the global structural features of CFG. The specific formula is as follows:

[0083]

[0084] in, represents the output of the first layer of GAT, GAT n Represents the GAT layer of CFG. n represents the adjacency matrix of CFG, The initial input of the model is the input CFG embedding. In particular, GAT is the same as the self-attention mechanism and is used to learn the contextual information of all nodes of CFG.

[0085] S4: Encode the tokens embedding and sentence embedding respectively to obtain the tokens features and sentence features; use the CFG encoder to process the multi-scale fusion matrix and CFG global structure features to obtain the multimodal feature M.

[0086] The present invention uses two independent encoders to encode the tokens and sentences of the source code respectively. These two encoders follow the structure of the traditional Transformer encoder, such as Figure 2 shown.

[0087] During the encoding process, the present invention adds the relative position information of tokens and the relative position information of statements in the code snippet to more accurately capture the semantic feature information of the code. The sequential relative position information between the i-th and j-th tokens in the input sequence is defined as The relative position information between the i-th and j-th statements is defined as And integrate this information into the projection of V. The specific formula for propagating the relative position information of tokens and sentences is as follows:

[0088]

[0089]

[0090] Among them, α ij Expressed as weight coefficient; x j represents the embedding vector of the jth token; y j Represented as the embedding vector of the jth sentence; W V represents the trainable parameter matrix; z c-i represents the output vector of the self-attention mechanism of the i-th token, that is, the tokens feature obtained after the i-th token is embedded and encoded, z s-i represents the output vector of the self-attention mechanism of the ith sentence, that is, the sentence features obtained after the ith sentence is embedded and encoded; n represents the number of token embeddings, and n represents the number of sentence embeddings.

[0091] The present invention also adds the relative position information of the two modes to the projection of K so as to calculate e ij The relative position relationship between information is considered when calculating e. Compatibility function is used to compare two input elements. ij , the specific formula is as follows:

[0092]

[0093]

[0094] Among them, e c-ij represents the unnormalized token attention weight, e s-ij represents the unnormalized sentence attention weight; d z represents the dimension of the K vector, W represents the scaling factor used to avoid the dot product result being too large; Q , W K Represents a trainable parameter matrix.

[0095]

[0096]

[0097]

[0098]

[0099] clip(x,k)=max(-k,min(k,x))

[0100] Among them, d ij Indicates the shortest relative distance between the i-th token and the j-th token; D ij Represents the shortest relative distance value between the i-th statement and the j-th statement; Represents the relative position difference between the i-th token and the j-th token; represents the relative position difference between the i-th statement and the j-th statement, k represents the predefined maximum absolute value of the relative position distance, which means that if the relative position between elements exceeds k, it will be regarded as k; clip(x,k) is used to limit the relative position difference to the range of [-k,k], and x is substituted into d ij or D ij .

[0101] The CFG encoder is used to process the multi-scale fusion matrix and CFG global structure features:

[0102] Preferably, the CFG encoder structure is as follows Figure 3 As shown in the figure, the encoder of CFG takes the global structural features of CFG as the input of the model, that is, as Q c , K c and V c , then the multi-scale matrix A + Directly integrated into the self-attention formula. The encoder can not only obtain the global structural features containing all node information, but also capture multiple local structural feature information, so that the model can more comprehensively understand the information represented by CFG.

[0103]

[0104] Among them, d k Represents the dimension of the attention mechanism output.

[0105] S5: Three cross-feature enhancement fusion modules are used to process the tokens features and sentence features to obtain the cross-fusion feature vector F.

[0106] Preferably, the cross-feature enhancement fusion module structure is as follows Figure 4 As shown in the figure, the process of processing tokens features and sentence features includes:

[0107] Take the tokens features as the first Q vector Q t , take the sentence features as the first K vector K l and the first V vector V l ; The first cross-feature enhancement fusion module is used to perform self-attention mechanism processing according to the first Q vector, the first K vector and the first V vector to obtain the first fusion feature F1.

[0108]

[0109] Take the tokens features as the second K vector K t and the second V vector V t , taking the sentence features as the second Q vector, and using the second cross feature enhancement fusion module according to the second Q vector Q l , the second K vector and the second V vector are processed by the self-attention mechanism to obtain the second fusion feature F2.

[0110]

[0111] Among them, d k Set to 64.

[0112] By using two cross-feature enhancement fusion modules to simultaneously receive the feature maps of its own and another modality, and by using multi-head cross-attention to tightly fuse the two feature maps, more accurate and comprehensive feature information can be obtained.

[0113] The first fusion feature and the second fusion feature are input into the third cross-feature enhancement fusion module for processing, that is, the first fusion feature is taken as K and V, and the second fusion feature is taken as Q, and is input into the third cross-feature enhancement fusion module for processing to obtain a cross-fusion feature vector.

[0114] S6: Obtain the natural language description of the code and its word position information, and embed the natural language description and its word position information to obtain the code description embedding; use the Masked attention mechanism to process the code description embedding to obtain the code description feature.

[0115] The natural language description and its word position information are embedded. The embedding process uses the same word embedding technology as the source code tokens. The embedding of the natural language description and the word position information are added together to obtain the code description embedding.

[0116] The Masked attention mechanism is used to process the code description embedding. The code description embedding is used as Q, K, and V vectors. The self-attention mechanism is processed according to the Q, K, and V vectors. The calculation formula is the same as that of the self-attention mechanism operation to obtain the code description features.

[0117] S7: Input the code description features, the cross-fusion feature vectors and the multimodal features into the decoder for processing to obtain decoding features.

[0118] The code description feature is taken as the Q vector, and the cross-fusion feature vector is taken as the K vector and the V vector. The first FAF attention module is used to perform self-attention mechanism processing according to the Q, K and V vectors to obtain the initial decoding vector D F ;

[0119] The initial decoding vector is taken as the Q vector, and the multimodal features are taken as the K vector and the V vector. The second FAF attention module is used to perform self-attention mechanism processing according to the Q, K and V vectors to obtain the decoding feature D G .

[0120] S8: Use the FFN module to process the decoded features and obtain the prediction summary result.

[0121] The FFN module of the present invention is composed of two fully connected layers, receiving D G As input, it is then calculated through the Softmax activation function to get the probability of predicting the summary.

[0122] S9: Calculate the total model loss based on the prediction summary results and adjust the model parameters based on the total model loss to obtain a trained code summary generation model based on multimodal feature fusion.

[0123] The present invention adopts the cross entropy loss function as the total model loss Loss, and the calculation formula is:

[0124]

[0125] Where n represents the total number of code comment pairs in the training set, m represents the maximum length of the generated target code summary, represents the jth word in the i-th sample, It represents the probability that the model generates the corresponding label at the jth position of the i-th sample.

[0126] The present invention also proposes a code summary generation system based on multimodal feature fusion, which can execute the above-mentioned code summary generation method based on multimodal feature fusion, including: a preprocessing module, an embedding module, an encoder module, a fusion module and a joint decoder module;

[0127] The preprocessing module is used to generate three modal data of the code, namely tokens, statements and CFG;

[0128] The embedding module is used to embed the three modal data of the code to generate tokens embedding, sentence embedding and CFG embedding;

[0129] The encoder module is used to encode tokens embedding, sentence embedding and CFG embedding to generate tokens features, sentence features and multimodal features;

[0130] The fusion module is used to fuse tokens features and sentence features to generate a cross-fusion feature vector; by closely fusing the semantic feature information of the two modalities, more accurate and comprehensive semantic feature information is obtained.

[0131] The joint decoder module is used to process the natural language description and its word position information, multimodal features, and cross-fusion feature vectors, and output the prediction summary result. The joint decoder module includes a Masked attention module, a FAF attention module, and a FFN module;

[0132] The Masked attention module is used to process the natural language description and its word position information to obtain the code description features;

[0133] The FAF attention module is used to process the code description features, the cross-fusion feature vectors and the multimodal features to obtain the decoding features;

[0134] The FFN module is used to process the decoding features and output a prediction summary result.

[0135] In summary, the present invention adopts a multimodal feature fusion method based on information sharing. The method aims to make full use of the sequence information and semantic information of the code to obtain more comprehensive local semantic information. Fine-grained source code tokens information and coarse-grained source code statement-level information are used, and a novel fusion strategy is introduced to integrate the two levels of feature information of the code. In addition, in order to obtain more comprehensive structural information, the present invention also uses the control flow graph mode of the source code for code representation, and uses a method of integrating multi-scale matrices into the attention mechanism to capture structural features, and finally generates a high-quality code summary.

[0136] The above embodiments further illustrate the purpose, technical solutions and advantages of the present invention in detail. It should be understood that the above embodiments are only preferred implementation modes of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made to the present invention within the spirit and principles of the present invention should be included in the protection scope of the present invention.< / pad>

Claims

1. A code summary generation method based on multimodal feature fusion, characterized in that: include: Obtain the code and preprocess it, input the preprocessed data into the trained code summary generation model based on multimodal feature fusion to obtain the code summary generation result; The training process of the code summary generation model based on multimodal feature fusion includes the following steps: S1: Get the training code and preprocess it to get three modal data of the code, namely, the code tokens, statements and control flow graph CFG; S2: Add corresponding position index information to the three modal data of the code respectively, embed the three modal data and their corresponding position index information to obtain tokens embedding, sentence embedding and CFG embedding; S3: Extract the multi-scale matrix of CFG and perform weighted fusion on it to obtain the multi-scale fusion matrix; use the graph attention model GAT to process the CFG embedding and the multi-scale matrix of CFG to obtain the global structural features of CFG; the formula for obtaining the multi-scale fusion matrix is: A + =αA+βA 2 +γA 3 +…+(1-a-b-c-…)A n Among them, A + represents the multi-scale fusion matrix, α, β, and γ represent the first, second, and third weight coefficients respectively; A represents the adjacency matrix of CFG, A n Represents the n-th power matrix of CFG; S4: Encode the tokens embedding and sentence embedding respectively to obtain the tokens features and sentence features; use the CFG encoder to process the multi-scale fusion matrix and CFG global structure features to obtain multi-modal features; S5: Three cross-feature enhancement fusion modules are used to process tokens features and sentence features to obtain cross-fusion feature vectors; the formula for obtaining multimodal features is: Among them, M represents multimodal features; Q c , K c 、V c Represents the query, key and value of the CFG encoder input respectively; d k Represents the dimension of the attention mechanism output; S6: Obtain the natural language description of the code and its word position information, and embed the natural language description and its word position information to obtain the code description embedding; use the Masked attention mechanism to process the code description embedding to obtain the code description feature; S7: input the code description feature, the cross-fusion feature vector and the multimodal feature into the decoder for processing to obtain a decoding feature; S8: The FFN module is used to process the decoding features to obtain a prediction summary result. The process of obtaining the decoding features includes: The code description feature is used as the Q vector, the cross-fusion feature vector is used as the K vector and the V vector, and the first FAF attention module is used to perform self-attention mechanism processing according to the Q, K and V vectors to obtain the initial decoding vector; The initial decoding vector is taken as the Q vector, and the multimodal features are taken as the K vector and the V vector. The second FAF attention module is used to perform self-attention mechanism processing according to the Q, K and V vectors to obtain the decoding features. Among them, the Q, K and V vectors are the query vector, the key vector and the value vector respectively. S9: Calculate the total model loss based on the prediction summary results and adjust the model parameters based on the total model loss to obtain a trained code summary generation model based on multimodal feature fusion.

2. According to claim 1, a code summary generation method based on multimodal feature fusion is characterized in that: The process of preprocessing the code includes: Screen the code, delete the duplicate code in the code, and obtain the screened code; Split the CamelCase and Snake_case code tokens in the filtered code to get the code tokens; The filtered code statements are truncated or padded according to a preset maximum length to obtain code statements; Represent the code as a CFG.

3. According to the method for generating a code summary based on multimodal feature fusion according to claim 1, it is characterized in that: In step S4, the formula for obtaining tokens features and sentence features is: Among them, z c-i represents the tokens features obtained after i tokens are embedded and encoded, z s-i represents the sentence features obtained after embedding encoding of the i-th sentence, α c-ij represents the token attention weights of the i-th token and the j-th token, α s-ij represents the sentence attention weights of the i-th sentence and the j-th sentence, x j represents the embedding vector of the jth token, y j represents the embedding vector of the jth sentence, W V represents the trainable parameter matrix, Indicates the relative position information between the i-th and j-th tokens. It represents the relative position information between the i-th and j-th statements; n represents the number of token embeddings, and m represents the number of sentence embeddings.

4. The method for generating a code summary based on multimodal feature fusion according to claim 1, characterized in that: In step S5, the process of obtaining the cross-fusion feature vector includes: The tokens feature is used as the first Q vector, and the sentence feature is used as the first K vector and the first V vector; the first cross feature enhancement fusion module is used to perform self-attention mechanism processing on the first Q vector, the first K vector and the first V vector to obtain the first fusion feature; The tokens feature is used as the second K vector and the second V vector, and the sentence feature is used as the second Q vector. The second cross-feature enhancement fusion module is used to perform self-attention mechanism processing on the second Q vector, the second K vector and the second V vector to obtain the second fusion feature; The first fusion feature and the second fusion feature are input into the third cross-feature enhancement fusion module for processing to obtain a cross-fusion feature vector.

5. The code summary generation method based on multimodal feature fusion according to claim 1 is characterized in that: In step S6, the process of using the Masked attention mechanism to process the code description embedding includes: embedding the code description as Q, K, V vectors, performing self-attention mechanism processing according to the Q, K, V vectors, and obtaining code description features.

6. A code summary generation system based on multimodal feature fusion, the system is used to execute any one of the code summary generation methods based on multimodal feature fusion according to claims 1 to 5, characterized in that: include: Preprocessing module, embedding module, encoder module, fusion module and joint decoder module; The preprocessing module is used to generate three modal data of the code, namely tokens, statements and CFG; The embedding module is used to embed the three modal data of the code to generate tokens embedding, sentence embedding and CFG embedding; The encoder module is used to encode tokens embedding, sentence embedding and CFG embedding to generate tokens features, sentence features and multimodal features; The fusion module is used to fuse tokens features and sentence features to generate a cross-fusion feature vector; The joint decoder module is used to process the natural language description and its word position information, multimodal features, and cross-fused feature vectors, and output a prediction summary result.

7. The code summary generation system based on multimodal feature fusion according to claim 6, characterized in that: The joint decoder module includes a Masked attention module, a FAF attention module and a FFN module; The Masked attention module is used to process the natural language description and its word position information to obtain the code description features; The FAF attention module is used to process the code description features, the cross-fusion feature vectors and the multimodal features to obtain the decoding features; The FFN module is used to process the decoding features and output a prediction summary result.