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

Cross-Language Learning for Program Classification Using Bilateral Tree-Based Convolutional Neural Networks

Nghi D. Q. Bui, Lingxiao Jiang, Yijun YuWorkshops @ AAAI 2017

Abstract

Towards the vision of translating code that implements an algorithm from one programming language into another, this paper proposes an approach for automated program classification using bilateral tree-based convolutional neural networks (BiTBCNNs). It is layered on top of two tree-based convolutional neural networks (TBCNNs), each of which recognizes the algorithm of code written in an individual programming language. The combination layer of the networks recognizes the similarities and differences among code in different programming languages. The BiTBCNNs are trained using the source code in different languages but known to implement the same algorithms and/or functionalities. For a preliminary evaluation, we use 3591 Java and 3534 C++ code snippets from 6 algorithms we crawled systematically from GitHub. We obtained over 90% accuracy in the cross-language binary classification task to tell whether any given two code snippets implement the same algorithm. Also, for the algorithm classification task, i.e., to predict which one of the six algorithm labels is implemented by an arbitrary C++ code snippet, we achieved over 80% precision.

Introduction

Software engineers frequently encounter code snippets in unfamiliar languages and must identify the underlying logic—for instance, determining if a block of code implements Quick Sort or Merge Sort. While humans can often discern structural similarities across languages, automated tools struggle due to significant differences in syntax, keywords, and API calls. Existing research has primarily focused on token-based models or direct language migration, which often fail to capture high-level structural logic. This paper introduces BiTBCNNs (Bilateral Tree-Based Convolutional Neural Networks), a deep learning architecture designed for cross-language program classification. By processing code as Abstract Syntax Trees (ASTs) rather than raw text, the model identifies whether two snippets from different languages perform the same function.

Methodology

The proposed architecture utilizes a "bilateral" approach, inspired by Siamese networks used in Natural Language Processing. The process involves three key stages:

  1. AST2vec (Pre-training): Code is parsed into an AST. Using a technique similar to word2vec, the model learns vector representations for AST node types (e.g., while, for, if), capturing the semantic context of code structures.
  2. Tree-Based Convolutional Neural Networks (TBCNNs): Unlike standard CNNs that operate on grids or sequences, TBCNNs use sliding subtree filters to extract structural features directly from the tree-shaped AST.
  3. Combination Layer: Two TBCNNs run in parallel. Their outputs are concatenated into a joint feature representation layer, which is then processed by fully connected layers and a final Softmax layer to determine algorithmic similarity.
The BiTBCNN architecture concatenates features from two parallel TBCNNs to classify algorithmic similarity.

Dataset and Preprocessing

The model was trained and evaluated on a custom dataset crawled from GitHub, consisting of 3,591 Java and 3,534 C++ snippets across six classic algorithms: Merge Sort, Bubble Sort, Quick Sort, Linked List operations, Breadth-First Search, and Knapsack. Code was parsed using srcML and converted into ASTs. A unified vocabulary of approximately 450 AST node types was used to create a common representation across languages.

Results and Discussion

The BiTBCNN model focuses on structure over syntax. By prioritizing AST node types over identifier names, the model learns the "skeleton" of an algorithm, making it robust against varying coding styles.

Performance Metrics

The model was evaluated on two primary tasks:

  • Binary Classification: Determining if two snippets (one Java, one C++) implement the same algorithm. The model achieved an overall accuracy exceeding 90%, with high F1-scores for both similar and dissimilar pairs.
  • Algorithm Detection: Identifying which of the six Java algorithm categories an unknown C++ snippet belongs to. The model achieved 80.5% precision, demonstrating successful knowledge transfer from Java to C++.
Performance metrics for binary classification, showing high precision and F1-scores for both similar (1) and dissimilar (0) pairs.

Conclusion

BiTBCNNs offer a promising path for automated program understanding across languages. While the current study focused on well-defined algorithms, future work will explore "program slicing" for more complex software and the integration of identifier semantics to further enhance accuracy. Expanding the scope to more languages like Python and tasks like cross-language code clone detection remains a key objective.

Summary updated

BibTeX
@inproceedings{bui2017cross,
  author = {Nghi D. Q. Bui and Lingxiao Jiang and Yijun Yu},
  title = {{Cross-Language Learning for Program Classification Using Bilateral Tree-Based Convolutional Neural Networks}},
  booktitle = {Workshops @ AAAI},
  year = {2017},
  url = {https://openreview.net/forum?id=B1N_u0eO-S},
}
Figure