code2seq: Generating Sequences from Structured Representations of Code

Uri Alon, Shaked Brody, Omer Levy, Eran Yahav
8/4/2018
cs.LGcs.PLstat.ML

Official code: tech-srl/code2seq (564 stars, MIT, last commit 2026-06-30).

Abstract

The ability to generate natural language sequences from source code snippets has a variety of applications such as code summarization, documentation, and retrieval. Sequence-to-sequence (seq2seq) models, adopted from neural machine translation (NMT), have achieved state-of-the-art performance on these tasks by treating source code as a sequence of tokens. We present ${\rm {\scriptsize CODE2SEQ}}$: an alternative approach that leverages the syntactic structure of programming languages to better encode source code. Our model represents a code snippet as the set of compositional paths in its abstract syntax tree (AST) and uses attention to select the relevant paths while decoding. We demonstrate the effectiveness of our approach for two tasks, two programming languages, and four datasets of up to $16$M examples. Our model significantly outperforms previous models that were specifically designed for programming languages, as well as state-of-the-art NMT models. An interactive online demo of our model is available at http://code2seq.org. Our code, data and trained models are available at http://github.com/tech-srl/code2seq.

View on arXivView PDF

Code Implementations(1)

tech-srl/code2seqOfficial100%
MIT

Code for the model presented in the paper: "code2seq: Generating Sequences from Structured Representations of Code"

564162C#, JavaDec 6, 20183 months agoMIT
codecode2seqfromgeneratingiclr2019+4 more

Similar Papers

Cite this paper

@article{alon2018codeseq,
  title  = {code2seq: Generating Sequences from Structured Representations of Code},
  author = {Uri Alon and Shaked Brody and Omer Levy and Eran Yahav},
  year   = {2018},
  eprint = {1808.01400},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/1808.01400}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/1808.01400.svg)](https://codeofpaper.com/paper/1808.01400)

Discussion