Hierarchical Abstract Syntax Tree Representation Learning Based on Graph Coarsening for Program Classification

Y. J. Yang, Yuzhang Lee, Zeyu He, Chunlu Wang · 2023

Abstract Syntax Tree (AST) is a graph structure obtained from code syntax analysis whose representation has recently played an increasingly important role in program classification. In our study, we innovatively propose that a better AST representation should be hierarchical, combined with both low-and-high level features of the program in AST. Low-level program features in AST are mainly affected by code and writing style. Higher-level program features, such as the structure and logic of the program, are constituted by code blocks as program codes in the same code block share similar program logic features. However, it is difficult to cluster codes into code blocks by general code analysis. To efficiently extract hierarchical AST representations, we apply a graph coarsening (pooling) module to AST for the first time, which can coarsen and cluster the original AST nodes into several node clusters based on node features and structures. After graph coarsening, these node clusters are considered code blocks, and the whole coarsened AST graph representation will represent higher-level program features. Our experimental results show that hierarchical AST representations yield an improvement of about 2% −3% and 12%-17% accuracy of cross-language program classification on Dataset JC and Dataset Leetcode, respectively, compared to the AST representations only based on low-level program features.

Read the paper · More papers on PaperTik