Source-linked AI summary

A Neural Architecture for Generating Natural Language Descriptions from Source Code Changes

Pablo Loyola, Edison Marrese-Taylor, Yutaka Matsuo

arXiv:1704.04856v1cs.CL

TL;DR

Static code summaries do not describe program changes, which are relevant to understanding software evolution. This paper uses an attention-augmented encoder-decoder to generate natural-language descriptions of code changes, with semantically sound outputs reported in both in-project and cross-project settings.

  • Problem

    Existing code summarization is static, while source-code changes are important for understanding program evolution.

    Source: §1 · p. 1
  • Method

    An attention-augmented encoder-decoder generates natural-language descriptions of source-code changes.

    Source: §1 · p. 1, §3 · p. 2
  • Results

    The model generated semantically sound descriptions in both in-project and cross-project settings.

    Source: §1 · p. 1
  • Takeaways & Limitations

    The results suggest that change description generation is feasible as a contribution to understanding software evolution from a linguistic perspective.

    Source: §5 · p. 4

    The study uses only single-file atomic commits, reducing the training data by roughly 50% on average.

    Source: §4 · p. 3

Abstract

from arXiv · show

We propose a model to automatically describe changes introduced in the source code of a program using natural language. Our method receives as input a set of code commits, which contains both the modifications and message introduced by an user. These two modalities are used to train an encoder-decoder architecture. We evaluated our approach on twelve real world open source projects from four different programming languages. Quantitative and qualitative results showed that the proposed approach can generate feasible and semantically sound descriptions not only in standard in-project settings, but also in a cross-project setting.

1 Introduction

Existing code summaries describe static code, while this work targets explanations of source-code changes to represent program evolution. The model uses commit changes and messages to generate descriptions, and produces semantically sound results in in-project and cross-project settings.

1 Introduction

  • Existing code summarization is static, while change descriptions target incremental modifications that matter for understanding program evolution.The authors envision support for debugging, repairing, and documenting source-code changes.Source: §1 · p. 1
  • A commit supplies both the change and its explanatory message, which the encoder-decoder model uses to generate a natural-language description.Attention helps the model focus on expressive parts of the input modalities.Source: §1 · p. 1
  • Across twelve real-world software systems, the model generated semantically sound descriptions in both in-project and cross-project settings.Source: §1 · p. 1

2 Related Work

Prior NLP applications in software engineering include code search, bug localization, API suggestion, and source-code summarization. Earlier change summarizers used rules or symbolic execution; this work instead learns descriptions from code changes without hand-crafted features.

2 Related Work

  • NLP methods have been applied to software engineering tasks including code search, traceability, feature location, bug localization, API suggestion, and code completion.Source-code summarization has used information retrieval and representation-learning approaches.Source: §2 · p. 2
  • Iyer et al. (2016) summarize code snippets with an attention-based encoder-decoder, whereas this work targets code changes rather than whole-file descriptions.Source: §2 · p. 2
  • Earlier code-change summarizers used rules or symbolic execution; the authors position their approach as the first to generate descriptions without hand-crafted features.Source: §2 · p. 2

3 Proposed Model

The model learns natural-language descriptions from code-change and description pairs. An attention-augmented encoder-decoder generates the description one word at a time, using source-code context to guide the decoder.

3 Proposed Model

  • Training pairs associate code changes between consecutive project versions with natural-language descriptions, and the model aims to produce the most likely description for an input snippet.Source: §3 · p. 2
  • An encoder embeds the source sequence, while an attention-guided RNN decoder generates natural-language words sequentially.Source: §3 · p. 2
  • The decoder combines its hidden state with a weighted source-code context, whose attention weights assign contributions to code tokens.Source: §3 · p. 2
  • The decoder uses dropout regularization, and beam search generates summaries with a maximum length of 20 words.The reported beam size is 10.Source: §3 · pp. 2–3
  • METEOR selects the checkpoint on validation data, while BLEU-4 is used for test-set evaluation.Source: §3 · p. 3

4 Empirical Study

The empirical study evaluates generated commit descriptions on data from open-source projects, examining atomic, full-history, and cross-project settings.

Data and pre-processing

  • The study collected commit diffs and metadata from twelve GitHub projects—three each in Python, Java, JavaScript, and C++; diffs were lexer-tokenized per line.Commit messages were processed with the Penn Treebank tokenizer.Source: §4 · p. 3

Experimental Setup

  • Restricting training to atomic, single-file commits reduces the data by roughly 50%, while keeping extracted code lines from the same file.The study expects this restriction to increase the likelihood of a direct relation between commit messages and altered lines.Source: §4 · p. 3

Results and Discussion

  • Generated descriptions are generally semantically correlated with references, often favor general terms and rephrasing, but show memorization signs for youtube-dl.The examples include Theano, bitcoin, and youtube-dl changes.Source: §4 · p. 4, Table 2 · p. 4
  • In Python uni-action cross-project tests, BLEU scores were 14.6 for only-adding and 18.9 for only-removing instances, with validation accuracy up to 43.94%.The uni-action dataset contains commits that only add or only remove lines.Source: §4 · pp. 3–4
  • Full-dataset BLEU and validation accuracy remain reasonably consistent despite greater code–language disparity, suggesting representations can compress multifile changes.Full-history commits added an average of 1.97% extra data; NEW FILE delimiters marked code from different files.Source: §4 · pp. 3–4, Table 3 · p. 4
  • Attention heatmaps show soft alignments associating source-code tokens with meaningful words in generated descriptions.Source: §4 · p. 4, Figure 1 · p. 4
  • On atomic data, the model outperforms the baseline in all but one project, with an average gain of 5 BLEU points.The baseline is MOSES.Source: §4 · p. 3, Table 3 · p. 4

5 Conclusion and Future work

The authors propose an encoder-decoder model for generating natural-language descriptions of source-code changes, and view the current results as suggesting feasibility. They identify richer inputs as future work.

  • The paper proposes an encoder-decoder model that automatically generates natural-language descriptions from source-code changes.Source: §5 · p. 4
  • The authors say current results suggest the approach is feasible and could contribute to understanding software evolution if improved.Source: §5 · p. 4
  • Future work will explore richer inputs, including abstract syntax trees and execution traces.Source: §5 · p. 4
Loading 1704.04856v1…