Abstract
Comments in source code are crucial for developers to understand the purpose of the code and to use it correctly. However, keeping comments aligned with the evolving codebase poses a significant challenge. With increasing interest in automated solutions to identify and rectify discrepancies between code and its associated comments, most existing methods rely heavily on heuristic rules. This paper introduces DocChecker, a language model-based framework adept at detecting inconsistencies between code and comments and capable of generating synthetic comments. This functionality allows DocChecker to identify and rectify cases where comments do not accurately represent the code they describe. The efficacy of DocChecker is demonstrated using the Just-In-Time and CodeXGlue datasets in various scenarios. Notably, DocChecker sets a new benchmark in the Inconsistency Code-Comment Detection (ICCD) task, achieving 72.3% accuracy, and scoring 33.64 in BLEU-4 on the code summarization task. These results surpass other Large Language Models (LLMs), including GPT 3.5 and CodeLlama.
Introduction
In software engineering, comments are vital for maintainability, but they are notoriously difficult to keep updated. As code evolves, comments often become "stale" or inaccurate, leading to developer confusion and potential software defects. This phenomenon, often referred to as "comment rot," presents a significant hurdle for long-term project health.
Existing solutions for detecting these inconsistencies typically fall into two categories: heuristic-based rules, which struggle with complex logic, or general-purpose deep learning models, which often lack the specific training required to handle the subtle semantic relationships between code and natural language. Furthermore, most existing tools focus solely on detection without offering a mechanism for resolution.
Methodology
DocChecker addresses these challenges by leveraging the UniXcoder backbone (a 124M parameter model) and a specialized multi-task pre-training strategy. The framework "bootstraps" its understanding through three simultaneous objectives:
- Code-Text Contrastive Learning (CTC): This aligns the feature spaces of code and text, teaching the model that a specific snippet of code and its correct description should have similar mathematical representations.
- Binary Classification (BC): The model is explicitly trained to distinguish between consistent (positive) and inconsistent (negative) code-comment pairs.
- Comment Generation (CG): This enables the model to act as a "resolving" agent. If an inconsistency is detected, the model uses its decoder to generate a new, accurate summary of the code.
The framework is packaged as a Python library for programmatic use and includes a user-friendly web interface for manual code verification.
Experimental Results
The researchers evaluated DocChecker using several industry-standard benchmarks, including the Just-In-Time (JIT) dataset for detection and CodeXGlue for code summarization across six programming languages.
Performance Benchmarks
- Detection Accuracy: DocChecker set a new benchmark on the ICCD task with 72.3% accuracy, outperforming CodeLlama by 10% and StarCoder by 30%.
- Summarization Quality: On the code summarization task, it achieved a BLEU-4 score of 33.64, nearly doubling the performance of earlier models like RoBERTa (16.57) and CodeBERT (17.83).
- State-of-the-Art Status: The model achieved a new SoTA on the Full Test Set of the JIT dataset with a 74.3% F1-score.
Key Insights
A striking finding of this research is that specialization beats scale. Despite having only 124M parameters, DocChecker outperforms massive models like StarCoder (15B) and CodeLlama (34B). This suggests that for niche software engineering tasks, targeted multi-task pre-training is more effective than raw model size.
Furthermore, the use of "hard negatives" during training—text that is semantically close but technically incorrect—was essential for forcing the model to learn the fine-grained details of code logic. The study also highlighted the superiority of the encoder-decoder architecture for this task, as it provides a better balance between understanding input code and generating descriptive text.
Conclusion and Future Work
DocChecker represents a significant step forward in automated documentation maintenance. While the current framework is highly effective, future work will focus on expanding context windows for longer functions and integrating the tool directly into IDEs like VS Code or IntelliJ to provide real-time "linting" for comments.
The project is open-source and accessible at https://github.com/FSoft-AI4Code/DocChecker.
Summary updated