Source code abstract generation method

By training the extractor and editor, combining semantics, lexical and syntax similarity, extracting abstract prototypes from similar codes, solving the problem of missing or outdated code summary, achieving high-quality and comprehensive source code summary generation, improving the generalization ability and accuracy of the model.

CN119883271AActive Publication Date: 2025-04-25AVIATION IND INFORMATION CENT +1
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202411790789.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-06
Publication Date
2025-04-25
Estimated Expiration
2044-12-06

AI Technical Summary

Technical Problem

In the prior art, code summary is often missing or outdated, and manual writing and maintenance of summary is cumbersome and time-consuming. The summary generated by traditional information retrieval methods in data sets with low code reuse rates is likely to contain inaccurate or incorrect information.

Method used

By training extractors and editors, using preprocessed open source datasets and abstract syntax tree (AST) sequences, combining semantics, lexical and syntax similarity, extract abstract prototypes from similar codes, and generate high-quality source code summary through deep learning techniques.

Benefits of technology

Effectively distinguish and integrate key information in the search results, reduce irrelevant content, and generate higher quality and comprehensive abstracts, which improves the model's attention and generalization ability to low-frequency words, ensuring the accuracy and comprehensiveness of the abstract.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119883271A_ABST
    Figure CN119883271A_ABST
Patent Text Reader

Abstract

The invention discloses a source code abstract generation method which specifically comprises the following steps: firstly, acquiring an open source data set, preprocessing the data set, and generating an abstract syntax tree (AST) and a SimSBT traversal sequence of each code snippet; then, other code snippets similar to the target code snippets are retrieved from the corpus to serve as abstract prototypes; then, the abstract prototype is refined by means of an extractor, key information is reserved, and redundant content is removed; and finally, generating a target abstract through an encoder. By means of the method, redundant and error information in the abstract prototype can be effectively recognized and corrected, and meanwhile the generated abstract can reflect the actual function of the code more accurately in combination with retrieval and generation strategies.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a source code summary generation method. Background Art

[0002] In recent years, the complexity of software systems has been growing, which has led to a significant increase in software testing and maintenance costs. According to research, in the software development life cycle, the time cost of the maintenance phase accounts for an average of 59% of the total time cost. Code comprehension is a core link in the software development and maintenance process, and its efficiency directly affects the smoothness of the development process and the probability of errors. High-quality code summaries can not only significantly improve the efficiency of code comprehension and reduce errors in the development process, but also play an important role in team collaboration. Through clear code summaries, communication barriers can be reduced and team members can understand each other's code intentions faster. However, in reality, code summaries are often missing or become outdated due to program iterations. Manually writing and maintaining these summaries is cumbersome and time-consuming. In view of this, automatic code summary generation has become an important research topic in the fields of software engineering and natural language processing.

[0003] Traditional code summary generation methods mainly rely on information retrieval technology. Such methods usually build a corpus of code-summary pairs from open source software repositories such as GitHub or software question-and-answer websites, and then extract key information from the source code based on similarity measures in terms of lexical and grammatical aspects. Finally, by retrieving the code snippet that is most similar to the target code snippet, its comments are reused as the summary. Although this method is relatively simple, it has still achieved remarkable results in the field of summary generation, mainly due to the highly structured characteristics of code summaries and their frequent standard phrases such as "return true if", "get the value of", "outputs the" or "throw an exception if". However, traditional methods based on information retrieval still face potential challenges: the similarity between the retrieved code and the source code is limited, which may lead to a large deviation between the generated summary and the actual needs. Especially in datasets with low code reuse rates, the generated summary is more likely to contain inaccurate or even wrong information. Summary of the invention

[0004] The purpose of the present invention is to provide a source code summary generation method in view of the deficiencies in the prior art.

[0005] In a first aspect, the present invention provides a method for generating a source code summary, comprising the following steps: S1: Train extractors and editors using code summarization-related datasets; S2: Use the trained extractor and editor to predict the summary of the source code and generate the corresponding natural language description.

[0006] Preferably, the step S1 comprises the following steps: S11: Obtain open source datasets, perform preprocessing, generate abstract syntax tree (AST) sequences for each code snippet, and build a retrieval corpus; S12: Based on the similarity, similar codes are retrieved from the search corpus to obtain the top k summary prototypes with high similarity; the similarity includes semantic similarity, lexical similarity and grammatical similarity; S13: Refine the summary prototype obtained in S12, retain key words and remove irrelevant information, and establish a summary framework; S14: The summary framework obtained in S13 is regarded as a soft template, and the target summary is generated under the guidance of the source code.

[0007] Preferably, the S11 comprises the following steps: S111: Convert the source code in the open source dataset into an abstract syntax tree structure, traverse the type nodes of the abstract syntax tree, obtain an ordered sequence to enhance the structural information of the source code; match the ordered sequence with the source code to construct a new dataset; S112: Divide the new data set into a training set, a test set, and a validation set, and regard the training set as a retrieval corpus.

[0008] Preferably, the S12 comprises the following steps: S121: For a given source code, extract the embedding of the pre-trained model as a semantic feature vector, and calculate the semantic similarity by L2 distance between the semantic feature vectors; S122: Take any two source code segments and calculate the Jaccard similarity, which is the lexical similarity; S123: traverse the abstract syntax tree to obtain an ordered sequence, calculate the edit distance of the ordered sequence, and use it as the grammatical similarity; S124: n candidate similar code summary pairs are screened out according to the semantic similarity obtained in S121, and then k most similar code summary pairs are selected from the n candidate similar code summary pairs as summary prototypes according to the comprehensive scores of lexical similarity and grammatical similarity obtained in S122 and S123; n>k.

[0009] Preferably, the S13 comprises the following steps: S131: extracting common substrings from the abstract prototype and the target abstract, marking the words in the common substrings as “1” and marking the other words as “0”, forming a label array that the extractor needs to predict, and generating extractor training data from the abstract prototype, the source code, and the corresponding label array; S132: train the extractor using the extractor training data to capture the relationship between the summary prototype and the source code, and construct a summary framework by predicting whether each word in the summary prototype should be retained; Preferably, the S132 includes the following steps: S1321: Inputting the summary prototype and the source code into the extractor simultaneously to obtain corresponding vector representations; S1322: passing the vector representation obtained in S1321 to the linear classification layer to evaluate the probability of each word in the summary prototype being retained; S1323: Generate a summary framework according to the prediction result of S1322.

[0010] Preferably, the S14 specifically includes: Input the result of splicing the summary framework and the source code into the editor to obtain the target summary; Preferably, S2 comprises the following steps: S21: Use the search algorithm to find the closest k code snippets in the retrieval corpus and obtain k summary prototypes; S22: refine the searched summary prototype and input it into the extractor to obtain k summary frames; S23: Filter out a summary frame from the k summary frames, input the summary frame together with the source code into the editor, and output the predicted summary result.

[0011] Preferably, the pre-trained model used in the semantic similarity calculation is a CodeBert model, the pre-trained model used in the extractor is a GraphCodeBert model, and the editor uses a CodeT5 model.

[0012] In a second aspect, the present invention provides a source code summary generation system, including a trained extractor and an editor, to achieve summary prediction of source code and generate corresponding natural language description.

[0013] Compared with the prior art, the source code annotation generation method disclosed in the present invention has at least the following beneficial effects: 1. By refining the summary prototype to extract the structured framework, and organically combining it with the specific content of the source code as the input information of the model. This method can effectively distinguish and integrate the key information in the retrieval results, while excluding irrelevant content, thus overcoming the problem of mixing relevant and irrelevant information in traditional information retrieval methods.

[0014] 2. Combining search technology with deep learning technology not only improves the model's attention to low-frequency words, but also enhances the model's generalization ability, which helps to generate higher quality and more comprehensive summaries.

[0015] 3. By adopting different summary frameworks to train the model, effective data enhancement is achieved, which significantly improves the model's diverse learning ability and thus enhances its generalization performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 The figure is a flow chart of the method of the present invention.

[0017] Figure 2 This is a training flow chart of the extractor and editor of the present invention.

[0018] Figure 3 The figure is a flowchart for constructing the abstract prototype of the present invention.

[0019] Figure 4 The figure is a flow chart for constructing the abstract framework of the present invention.

[0020] Figure 5 A flowchart for constructing a summary of the objectives of the present invention.

[0021] Figure 6 This is a test flow chart of the extractor and editor of the present invention.

[0022] Figure 7 This is one of the embodiments of the method of the present invention.

[0023] Figure 8 This is one of the embodiments of the AST structure diagram and SimSBT traversal sequence diagram construction process of the present invention.

[0024] Fig. 9 This is one of the embodiments of the process of constructing the abstract framework diagram of the present invention. DETAILED DESCRIPTION

[0025] The specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0026] As can be seen from the background technology, traditional methods based on information retrieval still face potential challenges: the similarity between the retrieved code and the source code is limited, which may lead to a large deviation between the generated summary and the actual needs, especially in data sets with low code reuse rates. The generated summary is more likely to contain inaccurate or even wrong information.

[0027] Therefore, the present invention provides a source code summary generation method, which aims to solve the information mixing problem existing in traditional information retrieval methods by integrating the structural information of similar summaries with the specific content of source code. Specifically, the retrieved similar summaries are first used as prototypes to screen out keywords and phrases closely related to the current summary task. In view of the potential inconsistency between the prototype and the target summary, irrelevant information in the prototype is eliminated to extract an abstract retrieval framework. Next, this framework is combined with the source code to provide a richer input for the pre-trained model to fill in the specific vocabulary in the abstract framework. By appropriately adjusting the similar summaries, it is possible to generate a target summary that meets specific needs, in which the similar summaries provide a basic syntactic framework and the source code supplements the specific vocabulary information. This process not only improves the quality of the input information, but also provides more precise guidance for the model, so that it can more effectively use the existing corpus for input enhancement and generate a more accurate and coherent target summary. The present invention can effectively identify and correct redundant and erroneous information in the summary prototype, and at the same time combine the retrieval and generation strategies so that the generated summary more accurately reflects the actual function of the code.

[0028] Specifically, this embodiment relates to a source code summary generation method, see Figure 1 , mainly includes two steps, training phase S1 and generation phase S2. The training phase uses a large amount of high-quality data to train the model; the generation phase uses the trained model to predict the summary of the source code and output a natural language description. Figure 7 .

[0029] S1 specifically includes the following steps: S11: Obtain a large number of open source data sets, preprocess the data sets, obtain the AST of each code snippet, and use the SimSBT method to traverse it and extract the AST sequence representing the code structure. Figure 2 , the specific steps are as follows:

[0030] S111: Get a high-quality source code dataset from the open source platform GitHub, use JavaParser to convert code snippets into an abstract syntax tree structure, and obtain an ordered sequence by traversing the type nodes through the SimSBT method to enhance the structural information of the source code; match the ordered sequence with the source code to construct a new dataset; implement AST and traversal sequence, for example Figure 8 shown.

[0031] S112: Divide the new data set into a training set, a test set, and a validation set according to the ratio of 80%, 10%, and 10%. The training set will be used as the retrieval corpus for subsequent retrieval methods.

[0032] S12: Retrieve similar codes from the corpus based on semantic similarity, lexical similarity, and grammatical similarity to obtain the Top-k summary prototypes, see Figure 3 , as follows: S121: Input the source code into the pre-trained model to obtain the embedding matrix of the code, in which each row is represented as a vector form of a word to obtain a semantic feature vector. The pre-trained model used in this article is CodeBert, and the semantic vector representation is further optimized in combination with the BERT-Whithening operation. The BERT-Whithening operation helps to reduce storage space, increase the speed of model retrieval, and optimize performance. Save the processed vector representation to build a semantic warehouse for subsequent retrieval. The semantic similarity is measured by calculating the L2 distance between given codes. The calculation formula is as follows:

[0033] in and They represent the feature vectors of code snippets A and B after BERT-Whitening optimization, and d is the dimension preserved by the Bert-Whitening operation.

[0034] S122: Segment the given code snippet according to the camel case naming rule, remove duplicates to form a tag set, and use Jaccard similarity to calculate the similarity between the two sets, which is used as a metric for lexical similarity. The formula is as follows:

[0035] in and A set of tags representing code snippets A and B respectively; S123: The grammatical similarity is evaluated by calculating the edit distance of the SimSBT traversal sequence of the abstract syntax tree. The formula is as follows: in represents the Levenshtein distance; S124: First, based on the semantic similarity calculated in S121, the top n most similar candidate codes are selected from the corpus. and grammatical similarity , calculate the comprehensive score of each candidate code The higher the score, the better. The most similar k code snippets are selected from the candidate codes, and their corresponding summaries are used as summary prototypes.

[0036] where 𝜆 is a hyperparameter used to adjust the importance of lexical and grammatical similarity, Represents two source code snippets.

[0037] S13: Refine the summary prototype obtained in S12, retain key information and remove irrelevant parts, and build a summary framework. Figure 4 , the specific steps are as follows:

[0038] S131: In the process of constructing model training data, the following strategy is adopted: the input of the model consists of code snippets and retrieved summary prototypes, and the target output is a label array. The common substring part is extracted from the summary prototype and the target summary, and these words are marked as "1", while other words are regarded as mismatched words and marked as "0", so as to form the label array that the model needs to predict. Finally, the summary framework is generated according to the summary prototype and the label array, that is, the part with the label "0" is replaced with the model placeholder.

[0039] S132: Capture the relationship between the summary prototype and the input code snippet with the help of the extractor. Combine the code snippet and the summary prototype and input them into the extractor to predict whether each word in the prototype should be retained, thereby constructing the final summary framework.

[0040] Fig. 9 The embodiment process of constructing the summary framework is shown. The detailed flow chart of step S132 in this method further includes:

[0041] S1321: After decomposing the summary prototype sequence and the code sequence word by word, they are input into the pre-trained model in the extractor to obtain the corresponding vector representation. The pre-trained model used in this method is GraphCodeBert, and a linear classification layer is added on top of its output layer to adapt to the classification task. The formula is as follows:

[0042] in Represents the model embedding result, represents the input code sequence, represents the summary prototype obtained by S124; The above extractor consists of a pre-trained model and a linear classification layer.

[0043] S1322: The vector obtained in S1321 is expressed as Passed to the linear classification layer, which is responsible for evaluating the probability of retaining each word in the summary prototype If the retention probability of a word is higher than the preset threshold, the label of the corresponding array position is set to "1", otherwise it is set to "0". The formula is as follows:

[0044] in and are two trainable parameters; S1323: Generate a summary framework according to the tag array predicted in S1322. Specifically, the tag array corresponds to each word of the summary prototype, and the word corresponding to the position marked as "0" is replaced with a model placeholder.

[0045] The implementation process of abstract framework construction can be found in Fig. 9 .

[0046] S14: Treat the summary framework obtained in S13 as a soft template and generate the target summary under the guidance of the input code. Figure 5 , the specific steps are as follows:

[0047] S141: Construct a new dataset based on the summary framework generated by S1323. Concatenate the input code snippet and the selected summary framework into a single input sequence and separate them with special markers (such as [SEP]) to ensure that the model can clearly distinguish the two parts.

[0048] S142: During training, each summary frame and its associated input code are combined into a data record. It is worth noting that the same piece of code may be associated with multiple frames, which will generate multiple data records, each of which will produce a corresponding summary, thereby enhancing the training data. This enhancement strategy enables the model to learn a variety of summary frames, thereby improving its generalization ability.

[0049] S2: Use the trained extractor and editor to predict the source code summary and generate the corresponding natural language description. Figure 6 , as follows:

[0050] S21: Use the search algorithm to locate the closest k code snippets in the retrieval corpus constructed in the early stage, and extract the corresponding summaries as summary prototypes.

[0051] S22: The retrieved summary prototype is refined and input into the extractor to generate a summary framework.

[0052] S23: Select the most suitable one from multiple candidate frames to generate a summary. The selection criteria are mainly based on the composition of the label array in the frame: it tends to select frames containing more "1" (retained tokens) and fewer "0" (ignored tokens). Finally, the selected summary frame is input into the editor together with the source code, and the predicted summary result is output. This article uses CodeT5 as the editor.

[0053] The source code summary method of the present invention can be applied to software maintenance scenarios. When existing software needs to be maintained and updated, the source code summary helps maintenance personnel quickly become familiar with the functions and structures of the code, so as to make modifications and optimizations more accurately and reduce maintenance costs.

[0054] Specifically, the software maintenance method may include, for example: Get the problems or areas for improvement in the software; Get the software source code that needs to be maintained from the version control system; A source code summary generation tool is used to generate a summary for the entire software system. The source code summary generation tool here can call the source code summary method involved in the present invention; By reading the source code summary, you can quickly understand the overall architecture of the software and the code logic of the relevant parts of the problem; Conduct a detailed review of the code related to the problem and analyze possible causes and solutions; Develop a specific maintenance plan based on the results of problem analysis and code review; Determine maintenance goals, steps, timelines, and resources required; Modify and optimize source code according to the maintenance plan.

[0055] An embodiment of the present invention may also provide an electronic device. Specifically, the electronic device includes a memory and a processor. The memory stores executable code. When the processor executes the executable code, the method described in any one of the implementation modes is implemented.

[0056] The memory may include high-speed random access memory (RAM), and may also include non-volatile memory (Non-volatile Memory), such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.

[0057] The bus may be an ISA bus, a PCI bus or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc.

[0058] Among them, the memory is used to store the program, and the processor executes the program after receiving the execution instruction. The method executed by the device for flow process definition disclosed in any embodiment of the above-mentioned embodiment of the present invention can be applied to the processor or implemented by the processor.

[0059] The processor may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor or an instruction in the form of software. The above processor may be a general-purpose processor, including a central processing unit (CPU) and a graphics processing unit (GPU). When performing large-scale model reasoning, the choice of GPU as a processor has significant advantages because the GPU can accelerate the reasoning process of the neural network model through high parallel computing capabilities. For more complex deep learning tasks or reasoning involving large models, GPU is an ideal choice; and in some scenarios where resources are relatively tight or the reasoning scale is small, the CPU can still be used as a processor to perform tasks. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present invention may be accelerated by a hardware accelerator (such as GPU, TPU, FPGA, etc.), or executed by combining hardware and software modules in a decoding processor. The software module can be located in a storage medium mature in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.

[0060] The embodiments of the present invention may also provide a computer program product of a readable storage medium, including a computer readable storage medium storing program code, wherein the instructions included in the program code can be used to execute the methods described in the foregoing method embodiments. The specific implementation can be referred to the foregoing method embodiments, which will not be described in detail here.

[0061] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, and other media that can store program codes.

[0062] In summary, the source code summary generation method of the present invention achieves excellent technical effects in extracting source code summaries, and brings significant improvements to fields such as software development and maintenance: The present invention uses semantic, lexical and grammatical similarity to retrieve similar codes and obtain abstract prototypes. Semantically, the L2 distance is calculated by embedding vectors of pre-trained models; lexically, the Jaccard similarity is used after word segmentation based on camel case naming; and the syntax is evaluated by the edit distance of the abstract syntax tree traversal sequence. Multi-dimensional similarity considerations work together to ensure accurate retrieval and lay the foundation for high-quality abstracts.

[0063] The present invention analyzes common substrings from the abstract prototype and the target abstract, constructs a label array with "1" and "0" marks to generate a summary framework, accurately retains key words and removes irrelevant information, makes the core of the summary prominent, concisely and accurately reflects the code function, and realizes accurate extraction of key information.

[0064] The present invention uses CodeBert model for pre-training to optimize semantic vectors, selects GraphCodeBert as the extractor to capture the relationship between prototypes and codes, and uses CodeT5 to generate summaries. The strong semantic parsing of CodeBert, the good relationship mining of GraphCodeBert, and the excellent text generation of CodeT5 can jointly improve the quality and accuracy of summaries.

[0065] Therefore, the traditional information retrieval method leads to summary deviation due to the low similarity between the retrieval code and the source code. The present invention refines the prototype into a framework and combines it with the source code to distinguish and integrate information, overcome the disadvantage of mixed search results, and ensure that the summary fits the real function of the code. It integrates search and deep learning technology to improve the ability to process low-frequency words. It accurately identifies and extracts low-frequency professional vocabulary in specific fields to avoid missing key information, so that the summary can fully and accurately convey the semantics of the code and enhance the comprehensiveness and depth of the summary.

[0066] In addition to the above embodiments, the present invention may also have other implementation modes. Any technical solution formed by equivalent replacement or equivalent transformation is within the protection scope required by the present invention.

[0067] The present invention is described in detail above, but the specific implementation of the present invention is not limited thereto. Those skilled in the art may make various modifications or alterations without departing from the spirit and scope of the claims of the present application.

Claims

1. A source code summary generation method, characterized in that: The following steps are involved: S1: Train extractors and editors using code summarization-related datasets; S2: Use the trained extractor and editor to predict the summary of the source code and generate the corresponding natural language description.

2. The method according to claim 1, characterized in that: The step S1 comprises the following steps: S11: Obtain open source datasets, perform preprocessing, generate abstract syntax tree sequences for each code snippet, and build a retrieval corpus; S12: Based on the similarity, similar codes are retrieved from the search corpus to obtain the top k summary prototypes with high similarity; the similarity includes semantic similarity, lexical similarity and grammatical similarity; S13: Refine the summary prototype obtained in S12, retain key words and remove irrelevant information, and establish a summary framework; S14: The summary framework obtained in S13 is regarded as a soft template, and the target summary is generated under the guidance of the source code.

3. The method according to claim 2, characterized in that: The S11 The steps include: S111: Convert the source code in the open source dataset into an abstract syntax tree structure, traverse the type nodes of the abstract syntax tree, and obtain an ordered sequence to enhance the structural information of the source code; Match the ordered sequence with the source code to construct a new data set; S112: Divide the new data set into a training set, a test set, and a validation set, and regard the training set as a retrieval corpus.

4. The method according to claim 3, characterized in that: The S12 comprises the following steps: S121: For a given source code, extract the embedding of the pre-trained model as a semantic feature vector, and calculate the semantic similarity by L2 distance between the semantic feature vectors; S122: Take any two source code segments and calculate the Jaccard similarity, which is the lexical similarity; S123: traverse the abstract syntax tree to obtain an ordered sequence, calculate the edit distance of the ordered sequence, and use it as the grammatical similarity; S124: n candidate similar code summary pairs are screened out according to the semantic similarity obtained in S121, and then k most similar code summary pairs are selected from the n candidate similar code summary pairs as summary prototypes according to the comprehensive scores of lexical similarity and grammatical similarity obtained in S122 and S123; n>k.

5. The method according to claim 4, characterized in that: The S13 comprises the following steps: S131: extracting common substrings from the abstract prototype and the target abstract, marking the words in the common substrings as "1" and marking the other words as "0" to form a label array that the extractor needs to predict, and generating extractor training data from the abstract prototype, source code, and corresponding label array; S132: Train the extractor using the extractor training data to capture the relationship between the summary prototype and the source code, and construct a summary framework.

6. The method according to claim 5, characterized in that: The S132 comprises the following steps: S1321: Inputting the summary prototype and the source code into the pre-trained model simultaneously to obtain corresponding vector representations; S1322: passing the vector representation obtained in S1321 to the linear classification layer to evaluate the probability of each word in the summary prototype being retained; S1323: Generate a summary framework according to the prediction result of S1322.

7. The method according to claim 2, characterized in that: The S14 is specifically: The result of splicing the summary framework and the source code is input into the editor to obtain the target summary.

8. The method according to claim 1, characterized in that: The S2 comprises the following steps: S21: Find the closest k code snippets in the retrieval corpus and obtain k summary prototypes; S22: refine the searched summary prototype and input it into the extractor to obtain k summary frames; S23: Filter out a summary frame from the k summary frames, input the summary frame together with the source code into the editor, and output the predicted summary result.

9. The method according to claim 7 or 8, characterized in that: The pre-trained model used in the semantic similarity calculation is the CodeBert model, the pre-trained model used in the extractor is the GraphCodeBert model, and the editor uses the CodeT5 model.

10. A source code summary generation system based on the method according to any one of claims 1 to 9, characterized in that Includes trained extractors and editors to predict source code summaries and generate corresponding natural language descriptions.

Citation Information

Patent Citations

  • Abstraction generation method and device and computer equipment

    CN110334334A

  • Decision-based code annotation generation method fusing information retrieval and deep learning

    CN113743064A

  • Long text abstract generation method based on hierarchical BERT model and label migration

    CN116501861A

  • Code abstract generation method fusing abstract syntax tree node features

    CN116820557A

  • Automatic code abstract optimization method based on multi-task hybrid expert network

    CN117827272A