HackerPapers

arXiv:1803.09473cs.LG

code2vec: Learning Distributed Representations of Code

Uri Alon, Meital Zilberstein, Omer Levy, Eran Yahav

Early discovery. Linked by one identifiable commenter. This paper is outside the main ranking; a mention is not an endorsement.

Abstract

We present a neural model for representing snippets of code as continuous distributed vectors ("code embeddings"). The main idea is to represent a code snippet as a single fixed-length $\textit{code vector}$, which can be used to predict semantic properties of the snippet. This is performed by decomposing code to a collection of paths in its abstract syntax tree, and learning the atomic representation of each path $\textit{simultaneously}$ with learning how to aggregate a set of them. We demonstrate the effectiveness of our approach by using it to predict a method's name from the vector representation of its body. We evaluate our approach by training a model on a dataset of 14M methods. We show that code vectors trained on this dataset can predict method names from files that were completely unobserved during training. Furthermore, we show that our model learns useful method name vectors that capture semantic similarities, combinations, and analogies. Comparing previous techniques over the same data set, our approach obtains a relative improvement of over 75%, being the first to successfully predict method names based on a large, cross-project, corpus. Our trained model, visualizations and vector similarities are available as an interactive online demo at http://code2vec.org. The code, data, and trained models are available at https://github.com/tech-srl/code2vec.

arXiv comments
Accepted in POPL 2019
Journal reference
DOI
Subjects
cs.LGMachine Learning cs.AIArtificial Intelligence cs.PLProgramming Languages stat.MLMachine Learning (Statistics)

On Hacker News

Linked by 1 identifiable commenter in 2 comments across 2 threads, from Jun 2018 to Apr 2019.

Comments linking this paper, per year.

Discussed in comments2 threads

    • I like the README.md for StarSpace[1] because it has lots of examples which get you thinking. I used graph embeddings as input to a classifier to classify people when follower/followee information was easy to gather but text wasn't. Basically anything that can be represented as…

      nlView on HNParent context

  1. Deep code search 1 comment
    • I've been playing around in this area for a while and I think there is a lot of potential - although I'm not sure code search is the ultimate expression of how this should be used. There's another interesting paper called code2vec[1]. Code2vec uses the AST of a code snippet and…

      nlView on HNParent context

Submitted to Hacker News

Connected through shared HN threads, not inferred similarity or a recommendation.