ICPC-2018 Deep code comment generation

· ICPC· · code-comment

Paper: Deep code comment generation

DeepCom: NMT + SBT + type substitution

Abstract

DeepCom applies NLP techniques to learn from large-scale corpora and generate comments from them. It uses neural networks to analyze structural information in Java methods and evaluates outputs with machine translation metrics.

Introduction

In software development and maintenance, developers spend about 59% of their time understanding code, which makes code comments important.

Template-based and heuristic approaches suffer from two limitations:

  • When identifiers and method names are poorly chosen, it is difficult to extract accurate keywords.
  • They rely on retrieving similar code fragments and on how similar those fragments are.

The authors cast comment generation as a variant of neural machine translation (NMT): translating from a programming language into natural language. Unlike Code-NN, which models only comments, they model both code and comments. Relative to conventional machine translation, this task poses additional challenges:

  • Code is structured: how to exploit rich structural information to improve existing NMT methods.
  • Vocabulary: natural language may use on the order of 30,000 frequent words, whereas code vocabularies of roughly 200,000 tokens are common because of identifiers and similar tokens.

For structure, they traverse the abstract syntax tree (AST) with the structure-based traversal (SBT) method. For vocabulary, they replace concrete tokens with their types or with <UNK>.

Proposed Approach

avatar

Sequence-to-Sequence Model

The encoders are LSTMs with attention.

Abstract Syntax Tree with SBT traversal

avatar
  • Starting from the root, a pair of parentheses denotes tree structure; the root node itself is placed immediately after the closing parenthesis, e.g., (1)1.

  • Next, traverse each subtree of the root and place each subtree’s root inside parentheses, e.g., (1(2)2(3)3)1.

  • Recurse on each subtree until every node has been visited, yielding a final sequence such as (1(2(4)4(5)5(6)6)2(3)3)1.

Experiment

avataravatar

<HR align=left color=#987cb9 SIZE=1>