code2vec is an open-source neural network that learns distributed representations of code: it embeds code snippets into vectors that capture semantic similarity, famously powering a demo that predicts method names from code bodies. Released under the MIT license by researchers at the Technion, it has about 1,100 stars on GitHub and was last updated in 2023.
Published at POPL 2019 by Uri Alon and colleagues, code2vec was a landmark in machine learning for code. The model represents a code snippet as a set of paths through its abstract syntax tree, between terminal tokens, and learns attention over those paths to produce a single code vector. That vector can then be used for downstream tasks, most visibly predicting a method’s name from its body, which the online demo at code2vec.org lets anyone try. The repository contains the official TensorFlow implementation, including a tf.keras version, plus the preprocessing pipeline for Java code. code2vec launched a research line that continued with code2seq and structural language models of code, and it remains a standard citation and teaching example for how neural models can learn from the structure of programs rather than treating code as plain text.
code2vec is free and open source under the MIT license. The code, trained models and online demo are available at no cost; you only need your own compute for training.
code2vec is for researchers and students in machine learning for code, and for developers curious about how neural embeddings of programs work, from code search and summarization to automated documentation.