Table of Contents
Fetching ...

R2ComSync: Improving Code-Comment Synchronization with In-Context Learning and Reranking

Zhen Yang, Hongyi Lin, Xiao Yu, Jacky Wai Keung, Shuo Liu, Pak Yuen Patrick Chan, Yicheng Sun, Fengji Zhang

TL;DR

This work tackles Code-Comment Synchronization (CCS) by leveraging in-context learning (ICL) in large language models (LLMs) augmented with retrieval and post-processing. It introduces R$^2$ComSync, which uses Ensemble Hybrid Retrieval to curate instructive demonstrations from semantic and change-pattern perspectives and applies a Multi-turn Re-ranking strategy with three hierarchical rules to prioritize correct-prone CCS candidates. Across Java and Python datasets, R$^2$ComSync substantially improves CCS metrics over state-of-the-art baselines and gains are corroborated by human evaluation, confirming higher similarity, naturalness, and sensitivity of synchronized comments. The results demonstrate the practicality of LLM-based CCS when paired with targeted retrieval and re-ranking, and provide actionable guidance on model selection, demonstration retrieval, and threshold tuning for real-world software maintenance workflows.

Abstract

Code-Comment Synchronization (CCS) aims to synchronize the comments with code changes in an automated fashion, thereby significantly reducing the workload of developers during software maintenance and evolution. While previous studies have proposed various solutions that have shown success, they often exhibit limitations, such as a lack of generalization ability or the need for extensive task-specific learning resources. This motivates us to investigate the potential of Large Language Models (LLMs) in this area. However, a pilot analysis proves that LLMs fall short of State-Of-The-Art (SOTA) CCS approaches because (1) they lack instructive demonstrations for In-Context Learning (ICL) and (2) many correct-prone candidates are not prioritized.To tackle the above challenges, we propose R2ComSync, an ICL-based code-Comment Synchronization approach enhanced with Retrieval and Re-ranking. Specifically, R2ComSync carries corresponding two novelties: (1) Ensemble hybrid retrieval. It equally considers the similarity in both code-comment semantics and change patterns when retrieval, thereby creating ICL prompts with effective examples. (2) Multi-turn re-ranking strategy. We derived three significant rules through large-scale CCS sample analysis. Given the inference results of LLMs, it progressively exploits three re-ranking rules to prioritize relatively correct-prone candidates. We evaluate R2ComSync using five recent LLMs on three CCS datasets covering both Java and Python programming languages, and make comparisons with five SOTA approaches. Extensive experiments demonstrate the superior performance of R2ComSync against other approaches. Moreover, both quantitative and qualitative analyses provide compelling evidence that the comments synchronized by our proposal exhibit significantly higher quality.}

R2ComSync: Improving Code-Comment Synchronization with In-Context Learning and Reranking

TL;DR

This work tackles Code-Comment Synchronization (CCS) by leveraging in-context learning (ICL) in large language models (LLMs) augmented with retrieval and post-processing. It introduces RComSync, which uses Ensemble Hybrid Retrieval to curate instructive demonstrations from semantic and change-pattern perspectives and applies a Multi-turn Re-ranking strategy with three hierarchical rules to prioritize correct-prone CCS candidates. Across Java and Python datasets, RComSync substantially improves CCS metrics over state-of-the-art baselines and gains are corroborated by human evaluation, confirming higher similarity, naturalness, and sensitivity of synchronized comments. The results demonstrate the practicality of LLM-based CCS when paired with targeted retrieval and re-ranking, and provide actionable guidance on model selection, demonstration retrieval, and threshold tuning for real-world software maintenance workflows.

Abstract

Code-Comment Synchronization (CCS) aims to synchronize the comments with code changes in an automated fashion, thereby significantly reducing the workload of developers during software maintenance and evolution. While previous studies have proposed various solutions that have shown success, they often exhibit limitations, such as a lack of generalization ability or the need for extensive task-specific learning resources. This motivates us to investigate the potential of Large Language Models (LLMs) in this area. However, a pilot analysis proves that LLMs fall short of State-Of-The-Art (SOTA) CCS approaches because (1) they lack instructive demonstrations for In-Context Learning (ICL) and (2) many correct-prone candidates are not prioritized.To tackle the above challenges, we propose R2ComSync, an ICL-based code-Comment Synchronization approach enhanced with Retrieval and Re-ranking. Specifically, R2ComSync carries corresponding two novelties: (1) Ensemble hybrid retrieval. It equally considers the similarity in both code-comment semantics and change patterns when retrieval, thereby creating ICL prompts with effective examples. (2) Multi-turn re-ranking strategy. We derived three significant rules through large-scale CCS sample analysis. Given the inference results of LLMs, it progressively exploits three re-ranking rules to prioritize relatively correct-prone candidates. We evaluate R2ComSync using five recent LLMs on three CCS datasets covering both Java and Python programming languages, and make comparisons with five SOTA approaches. Extensive experiments demonstrate the superior performance of R2ComSync against other approaches. Moreover, both quantitative and qualitative analyses provide compelling evidence that the comments synchronized by our proposal exhibit significantly higher quality.}
Paper Structure (38 sections, 1 equation, 12 figures, 9 tables)

This paper contains 38 sections, 1 equation, 12 figures, 9 tables.

Figures (12)

  • Figure 1: CCS Samples in Liu's Training Set And Panth's Traning Set
  • Figure 2: Sample Analysis of Liu's Training Set
  • Figure 3: The Overview of R$^2$ComSync.
  • Figure 4: The Illustration of CoderBERT Retrieval.
  • Figure 5: LLMs' Performance Variation among Different Shot Numbers across three different datasets.
  • ...and 7 more figures