Multi-View Graph Representation for Programming Language Processing: An Investigation into Algorithm Detection

Ting Long, Yutong Xie, Xianyu Chen, Weinan Zhang, Qinxiang Cao, Yong Yu

Introduction

In the field of Programming Language Processing (PLP), representing source code in a format that captures its underlying logic remains a significant challenge. Traditional approaches often rely on Abstract Syntax Trees (ASTs), which represent the structural syntax of code but frequently fail to encapsulate deeper semantic meaning. This limitation is particularly evident in tasks such as algorithm detection, where different syntactic implementations may represent the same logical algorithm, or conversely, similar-looking code may perform entirely different functions. To address this, we present the Multi-View Graph (MVG) representation, a framework designed to prioritize program semantics over syntax.

The Multi-View Graph (MVG) Framework

The core of the MVG approach is the decomposition of source code into four specialized graph views, each capturing a distinct aspect of program logic:

  1. Data-Flow Graph (DFG): Traces the movement of data between variables and constants.
  2. Control-Flow Graph (CFG): Represents the execution order, including branches and loops.
  3. Read-Write Graph (RWG): A bipartite graph detailing the interactions between operations and operands.
  4. Combined Graph (CG): An integrated view that merges the previous three to capture complex interactions.
The MVG pipeline: From source code to representation via four specialized graph views.

As shown in the pipeline above, a rule-based parser generates these views, which are then processed by Gated Graph Neural Networks (GGNNs). Feature extraction is performed via max pooling, and the resulting vectors are concatenated to form a comprehensive representation for downstream classification tasks.

Experimental Setup and Datasets

The model was evaluated on two primary benchmarks:

  • POJ-104: A standard dataset containing 52,000 programs from a programming judge platform.
  • ALG-109: A new, more rigorous multi-label dataset of ~12,000 programs collected from the CSDN developer community. ALG-109 presents a higher difficulty level as single code snippets can be associated with multiple algorithmic labels, such as "Recursion" and "Depth First Search."

Results and Discussion

The MVG framework demonstrated superior performance across both datasets. On POJ-104, it achieved a state-of-the-art accuracy of 94.96%. On the more complex ALG-109, it reached a Micro-F1 score of 65.26%, significantly outperforming existing tree-based and sequence-based models like TBCNN and NCC.

Performance comparison of MVG against baselines (TBCNN, NCC, Devign, LRPG) across various algorithm categories.

Ablation studies revealed that the Data-Flow Graph (DFG) is the most critical component for identifying algorithms. Interestingly, the inclusion of AST information was found to slightly decrease performance, suggesting that pure syntax can act as noise in high-level semantic tasks. Visualization of the representation space further confirmed that MVG produces clearer decision boundaries between similar algorithms compared to baseline models.

Conclusion

The Multi-View Graph representation offers a robust method for capturing the semantic essence of source code. By disentangling different types of program flow, the model achieves high accuracy in algorithm detection even in low-data scenarios. Future research will explore the integration of self-supervised pre-training and the application of this framework to automated programming education tools.

Summary updated

BibTeX
@inproceedings{long2022multi,
  author = {Ting Long and Yutong Xie and Xianyu Chen and Weinan Zhang and Qinxiang Cao and Yong Yu},
  title = {{Multi-View Graph Representation for Programming Language Processing: An Investigation into Algorithm Detection}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2022},
  doi = {10.1609/aaai.v36i5.20522},
}
Figure