[Paper Review] Large Language Models are Few-Shot Summarizers: Multi-Intent Comment Generation via In-Context Learning
The paper shows that large language models (Codex) can generate multi-intent code comments via in-context learning, with strong gains when using ten demonstrations and retrieval-based demonstration strategies plus reranking.
Code comment generation aims at generating natural language descriptions for a code snippet to facilitate developers' program comprehension activities. Despite being studied for a long time, a bottleneck for existing approaches is that given a code snippet, they can only generate one comment while developers usually need to know information from diverse perspectives such as what is the functionality of this code snippet and how to use it. To tackle this limitation, this study empirically investigates the feasibility of utilizing large language models (LLMs) to generate comments that can fulfill developers' diverse intents. Our intuition is based on the facts that (1) the code and its pairwise comment are used during the pre-training process of LLMs to build the semantic connection between the natural language and programming language, and (2) comments in the real-world projects, which are collected for the pre-training, usually contain different developers' intents. We thus postulate that the LLMs can already understand the code from different perspectives after the pre-training. Indeed, experiments on two large-scale datasets demonstrate the rationale of our insights: by adopting the in-context learning paradigm and giving adequate prompts to the LLM (e.g., providing it with ten or more examples), the LLM can significantly outperform a state-of-the-art supervised learning approach on generating comments with multiple intents. Results also show that customized strategies for constructing the prompts and post-processing strategies for reranking the results can both boost the LLM's performances, which shed light on future research directions for using LLMs to achieve comment generation.
Motivation & Objective
- Motivate multi-intent code comment generation to reflect diverse developer intents beyond one-to-one mappings.
- Investigate whether pre-trained LLMs with in-context learning can generate comments from multiple perspectives without fine-tuning.
- Evaluate demonstration quantity, retrieval-based demonstration selection, and post-hoc reranking to maximize performance.
- Compare against a state-of-the-art supervised approach (DOME) on large Java code-comment datasets Funcom and TLC.
Proposed method
- Use OpenAI Codex as the LLM to perform in-context learning for multi-intent code comment generation.
- Provide a prompt template that includes language instruction, intent category, and a set of code demonstrations with corresponding comments.
- Design two retrieval strategies (token-based and semantic-based) to select demonstrations similar to the target code for prompt construction.
- Apply a reranking strategy for generated comments using a reference comment from the most similar retrieved code and compute token-based and semantic similarities.
- Evaluate on Funcom and TLC Java datasets using BLEU, ROUGE-L, and METEOR as metrics.
- Conduct multiple runs (100) to account for randomness in zero/one-shot settings and report averages; 100 runs for reranking evaluation to estimate optimal outcomes.

Experimental results
Research questions
- RQ1RQ1: How effective is Codex on multi-intent comment generation under zero-shot, one-shot, and few-shot learning compared to DOME?
- RQ2RQ2: Can retrieval-based demonstration selection improve Codex performance?
- RQ3RQ3: Can reranking of generated comments further improve Codex results?
Key findings
- Codex improves with more demonstrations; 10-shot prompts outperform DOME on average across BLEU, ROUGE-L, and METEOR.
- Demonstration selection by similarity to the target code substantially boosts performance (BLEU improvements of 97% and 131% on Funcom and TLC, respectively, versus random selection).
- Reranking using a similar code's reference comment yields additional gains (BLEU up to ~9.9% and ~9.6% on Funcom and TLC).
- Zero-shot and one-shot Codex underperform compared to DOME, but 5-shot Codex can be competitive on ROUGE-L and METEOR and 10-shot Codex consistently surpasses DOME on all metrics in the two datasets.
- Across intents, the best Codex results with 10-shot prompts show substantial gains over zero/few-shot baselines and demonstrate the potential of LLMs for multi-intent code comment generation.
- The findings suggest promising directions for prompt design, demonstration retrieval, and post-processing in LLM-based code comment generation.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.