Skip to main content
QUICK REVIEW

[Paper Review] Open Vocabulary Learning on Source Code with a Graph-Structured Cache

Milan Cvitkovic, Badal Singh|arXiv (Cornell University)|Oct 18, 2018
Machine Learning in Materials ScienceMaterials Science20 citations
TL;DR

This paper proposes a Graph-Structured Cache (GSC) to address open-vocabulary challenges in source code representation by encoding out-of-vocabulary words as nodes connected to their usage sites in the code. When combined with graph neural networks on ASTs, the GSC improves code completion and variable naming performance by over 100% on the latter task, with only a 30% increase in training time.

ABSTRACT

Machine learning models that take computer program source code as input typically use Natural Language Processing (NLP) techniques. However, a major challenge is that code is written using an open, rapidly changing vocabulary due to, e.g., the coinage of new variable and method names. Reasoning over such a vocabulary is not something for which most NLP methods are designed. We introduce a Graph-Structured Cache to address this problem; this cache contains a node for each new word the model encounters with edges connecting each word to its occurrences in the code. We find that combining this graph-structured cache strategy with recent Graph-Neural-Network-based models for supervised learning on code improves the models' performance on a code completion task and a variable naming task --- with over $100\%$ relative improvement on the latter --- at the cost of a moderate increase in computation time.

Motivation & Objective

  • To address the challenge of open-vocabulary learning in source code, where new variable and method names are constantly introduced.
  • To improve the performance of graph neural network models on code representation tasks by incorporating dynamic, context-aware vocabulary handling.
  • To enable models to reason over out-of-vocabulary words without relying on fixed, closed vocabularies.
  • To evaluate the effectiveness of the Graph-Structured Cache on real-world code generation and completion tasks.

Proposed method

  • The Graph-Structured Cache (GSC) introduces a node for each new word encountered in the code, connected via edges to all its usage sites in the source code.
  • The GSC is integrated into the Abstract Syntax Tree (AST) to form an augmented graph, which is then processed by a Graph Neural Network (GNN) for downstream tasks.
  • A Pointer Sentinel Mixture model architecture is used, where the decoder combines attention over GSC nodes and a closed vocabulary to predict words.
  • The GSC enables the model to attend to both the structural context of code and the semantic and syntactic roles of rare or unseen words.
  • The model uses a GNN to propagate representations across the AST and GSC, capturing relational dependencies between code elements and their names.
  • The GSC is dynamically built during inference and training, with each new word added as a node linked to its occurrences in the code.

Experimental results

Research questions

  • RQ1Can a graph-structured cache improve model performance on code representation tasks involving out-of-vocabulary words?
  • RQ2How does the relational structure of the GSC compare to simpler OOV handling mechanisms like pointer networks?
  • RQ3To what extent does the GSC improve generalization across seen and unseen code repositories in variable naming tasks?
  • RQ4Does the inclusion of the GSC lead to measurable performance gains in code completion and variable naming, despite increased computational cost?
  • RQ5What components of the GSC architecture are essential for performance, and how do they contribute individually?

Key findings

  • The Graph-Structured Cache improved model accuracy by at least 7% on the code completion task compared to the baseline.
  • On the variable naming task, the GSC achieved a 103% relative improvement in performance over the baseline model.
  • The GSC outperformed a Pointer Sentinel model, indicating that relational information about word usage is crucial for performance.
  • The model maintained strong performance between seen and unseen test repositories, suggesting improved generalization.
  • The computational cost increased by approximately 30% due to the GSC, primarily from increased edge count in the graph.
  • Ablation studies confirmed that both the graph structure and the attention mechanism over GSC nodes are essential for the observed gains.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.