NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Structural Language Models for Any-Code Generation

Uri Alon, Roy Sadaka, Omer Levy, Eran YahavarXiv 2019

Abstract

Structural Language Modeling (SLM) is a novel approach to "any-code completion" that treats source code as a tree structure rather than a flat sequence of tokens. By utilizing Abstract Syntax Tree (AST) paths to represent context and a syntactic copy mechanism for user-defined symbols, SLM addresses the challenges of unbounded vocabularies and structural complexity in programming languages. Evaluation on Java and C# benchmarks demonstrates that SLM achieves state-of-the-art results, significantly outperforming sequential models and previous structured approaches.

Introduction

Modern code completion tools often struggle with "any-code completion"—the task of generating arbitrary, multi-token expressions or logic involving user-defined symbols. Traditional Natural Language Processing (NLP) models treat code as a linear sequence of words, failing to capture the nested, hierarchical nature of programming languages. This paper identifies two primary hurdles: the unbounded vocabulary of user-defined symbols and the structural complexity inherent in code.

Examples of any-code completion in Java and C# using SLM.

As shown in Figure 1, SLM can predict complex expressions like stats[i].getPath() by leveraging structural context, whereas standard models might struggle with the specific method calls or indexing logic.

Methodology: Structural Language Modeling (SLM)

The core innovation of SLM is representing programs as Abstract Syntax Trees (ASTs) and predicting the next node in the tree rather than the next token in a sequence.

AST Path Representation

To predict a target node, SLM considers the set of paths from every leaf node in the existing tree to the target position. This approach allows the model to capture long-range dependencies—such as a variable declaration at the start of a function—more effectively than sequential models, as structural distance in an AST often better reflects logical relevance than linear distance.

Node-by-Node Generation

Unlike previous models that predict entire grammar rules, SLM generates the AST node-by-node. This provides the flexibility needed for "any-code" tasks, allowing the model to build complex expressions incrementally without premature structural commitments.

Step-by-step generation of an AST for the expression 'if (x > 1)'.

Figure 6 illustrates this process: the model traverses the tree structure, using paths to inform the prediction of subsequent nodes (e.g., the Greater operator, the variable x, and the literal 1).

Syntactic Copy Mechanism

To handle the unbounded vocabulary of user-defined symbols, SLM employs a pointer-style mechanism. It can either generate a common subtoken from a fixed vocabulary or "copy" a symbol from the existing context based on its syntactic relationship (AST path) to the target node.

Evaluation and Results

The model was evaluated on two benchmarks: Java-small (1.3M examples) for any-code tasks and a C# Restricted Completion dataset (16k examples).

Key Results

  • Java Any-Code Completion: SLM achieved an exact-match accuracy@1 of 18.04%, surpassing the previous state-of-the-art (SOTA) of 16.93%.
  • C# Restricted Completion: SLM reached 37.61% accuracy@1, a significant improvement over the previous GNN-based SOTA of 26.42%.
  • Ablation Study: Removing the copy mechanism led to a performance drop from 18% to 10%, highlighting the necessity of referencing existing identifiers.

The authors also introduced the tree@k metric, which measures structural correctness regardless of specific leaf values (variable names). This metric revealed that while models are proficient at predicting the correct logic (syntax), they still face challenges in identifier naming.

Conclusion and Future Work

SLM demonstrates that treating code as a tree significantly improves completion performance. Future directions include integrating compiler feedback to filter out syntactically invalid candidates and expanding context to include project-wide dependencies. Addressing the "naming problem"—where the structure is correct but the identifier is slightly off—remains a key area for improvement.

Summary updated

BibTeX
@misc{alon2019structural,
  author = {Uri Alon and Roy Sadaka and Omer Levy and Eran Yahav},
  title = {{Structural Language Models for Any-Code Generation}},
  year = {2019},
  eprint = {1910.00577},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1910.00577},
}
Figure