[Paper Review] Cross-Language Learning for Program Classification using Bilateral Tree-Based Convolutional Neural Networks
This paper proposes Bilateral Tree-based Convolutional Neural Networks (BiTBCNNs) to classify programs across programming languages by leveraging shared algorithmic structures in abstract syntax trees (ASTs). Using ASTs from Java and C++ code snippets of six algorithms, the model achieves over 90% accuracy in cross-language binary classification and over 80% precision in multi-class algorithm classification, demonstrating effective transfer learning across languages via tree-structured neural networks.
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.
Motivation & Objective
- To enable automated classification of code snippets based on the algorithm they implement, regardless of programming language.
- To address the challenge of recognizing functional similarity in code across different syntaxes and language-specific idioms.
- To develop a deep learning model that captures structural and semantic similarities in ASTs across programming languages.
- To evaluate the feasibility of cross-language program classification using shared algorithmic patterns.
Proposed method
- The method employs two tree-based convolutional neural networks (TBCNNs), each trained on ASTs from a single programming language (e.g., Java and C++).
- Each TBCNN encodes the structural features of ASTs using learned embeddings for AST node types and fixed-depth subtree filters.
- A bilateral neural network architecture combines the two language-specific TBCNNs to compare and classify code snippets based on their structural and functional similarities.
- The model uses a shared softmax layer to predict the algorithm label by comparing the output representations of two code snippets from different languages.
- ASTs are converted into vector representations (AST2vec) using a skip-gram-like model trained on token sequences from source code, preserving structural and semantic proximity.
- The final classification is performed by comparing the encoded representations of a C++ snippet with those of labeled Java snippets to infer the most likely algorithm.
Experimental results
Research questions
- RQ1Can a deep learning model effectively classify programs across different programming languages based on their underlying algorithmic functionality?
- RQ2How well can a bilateral neural network architecture capture structural and semantic similarities in ASTs from different languages?
- RQ3To what extent can a model trained on one language generalize to classify code in another language when both implement the same algorithm?
- RQ4How does the performance of the model vary when transferring between different algorithms or programming languages?
Key findings
- The BiTBCNN model achieved over 90% accuracy in binary classification, determining whether two code snippets from different languages implement the same algorithm.
- For multi-class algorithm classification, the model achieved a precision of 80.5% when predicting the algorithm of a C++ code snippet based on its AST representation.
- The model demonstrated strong generalization across languages, suggesting that AST-based structural encoding captures language-agnostic algorithmic patterns.
- The use of AST2vec embeddings improved representation learning by preserving semantic and syntactic relationships among AST nodes.
- The model's performance was robust despite removing identifier names, indicating that structural features alone are sufficient for high-accuracy classification.
- The approach shows promise for cross-language code clone detection, algorithm patent analysis, and automated bug fixing, with potential for extension to more languages and algorithms.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.