Method and apparatus for generating code summaries that support low-resource programming languages

The method translates low-resource code into high-resource code using interlingual translation and core sentence extraction, enhancing semantic consistency and accuracy in code summaries without fine-tuning, addressing the challenges of low-resource languages.

JP7960439B1Active Publication Date: 2026-12-03HANGZHOU DIANZI UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
JP2026149138
Authority / Receiving Office
JP · JP
Patent Type
Patents
Current Assignee / Owner
Priority Date
2026-03-09
Filing Date
2026-07-07
Publication Date
2026-12-03
Estimated Expiration
2046-07-07

AI Technical Summary

Technical Problem

Conventional methods struggle to generate high-quality code summaries for low-resource programming languages due to insufficient language data, costly fine-tuning, and semantic mapping issues, leading to inaccurate summaries and hallucinations.

Method used

A method that translates low-resource code into high-resource code using interlingual translation, multi-temperature sampling, and core sentence extraction, combined with a large-scale language model for pure inference, without fine-tuning, to enhance semantic consistency and accuracy.

Benefits of technology

This approach achieves high-quality code summaries efficiently and cost-effectively by leveraging the inherent reasoning capabilities of large language models, reducing computational resources and improving summary accuracy without requiring parallel data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 0007960439000001_ABST
    Figure 0007960439000001_ABST
Patent Text Reader

Abstract

This invention provides a method and apparatus for generating code summaries that support low-resource programming languages. [Solution] The method involves using a large-scale language model to translate source code of a low-resource programming language into candidate code of a high-resource programming language, selecting the candidate code that is closest to the input source code from among the candidate codes that pass the analysis and verification process to determine the optimal translation code, searching a pre-built knowledge base for multiple codes and their summaries similar to the optimal translation code to use as reference examples, dividing the optimal translation code and reference example code into code statements, and selecting the core statement. The reference example code, core statement and summary, and the optimal translation code and core statement are input to the large-scale language model as a prompt context, and a code summary of the source code of the low-resource programming language is output.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of computers, and relates to the interdisciplinary field of natural language processing and software engineering, and in particular, to a code summary generation method and apparatus supporting low-resource programming languages.

Background Art

[0002] With the rapid development of computer software engineering technology, as a technology that automatically converts complex source code into natural language descriptions, code summaries play a very important role in scenarios such as software maintenance, code understanding, and automatic document generation. In the process of actual development and maintenance, developers often face a large amount of uncommented legacy code and mixed projects written in different programming languages. High-quality code summaries can significantly reduce the time cost for humans to read and understand code, and improve software iteration efficiency.

[0003] Currently, the research and application of code summary technology are mainly concentrated on mainstream high-resource programming languages such as Python and Java. These languages have a huge open-source community and large-scale parallel corpus. For example, the CodeSearchNet dataset provides millions of code-summary pairs, enabling models based on deep learning to be fully trained. However, in scientific computing, statistical analysis, and applications in specific fields, there are many low-resource programming languages that lack support from large-scale language data, such as R language, Julia language, Lua language, Ocaml language, and Racket language. Samples of these languages in public datasets are extremely scarce or completely missing. Therefore, when processing such languages, traditional mainstream models often cannot capture sufficient semantic features, resulting in extremely low accuracy of the generated summaries, which cannot meet the requirements of actual industrial applications.

[0004] Some studies attempt to solve this problem using context-based transfer learning techniques, but these experiments are often limited to "medium-scale resource" languages ​​such as Ruby, which actually have a certain amount of open-source language data. For languages ​​like R and Julia, which truly lack parallel language data, traditional methods such as fine-tuning and transfer learning are ineffective because the training set is insufficient.

[0005] Furthermore, most conventional methods for non-large-scale language models rely on a cumbersome fine-tuning training process, and even with transfer learning, the target language usually requires a certain amount of labeled data to be tuned to the model parameters. This not only increases the consumption of computational resources but also makes it difficult to directly deploy and use the model in a "zero-sample" situation where there is no training data. Also, while large-scale language models acquire extremely powerful general knowledge of high-resource languages ​​from a large amount of data during the pre-training phase, they have difficulty acquiring the grammatical structure and semantic representation of low-resource languages ​​due to the small proportion of samples they encounter. Models acquire the ability to generate general code summaries from large amounts of high-resource language data, but when faced with input from unfamiliar low-resource languages, biases in semantic understanding are likely to occur, and they may not be able to accurately identify the core function and intent of the code. As a result, when performing zero-sample inference directly, the generated summaries deviate from the true meaning of the code, or hallucination may occur.

[0006] In summary, conventional technologies lack a method to fully extract and utilize the accumulated knowledge inherent in large-scale language models, thereby leveraging their powerful contextual learning and inference capabilities to achieve high-quality code summary generation for low-resource programming languages. [Overview of the Initiative] [Problems that the invention aims to solve]

[0007] In response to the shortcomings of conventional technologies, the present invention proposes a code summary generation method and apparatus that supports low-resource programming languages. This method achieves semantic consistency from low-resource code to high-resource code by translating low-resource code into high-resource code, and by combining search extension technology and core sentence selection, it achieves high-quality code summary generation using the pure inference power of a large-scale language model without fine-tuning. This solves the technical problems that low-resource languages ​​have insufficient language data, that fine-tuning conventional models is costly, and that semantic mapping between languages ​​is lacking. [Means for solving the problem]

[0008] A code summary generation method that supports low-resource programming languages, comprising the following steps 1 to 4.

[0009] Step 1: Interlingual Translation

[0010] The process involves using source code from a low-resource programming language as input to a large-scale language model, selecting a high-resource programming language as the target translation language, and generating multiple candidate codes through multi-temperature sampling. Abstract syntactic tree analysis and verification are performed on the candidate codes, and from those that pass verification, the code most semantically closest to the input source code is selected as the optimal translation code.

[0011] Preferably, if none of the candidate code passes the abstract syntax tree analysis verification, the compiler's error reporting information is used to perform multiple iterative code repairs.

[0012] Preferably, the candidate code is translated into the same low-resource programming language as the source code, and the Bilingual Evaluation (BLEU) of the back-translated code and the source code is performed. The Understudy score and Sentence-BERT (Sentence Bidirectional Encoder Representations from Transformers) score are calculated, and the total scores are weighted. The candidate code corresponding to the backtranslation code with the highest total score is selected as the optimal translation code.

[0013] Preferably, the low-resource programming language is Julia, Lua, OCaml, R, or Racket. The high-resource programming language is Python.

[0014] Step 2, Search Extension

[0015] From a pre-built knowledge base, search for multiple codes and their summaries that are similar to the optimal translation code and use them as reference examples.

[0016] Step 3: Core sentence extraction

[0017] The optimal translation code output in Step 1, and the reference example code selected in Step 2. Each sentence is decomposed into nodes of an abstract syntax tree, and each node is mapped to a different type of sentence. The classified sentences are input into a core sentence discrimination model, which infers each sentence and determines whether it is a core sentence or a redundant sentence. The above core sentence discrimination model is a binary classification neural network model of an Encoder-Classifier architecture that has been trained in the training phase. We generate true labels using a greedy selection strategy based on the Common Subsequence (CSI) index.

[0018] Step 4, Fusion Generation

[0019] The reference example code, core sentences and summary, as well as the optimal translation code and core sentences are used as prompt context, input into a large language model, to output the code summary of the input source code.

[0020] A code summary generation device supporting low-resource programming languages, comprising a memory storing a computer program and a processor, wherein the processor implements functions of the following modules when executing the computer program.

[0021] The cross-language translation module is configured to input source code of a low-resource programming language, generate candidate codes through multi-temperature sampling, and output the selected optimal high-resource programming language code through an abstract syntax tree verification, error repair and back-translation optimal selection mechanism.

[0022] The retrieval augmentation module is configured to retrieve, based on the high-resource programming language code, a similar code and its summary from a pre-constructed knowledge base to serve as a reference example.

[0023] The core sentence extraction module is configured to perform abstract syntax tree parsing and sentence splitting on the high-resource programming language code to select important code sentences.

[0024] The fusion generation module is configured to receive the optimal translation code, important code sentences and reference examples, construct a prompt context and input the same into a large language model, to output a final code summary.

Effects of the Invention

[0025] The present invention has the following beneficial effects.

[0026] 1. Utilizing cross-lingual translation, multi-temperature sampling, and a compiler feedback repair mechanism, this approach translates low-resource code into high-resource language code that large language models excel at, without relying on parallel language data for low-resource languages. This solves the challenge of insufficient data for low-resource languages that makes training high-quality models difficult.

[0027] 2. Combining core sentence extraction and retrieval-augmented generation techniques, this method selects the most informative key sentences through sentence extraction, and combines reference examples retrieved by BM25 to effectively enhance the semantic richness of the input context. This significantly improves the accuracy of code summary generation without requiring fine-tuning.

[0028] 3. Fully leveraging the inherent reasoning capabilities of large language models, pure inference is performed and generated through a combination of preset decoding parameter combinations, eliminating the need for expensive parameter fine-tuning of large models. This reduces computational resource consumption and achieves low-cost, high-efficiency automatic code summary generation. [Brief Description of the Drawings]

[0029] [Figure 1] This is a flowchart of a code summary generation method supporting low-resource programming languages. [Figure 2] This is a flowchart of cross-lingual translation in an embodiment. [Figure 3] This is a flowchart of retrieval-augmented generation in an embodiment. [Figure 4] This is a flowchart of core sentence extraction in an embodiment. [Figure 5] This is a flowchart of training a core sentence discrimination model in an embodiment. [Figure 6] This is a flowchart of fusion generation in an embodiment. [Figure 7] This is a system block diagram of a code summary generation device supporting low-resource programming languages. [Modes for carrying out the invention]

[0030] The present invention will be further interpreted and explained below with reference to the drawings.

[0031] A code summary generation method that supports low-resource programming languages, specifically comprising the following steps 1 to 4, as shown in Figure 1.

[0032] Step 1: Interlingual Translation

[0033] As shown in Figure 2, candidate translations are generated by multi-temperature sampling, and the optimal translation code is selected by combining syntactic verification, iterative repair, and backtranslation optimal selection mechanisms.

[0034] S11. First, source code in a low-resource programming language is received and used as input for the large-scale language model. To utilize the large-scale language model's rich pre-training knowledge in the Python language, the target language for translation is set to Python.

[0035] In S12, to avoid the semantic bias that a single translation might introduce, a set of sampling temperatures T = {0, 0.7, 0.9, 1.1} is pre-defined. For temperature T = 0 (greedy mode), one candidate code is generated to obtain the most robust translation result. For the remaining three temperature values ​​T = (0.7, 0.9, 1.1), three candidate codes are generated for each to explore the possibility of different translations. Multi-temperature sampling generates 10 initial candidate codes, forming a candidate pool.

[0036] In S13, the built-in Python compiler is invoked to perform abstract syntax tree parsing verification on the 10 initial candidate codes in the candidate pool. The number of initial candidate codes that passed the parsing is statistically counted, and if at least one initial candidate code was successfully parsed, the repair stage is skipped and the process proceeds directly to S15. If all 10 initial candidate codes fail to parsing, it is determined that the current translation is unusable, and the process proceeds to the iterative repair mechanism in S14.

[0037] In S14, the initial candidate code that failed to be analyzed and the error reporting information generated by the compiler are combined to construct a repair prompt, which is then sent to the large-scale language model for self-correction. To prevent infinite loops, the number of repair attempts is set to 3. After each repair, the process proceeds to S13 to perform abstract syntax tree analysis verification again. Once the maximum number of repair attempts is reached, the repair process stops and the results are output.

[0038] S15, in order to select the code that is most semantically closest to the original input, the initial code that passed parsing and validation The candidate code is retranslated into the original low-resource programming language and denoted as LRPL'. Next, the BLEU score and Sentence-BERT score are calculated between LRPL' and the source code, and the word repetition and deep semantic similarity between LRPL' and the source code are measured. The total score of LRPL' is calculated using a weighted fusion method.

[0039] TotalScore=0.5×BLEU+0.5×Sentence_BERT

[0040] Finally, the initial candidate code corresponding to the LRPL' with the highest TotalScore is selected as the optimal translation code and output.

[0041] Step 2, Search Extension

[0042] As shown in Figure 3, a search engine based on the BM25 algorithm is used, and a knowledge base containing a large number of high-quality code-summary pairs is pre-built. The optimal translation code output in Step 1 is used as the query for the search engine, and the word frequency relevance score with each code in the code-summary pair knowledge base is calculated.

[0043] The words are sorted in descending order based on their word frequency relevance score, and the top three codes with the highest scores and their corresponding summaries are selected as reference examples.

[0044] Step 3: Core sentence extraction

[0045] As shown in Figure 4, deep syntactic analysis is performed on the source code to select the most important sentences containing the most information.

[0046] S31. Using an analysis tool, the optimal translation code output in step 1 and the reference example code selected in step 2 are each decomposed into nodes of an abstract syntax tree, and each node is mapped to a function definition statement, variable definition statement, loop statement, conditional control statement, or other statement.

[0047] In S32, the classified sentences are input into the core sentence discrimination model, each sentence is inferred, and a sentence importance label is output. An importance label of 1 indicates that the sentence is a core sentence, and an importance label of 0 indicates that the sentence is redundant.

[0048] The core sentence discrimination model described above is a binary classification neural network model using a pre-trained Encoder-Classifier architecture. As shown in Figure 5, during the training phase, true labels are generated using a greedy selection strategy based on the ROUGE-L index (Recall-Oriented Understudy for Gisting Evaluation - Longest Common Subsequence). First, the ROUGE-L score between each sentence and its corresponding reference summary is calculated, sorted in descending order of score, and attempts are made to add sentences to the core set one by one. Only when a newly added sentence increases the overall ROUGE-L score of the set against the reference summary is it recognized as containing valid new information, marked as true (i.e., with an importance label of 1), and otherwise marked as non-core (i.e., with an importance label of 0). This strategy ensures that the extracted set of sentences is the shortest in length and covers the most summary information.

[0049] Step 4, Fusion Generation

[0050] As shown in Figure 6, the output results from other stages are integrated to set specific decoding parameters and generate a final summary.

[0051] In S41, a structured template is used to assemble contextual information and construct a prompt, sequentially joining three example blocks, each containing example code, core statements within the code, and a standard summary. Subsequently, a target code block containing the optimal translation code and the core statements within that code is joined. This hierarchical structure guides the large-scale model to gain a deep understanding of the mapping relationship between code logic and summaries.

[0052] S42, in order for the large language model to output the most accurate results in pure inference mode, a set of fixed sampling parameter combinations is injected into the large language model. In this embodiment, the sampling temperature is set to 0.0 to force the model to select the word with the highest probability and eliminate randomness, and the nuclear sampling threshold is set to 0.95 and the number of candidate words to 50 to ensure consistency of generation. The maximum generation length is set to 128 to prevent the generation of excessively long and meaningless text. The stop symbol list is set to include marks such as <|eot_id|> to ensure that generation stops immediately after the summary generation is complete.

[0053] S43. A large-scale language model with 6B to 14B of parameters, which has been fine-tuned for instructions, is loaded. Inference is performed based on the above prompts and parameters, and the final code summary is output directly.

[0054] A code summary generator that supports a low-resource programming language, as shown in Figure 7, comprises an input device, an output device, memory, and a processor, wherein when the processor executes a program in memory, four core functional modules are instantiated, and each module contains a specific execution unit to support the implementation of the above method.

[0055] The interlingual translation module integrates three subunits: multi-temperature sampling, validation and repair, and back-translation optimal selection. These are used to process low-resource code input by the user and output the optimal translation code.

[0056] The search extension module enables accurate retrieval of reference examples from the knowledge base through its built-in BM25 search engine and Top-K interceptor.

[0057] The core sentence extraction module includes two subunits: AST analysis and classification, and core sentence discrimination. It receives data from the translation and search modules and is used to output important sentences.

[0058] The fusion generation module integrates three subunits: prompt construction, decoding setup, and model inference, ultimately generating a summary which is then output by an output device.

[0059] As shown by the flow of arrows in Figure 7, each module is tightly connected via data transmission channels, and these constitute the complete system of the present invention. [Industrial applicability]

[0060] The code summary generation method and apparatus for supporting low-resource programming languages ​​proposed in this invention can be applied to practical situations such as software engineering, scientific computing, and inter-language development collaboration, solving real-world problems such as missing documentation and difficulty in understanding that are faced in the field of low-resource languages. For example,

[0061] In the fields of scientific computing and statistical analysis, languages ​​such as R and Julia are often used for algorithm verification. For script code that is in use but lacks support from engineering documentation, the present invention can automatically generate clear natural language summaries, helping researchers without computer science expertise to quickly understand complex mathematical logic and algorithms, thereby improving the reusability of scientific research code.

[0062] Regarding support for emerging or minority programming languages, in the early stages where large parallel corpora are lacking for functional languages ​​such as OCaml or newly emerging domain-specific languages, the present invention can provide plug-and-play code comprehension support, thereby reducing the learning barrier for developers.

[0063] In managing multilingual projects, for large-scale data science projects involving multiple programming languages ​​(such as mixed development of Python and R), the present invention can automatically generate standardized summaries for low-resource language modules within a project, removing communication barriers between developers with different language stacks and improving the efficiency of team collaboration.

[0064] In the process of assisting with inter-language code migration, for example, when migrating R language code to a Python environment, the summary generated by this invention can be used as a semantic comparison, helping developers verify the consistency of functional logic before and after the migration.

[0065] Although the present invention has been described in detail above, the specific embodiments of the present invention are not limited thereto. All technical solutions formed using equivalent substitutions or equivalent transformations without departing from the spirit and scope of the claims of this application are all within the scope of protection sought by the present invention.

Claims

1. A code summary generation method that supports low-resource programming languages, Computers A language-to-language translation step involves using a large-scale language model to translate source code of a low-resource programming language into candidate code of a target high-resource programming language, selecting the candidate code that is semantically closest to the input source code from among the candidate codes that pass the analysis and verification process, and translating it into the optimal translation code. A search extension step that searches a pre-built knowledge base for multiple codes and their summaries that are similar to the optimal translation code and uses them as reference examples, A core sentence extraction step involves splitting the optimal translation code and reference example code into code sentences and selecting the core sentence, The process involves inputting the example code, core statements, and summary, as well as the optimal translated code and the core statements of the optimal translated code, into a large-scale language model as prompt context, and executing a fusion generation step that outputs a code summary of the source code of a low-resource programming language. A code summary generation method that supports low-resource programming languages, characterized in that the low-resource programming language and the high-resource programming language are distinguished based on the scale of resources of the open-source language data.

2. The code summary generation method for supporting a low-resource programming language according to Claim 1, characterized in that the interlanguage translation step generates a plurality of candidate codes by multi-temperature sampling.

3. The code summary generation method for supporting a low-resource programming language according to Claim 2, characterized in that the interlanguage translation step sets a set of sampling temperatures T = {0, 0.7, 0.9, 1.1}, generates one candidate code for temperature T = 0, and generates three candidate codes for temperatures T = (0.7, 0.9, 1.1).

4. The code summary generation method for supporting a low-resource programming language according to claim 1, characterized in that the low-resource programming language is Julia, Lua, Ocaml, R, or Racket, and the high-resource programming language is Python.

5. The code summary generation method for supporting a low-resource programming language according to Claim 1, characterized in that, in the interlanguage translation step, abstract syntactic tree analysis and verification are performed on the candidate code, and if none of the candidate code passes the verification, the candidate code that failed the analysis and error reporting information are sent to the large-scale language model as a repair prompt to perform self-repair.

6. The code summary generation method for supporting a low-resource programming language according to claim 5, characterized in that, in the interlanguage translation step, the maximum number of repairs is set to 3, the generated candidate code is analyzed and verified again after each repair, and when the maximum number of repairs is reached, the repair is immediately stopped and the result is output.

7. The code summary generation method for supporting a low-resource programming language according to Claim 1, characterized in that the interlanguage translation step involves translating the candidate code into the same low-resource programming language as the source code, calculating the BLEU score and Sentence-BERT score of the back-translated code and the source code, performing a weighted calculation of the total score, and selecting the candidate code corresponding to the back-translated code with the highest total score to make it the optimal translation code.

8. The method for generating a code summary that supports a low-resource programming language according to Claim 1, characterized in that the search extension step uses a search engine based on the BM25 algorithm to set the optimal translation code as a query statement, calculates a word frequency relevance score between the query statement and each code in a pre-built knowledge base, and selects the top three codes with the highest word frequency relevance scores and their corresponding summaries to use as reference examples.

9. In the core sentence extraction step, the code sentence obtained by splitting the optimal translation code and the code of the reference example is input to the core sentence discrimination model to select a core sentence, The core sentence discrimination model is a binary classification neural network model using an Encoder-Classifier architecture, which performs inference for each code sentence and outputs an importance label for the code sentence, where an importance label of 1 indicates that the code sentence is a core sentence, and an importance label of 0 indicates that the code sentence is redundant, and in the training phase, a greedy selection strategy based on the ROUGE-L index is used to generate true labels, specifically, the ROUGE-L score between each code sentence and the corresponding reference summary is calculated, sorted in descending order of score, and attempts are made to add the code sentences to the core set one by one, and only when the newly added code sentence increases the overall ROUGE-L score of the set against the reference summary is it recognized that this code sentence contains valid new information and is marked as true, i.e., the importance label is 1, and otherwise it is marked as non-core, i.e., the importance label is 0, characterized in that the code summary generation method for supporting a low-resource programming language according to claim 1.

10. A code summary generator that supports a low-resource programming language, comprising a memory in which a computer program is stored and a processor, wherein the processor implements the functions of the method according to any one of claims 1 to 9 when the computer program is executed.

Citation Information

Patent Citations

  • Method and terminal for realizing graphical programming

    CN114168123A

  • A method for implementing the block library system by the conversion between the code blocks and the text codes

    KR1020210067286A