Skip to main content
QUICK REVIEW

[Paper Review] Deep Learning to Detect Redundant Method Comments

Annie Louis, Santanu Kumar Dash|arXiv (Cornell University)|Jun 12, 2018
Software Engineering ResearchComputer Science28 references9 citations
TL;DR

This paper proposes a deep learning approach to detect redundant method comments by modeling comment entailment from code, using sequence-to-sequence models fine-tuned on code-comment pairs. The tool, Craic, identifies comments that merely restate code (high entailment), showing that Javadoc tags like @param and @throws are at least two times more predictable from code than free-form comments, indicating lower informativeness.

ABSTRACT

Comments in software are critical for maintenance and reuse. But apart from prescriptive advice, there is little practical support or quantitative understanding of what makes a comment useful. In this paper, we introduce the task of identifying comments which are uninformative about the code they are meant to document. To address this problem, we introduce the notion of comment entailment from code, high entailment indicating that a comment's natural language semantics can be inferred directly from the code. Although not all entailed comments are low quality, comments that are too easily inferred, for example, comments that restate the code, are widely discouraged by authorities on software style. Based on this, we develop a tool called CRAIC which scores method-level comments for redundancy. Highly redundant comments can then be expanded or alternately removed by the developer. CRAIC uses deep language models to exploit large software corpora without requiring expensive manual annotations of entailment. We show that CRAIC can perform the comment entailment task with good agreement with human judgements. Our findings also have implications for documentation tools. For example, we find that common tags in Javadoc are at least two times more predictable from code than non-Javadoc sentences, suggesting that Javadoc tags are less informative than more free-form comments

Motivation & Objective

  • To address the lack of practical support for identifying uninformative comments that merely restate code.
  • To develop a machine learning framework that scores comment redundancy without requiring expensive manual annotations.
  • To investigate whether common Javadoc tags produce more predictable, and thus less informative, comments than free-form comments.
  • To evaluate the feasibility of using deep learning to automatically detect comments that are easily inferable from code.

Proposed method

  • The authors define 'comment entailment' as the degree to which a comment's semantics can be inferred from the code, with high entailment indicating redundancy.
  • They train a sequence-to-sequence deep learning model on a large corpus of Java code-comment pairs from GitHub to predict comments from code.
  • The model is fine-tuned using a combination of pretraining on code and fine-tuning on annotated data, with perplexity used as a proxy for entailment.
  • A tool called Craic is built to score method-level comments based on their predicted perplexity, with low perplexity indicating high redundancy.
  • The approach leverages pre-trained language models to exploit large-scale software corpora without requiring manual entailment annotations.
  • The method evaluates comment types (e.g., @param, @return) by comparing their average perplexity to non-Javadoc comments.

Experimental results

Research questions

  • RQ1To what extent can comments be automatically detected as redundant based on their predictability from code?
  • RQ2Are Javadoc tags such as @param and @return more predictable from code than free-form comments, indicating lower informativeness?
  • RQ3How well does a deep learning model trained on code-comment pairs align with human judgments of comment redundancy?
  • RQ4Can perplexity from a sequence-to-sequence model serve as a reliable proxy for comment entailment and redundancy?
  • RQ5What implications do these findings have for the design of documentation generators and developer guidelines?

Key findings

  • Javadoc tags such as @param and @throws are at least two times more predictable from code than non-Javadoc comments, indicating they are less informative.
  • The average perplexity of @param and @throws comments is 6.49 and 2.50 respectively, significantly lower than the 15.58 average for non-Javadoc comments.
  • 180 out of 190 annotated Javadoc comment pairs were judged as entailing or partly entailing by human annotators, confirming high redundancy.
  • The deep learning model’s predictions show strong agreement with human judgments on comment entailment, validating its effectiveness.
  • Common Javadoc fields are systematically less informative than free-form comments, suggesting a need for redesign in documentation tools.
  • The results imply that deep learning models could automate generation of basic comment fields, allowing developers to focus on higher-level explanations.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.