Optimizing Knowledge Utilization for Multi-Intent Comment Generation With Large Language Models
- 28 April 2026
- journal article
- Published by Institute of Electrical and Electronics Engineers (IEEE) in IEEE Transactions on Software Engineering
- Vol. 52 (6) , 1791-1804
Abstract
Code comment generation aims to produce a generic overview of a code snippet, helping developers understand and maintain code. However, generic summaries alone are insufficient to meet the diverse needs of practitioners; for example, developers expect the implementation insights to be presented in an untangled manner, while users seek clear usage instructions. This highlights the necessity of multi-intent comment generation. With the widespread adoption of Large Language Models (LLMs) for code-related tasks, these models have been leveraged to tackle the challenge of multi-intent comment generation. Despite their successes, state-of-the-art LLM-based approaches often struggle to construct correct relationships among intents, code, and comments within a smaller number of demonstration examples. To mitigate this issue, we propose a framework named KUMIC for multi-intent comment generation. Built upon in-context learning, KUMIC leverages Chain-of-Thought (CoT) to optimize knowledge utilization for LLMs to generate intent-specific comments. Specifically, KUMIC first designs a retrieval mechanism to obtain similar demonstration examples, which exhibit high code-comment consistency. Then, KUMIC leverages CoT to guide LLMs to focus on statements facilitating the derivation of code comments aligned with specific intents. In this context, KUMIC constructs a mapping knowledge chain — linking code to intent-specific statements to comments — which enables LLMs to follow similar reasoning steps when generating the desired comments.We conduct extensive experiments to evaluate KUMIC, and the results demonstrate that KUMIC outperforms state-of-the-art baselines by 14.49%, 22.41%, 20.72%, and 12.94% in terms of BLEU, METEOR, ROUGE-L, and SBERT, respectively.Keywords
All Related Versions
Funding Information
- National Natural Science Foundation of China (62472310)
- National Natural Science Foundation of China (62322208)
- National Natural Science Foundation of China (62232001)
This publication has 39 references indexed in Scilit:
- Source Code Summarization in the Era of Large Language Models2025
- Explaining Transformer-based Code Models: What Do They Learn? When They Do Not Work?2023
- Developer-Intent Driven Code Comment Generation2023
- Retrieval-Based Prompt Selection for Code-Related Few-Shot Learning2023
- EditSum: A Retrieve-and-Edit Framework for Source Code Summarization2021
- Multi-threshold token-based code clone detection2021
- Detecting Code Clones with Graph Neural Network and Flow-Augmented Abstract Syntax Tree2020
- A Neural Model for Generating Natural Language Summaries of Program Subroutines2019
- AutoComment: Mining question and answer sites for automatic comment generation2013
- Automatic generation of natural language summaries for Java classes2013