CIDRe: A Reference-Free Multi-Aspect Criterion for Code Comment Quality Measurement

Maria Dziuba, Valentin MalykharXiv 2025 · OpenReview

Abstract

Effective generation of structured code comments requires robust quality metrics for dataset curation, yet existing approaches (SIDE, MIDQ, STASIS) suffer from limited code-comment analysis. We propose CIDRe, a language-agnostic reference-free quality criterion combining four synergistic aspects: (1) relevance (code-comment semantic alignment), (2) informativeness (functional coverage), (3) completeness (presence of all structure sections), and (4) description length (detail sufficiency). We validate our criterion on a manually annotated dataset. Experiments demonstrate CIDRe's superiority over existing metrics, achieving improvement in cross-entropy evaluation. When applied to filter comments, the models finetuned on CIDRe-filtered data show statistically significant quality gains in GPT-4o-mini assessments.

Introduction

High-quality code documentation is the backbone of maintainable software, yet generating it automatically remains a significant challenge. To train models to write effective comments, researchers require high-quality datasets. However, existing quality metrics have significant blind spots. Many rely on reference dependency (comparing text to a potentially flawed "gold standard"), domain mismatch (using readability indices designed for literature), or language barriers (relying on English-specific lexical databases).

The authors introduce CIDRe (Criterion for Code Comment Quality) to solve these issues by evaluating comments based on their intrinsic relationship with the code, rather than a potentially flawed reference text.

The CIDRe Framework

CIDRe evaluates a code-comment pair through four synergistic aspects that capture different dimensions of quality:

  1. Informativeness (I): Does the comment capture the functional "meat" of the code?
  2. Relevance (R): How well do the code and comment align semantically? This uses a fine-tuned CodeSage-small-v2 model to measure the semantic distance.
  3. Completeness (C): Does the comment cover all structural elements, such as parameters, return values, and exceptions?
  4. Description Length (D): A heuristic where detailed textual explanations before structural sections are linked to better system-wide understanding.
The CIDRe pipeline: Four aspects (Informativeness, Relevance, Completeness, Description length) are processed by a binary classifier to determine comment quality.

These four features are fed into a binary classifier (with SVM proving most effective) that outputs a probability score representing the comment's quality.

Informativeness via Attention

One of the most innovative components of CIDRe is the use of transformer self-attention weights (from the SFR-Embedding-Code-400M_R model) to identify which terms in the code are most important. By creating an "importance map," the metric can prioritize meaningful terms (like player_score) over trivial ones (like id or i) when checking for their presence in the documentation.

Heatmap of term importance derived from transformer self-attention weights, used to calculate the Informativeness score.

Experimental Evaluation

The researchers utilized the StRuCom dataset, containing 153K pairs of structured code comments in Russian across five languages (Python, Java, JS, C#, Go). They established a ground-truth benchmark by manually annotating 840 comments as "good" or "bad."

Key Results

  • Superior Accuracy: In cross-entropy (CE) evaluations—where lower is better—CIDRe (SVM) scored 1.35, significantly outperforming existing metrics like SIDE (5.32) and MIDQ (7.55).
  • Near-Perfect Classification: On the manually annotated test set, the full CIDRe model achieved an F1-score of 0.994.
  • Downstream Gains: The ultimate test involved filtering a training set with CIDRe and fine-tuning an LLM (Qwen2.5-Coder). In side-by-side evaluations using GPT-4o-mini as a judge, models trained on CIDRe-filtered data consistently outperformed those trained on raw or poorly filtered data across all five programming languages.

Conclusion

CIDRe represents a major step forward in automated documentation quality assessment by moving away from reference-based comparisons. By leveraging multi-dimensional analysis and transformer attention mechanisms, it provides a robust, language-agnostic tool for dataset curation. Future work aims to extend this criterion to broader natural language documentation systems and more diverse programming environments.

Summary updated

BibTeX
@misc{dziuba2025cidre,
  author = {Maria Dziuba and Valentin Malykh},
  title = {{CIDRe: A Reference-Free Multi-Aspect Criterion for Code Comment Quality Measurement}},
  year = {2025},
  eprint = {2505.19757},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.19757},
}
Figure