code2vec

code2vec

โ˜… 3.8 ๐Ÿ”– 1200 saves ๐Ÿ’ฐ Free GitHub

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.

Overview

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.

Key Features

  • Learns vector embeddings of code snippets from AST paths
  • Attention mechanism over paths between syntax tree terminals
  • Predicts method names from code bodies, with a live online demo
  • Official implementation of the POPL 2019 code2vec paper
  • TensorFlow and tf.keras implementations with Java preprocessing
  • Foundation of a research line continued by code2seq
  • MIT-licensed and free for research and commercial use

๐Ÿ’ณ Pricing

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.

Who Is It For

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.

๐Ÿš€ Visit code2vec Official Site

๐Ÿšฉ Report an issue