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

Building Program Vector Representations for Deep Learning

Hao Peng, Lili Mou, Ge Li, Yuxuan Liu, Lu Zhang, Zhi Jin

TL;DR

This paper introduces a novel "coding criterion" to generate vector representations for program components (nodes in Abstract Syntax Trees or ASTs). This representation learning approach enables the effective application of deep learning techniques to program analysis, achieving higher accuracy in program classification tasks compared to traditional methods.

What Problem Does This Paper Address?

Deep learning has revolutionized fields like natural language processing and image recognition by automatically learning complex features. However, applying deep learning to program analysis has been hindered by the difficulty of training deep neural networks effectively on program data. Traditional machine learning for program analysis often relies on manual feature engineering, which is time-consuming and task-specific. The core challenge is creating a suitable "pretraining" method for programs that allows deep neural networks to learn meaningful representations, overcoming issues like vanishing/exploding gradients during backpropagation.

Methods

The paper proposes a "coding criterion" to learn vector representations for nodes within a program's Abstract Syntax Tree (AST). The AST is chosen as the representation granularity because it offers a structured, compressed view of a program, unlike raw code or token sequences. The core idea is that the vector representation of a parent AST node should be predictable from the vector representations of its children. This is formalized by aiming to minimize the difference between a parent node's vector and a function (specifically, a tanh activation) of its children's vectors, weighted by their relative importance (number of leaves).

To address the issue of discrete program symbols and ensure meaningful representations, they employ a negative sampling strategy. For each positive example (a parent node and its children), a negative example is created by replacing one of the children with a random, unrelated symbol. The objective is to maximize the distance between the parent and its children's representations while simultaneously maximizing the distance between the parent and the negative sample. This "ranking criterion" helps prevent trivial solutions. The training is performed using stochastic gradient descent with momentum.

Datasets

The paper uses a dataset derived from an online Open Judge (OJ) system, containing C programming language source codes for four different programming problems. This dataset is split into training, cross-validation (CV), and testing sets with a 3:1:1 ratio.

Key Insights and Ideas

  • ASTs as a Foundation for Program Representations: The paper argues that ASTs provide a natural and effective structure for learning program representations, capturing essential structural information that token-level approaches miss.
  • "Coding Criterion" for Representation Learning: The novel "coding criterion" directly links parent and child node representations, enabling a form of unsupervised learning that prepares programs for deep learning.
  • Negative Sampling for Meaningful Representations: The use of negative sampling is crucial for preventing the model from learning trivial representations and for ensuring that similar program components have similar vector embeddings.
  • Deep Learning's Potential for Program Analysis: The success in program classification demonstrates that deep learning, when properly initialized with learned representations, can significantly outperform traditional methods.
  • Bridging the Gap to Deep Learning: The proposed representation learning acts as a "pretraining" step, making deep neural networks trainable and effective for program analysis tasks.

Key Results

  • Qualitative Evaluation: Nearest neighbor queries and k-means clustering on the learned representations showed that similar AST nodes (e.g., ID and Constant, or loop constructs like If/For/While) were clustered together, indicating meaningful embeddings. Dissimilar nodes were correctly separated.
  • Quantitative Evaluation (Program Classification): When feeding the learned representations into a Tree-based Convolutional Neural Network (TCNN), the accuracy reached 95.33%. This significantly outperformed baseline methods like logistic regression (81.16%) and SVM with RBF kernel (91.14%).
  • Improved Optimization and Generalization: Learning curves showed that using the pretrained representations led to much faster convergence and lower errors for both training and cross-validation compared to random initialization.

Limitations and Future Work

  • Limitations: The paper acknowledges that while ASTs capture structural information, they might not fully represent all aspects of program semantics. The "semantic barrier" for capturing precise semantics remains a challenge. The current approach treats all identifiers as the same symbol, which can be a drawback.
  • Future Work: The authors suggest exploring different perspectives for program modeling, such as treating programs as sequences of statements or as 2D signals. They also propose integrating human priors into network architectures (e.g., using CNNs for visual-like program structures) and exploring the combination of formal methods with neural networks. Various applications like bug detection, clone detection, and code retrieval are highlighted as promising future research directions.

Summary updated

BibTeX
@inproceedings{peng2015building,
  author = {Hao Peng and Lili Mou and Ge Li and Yuxuan Liu and Lu Zhang and Zhi Jin},
  title = {{Building Program Vector Representations for Deep Learning}},
  booktitle = {KSEM},
  year = {2015},
  doi = {10.1007/978-3-319-25159-2\_49},
}
Figure