Learning to Represent Programs with Graphs

Miltiadis Allamanis, Marc Brockschmidt, Mahmoud Khademi
11/1/2017
cs.LGcs.AIcs.PL

Official code: microsoft/graph-based-code-modelling (172 stars, MIT, last commit 2022-12-08).

Abstract

Learning tasks on source code (i.e., formal languages) have been considered recently, but most work has tried to transfer natural language methods and does not capitalize on the unique opportunities offered by code's known syntax. For example, long-range dependencies induced by using the same variable or function in distant locations are often not considered. We propose to use graphs to represent both the syntactic and semantic structure of code and use graph-based deep learning methods to learn to reason over program structures. In this work, we present how to construct graphs from source code and how to scale Gated Graph Neural Networks training to such large graphs. We evaluate our method on two tasks: VarNaming, in which a network attempts to predict the name of a variable given its usage, and VarMisuse, in which the network learns to reason about selecting the correct variable that should be used at a given program location. Our comparison to methods that use less structured program representations shows the advantages of modeling known structure, and suggests that our models learn to infer meaningful names and to solve the VarMisuse task in many cases. Additionally, our testing showed that VarMisuse identifies a number of bugs in mature open-source projects.

View on arXivView PDF

Code Implementations(1)

MIT

Code for "Generative Code Modeling with Graphs" (ICLR'19)

17237C#, PythonJan 10, 20193 years agoMIT

Similar Papers

Cite this paper

@article{allamanis2017learning,
  title  = {Learning to Represent Programs with Graphs},
  author = {Miltiadis Allamanis and Marc Brockschmidt and Mahmoud Khademi},
  year   = {2017},
  eprint = {1711.00740},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/1711.00740}
}

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/1711.00740.svg)](https://codeofpaper.com/paper/1711.00740)

Discussion