Summarizing Source Code using a Neural Attention Model

40297

Authors

nan

Abstract

High quality source code is often paired with high level summaries of the compu- tation it performs, for example in code documentation or in descriptions posted in online forums. Such summaries are extremely useful for applications such as code search but are expensive to manually author, hence only done for a small frac- tion of all code that is produced. In this paper, we present the first completely data- driven approach for generating high level summaries of source code. Our model, CODE-NN , uses Long Short Term Mem- ory (LSTM) networks with attention to produce sentences that describe C# code snippets and SQL queries. CODE-NN is trained on a new corpus that is auto- matically collected from StackOverflow, which we release. Experiments demon- strate strong performance on two tasks: (1) code summarization, where we estab- lish the first end-to-end learning results and outperform strong baselines, and (2) code retrieval, where our learned model improves the state of the art on a recently introduced C# benchmark by a large mar- gin. 1

Keywords

nan

Full Content

Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics, pages 2073–2083, Berlin, Germany, August 7-12, 2016. c⃝2016 Association for Computational Linguistics Summarizing Source Code using a Neural Attention Model Srinivasan Iyer Ioannis Konstas Alvin Cheung Luke Zettlemoyer Computer Science & Engineering University of Washington Seattle, WA 98195 {sviyer,ikonstas,akcheung,lsz}@cs.washington.edu Abstract High quality source code is often paired with high level summaries of the compu- tation it performs, for example in code documentation or in descriptions posted in online forums. Such summaries are extremely useful for applications such as code search but are expensive to manually author, hence only done for a small frac- tion of all code that is produced. In this paper, we present the first completely data- driven approach for generating high level summaries of source code. Our model, CODE-NN , uses Long Short Term Mem- ory (LSTM) networks with attention to produce sentences that describe C# code snippets and SQL queries. CODE-NN is trained on a new corpus that is auto- matically collected from StackOverflow, which we release. Experiments demon- strate strong performance on two tasks: (1) code summarization, where we estab- lish the first end-to-end learning results and outperform strong baselines, and (2) code retrieval, where our learned model improves the state of the art on a recently introduced C# benchmark by a large mar- gin. 1 Introduction Billions of lines of source code reside in online repositories (Dyer et al., 2013), and high quality code is often coupled with natural language (NL) in the form of instructions, comments, and docu- mentation. Short summaries of the overall com- putation the code performs provide a particularly useful form of documentation for a range of appli- cations, such as code search or tutorials. However, such summaries are expensive to manually author. 1. Source Code (C#): public int TextWidth(string text) { TextBlock t = new TextBlock (); t.Text = text; return (int)Math.Ceiling(t.ActualWidth ); } Descriptions: a. Get rendered width of string rounded up to the nearest integer b. Compute the actual textwidth inside a textblock 2. Source Code (C#): var input = "Hello"; var regEx = new Regex("World"); return !regEx.IsMatch(input ); Descriptions: a. Return if the input doesn’t contain a particular word in it b. Lookup a substring in a string using regex 3. Source Code (SQL): SELECT Max(marks) FROM stud_records WHERE marks < (SELECT Max(marks) FROM stud_records ); Descriptions: a. Get the second largest value of a column b. Retrieve the next max record in a table Figure 1: Code snippets in C# and SQL and their summaries in NL, from StackOverflow. Our goal is to automatically generate summaries from code snippets. As a result, this laborious process is only done for a small fraction of all code that is produced. In this paper, we present the first completely data-driven approach for generating short high- level summaries of source code snippets in natu- ral language. We focus on C#, a general-purpose imperative language, and SQL, a declarative lan- guage for querying databases. Figure 1 shows ex- …

Content truncated to 500 words

Labeled Text

High quality source code is often paired with high level summaries of the computation it performs, for example in code documentation or in descriptions posted in online forums. Such summaries are extremely useful for applications such as code search but are expensive to manually author, hence only done for a small fraction of all code that is produced. In this paper, we present the first completely datadriven approach for generating high level summaries of source code. Our model, CODE-NN , uses Long Short Term Memory (LSTM) networks with attention to produce sentences that describe C# code snippets and SQL queries. CODE-NN is trained on a new corpus that is automatically collected from StackOverflow, which we release. Experiments demonstrate strong performance on two tasks: (1) code summarization, where we establish the first end-to-end learning results and outperform strong baselines, and (2) code retrieval, where our learned model improves the state of the art on a recently introduced C# benchmark by a large margin. 1

Publication Details

Paper ID:
40297
Year:
2016
Publication:
TIPSTER
Publication Type:
conf
DOI:
nan