Skip to main content
QUICK REVIEW

[Paper Review] Abstract Syntax Tree for Programming Language Understanding and Representation: How Far Are We?

Weisong Sun, Chunrong Fang|arXiv (Cornell University)|Dec 1, 2023
Software Engineering ResearchComputer Science6 citations
TL;DR

This paper conducts a comprehensive empirical study comparing AST-based and token-based code representation learning across code clone detection, code search, and code summarization tasks. Surprisingly, models using AST-based representations consistently underperform those using token-based representations, though ASTs show superior performance on specific subsets of samples—highlighting the need for context-aware, stage-specific method selection in AST-based code representation.

ABSTRACT

Programming language understanding and representation (a.k.a code representation learning) has always been a hot and challenging task in software engineering. It aims to apply deep learning techniques to produce numerical representations of the source code features while preserving its semantics. These representations can be used for facilitating subsequent code-related tasks. The abstract syntax tree (AST), a fundamental code feature, illustrates the syntactic information of the source code and has been widely used in code representation learning. However, there is still a lack of systematic and quantitative evaluation of how well AST-based code representation facilitates subsequent code-related tasks. In this paper, we first conduct a comprehensive empirical study to explore the effectiveness of the AST-based code representation in facilitating follow-up code-related tasks. To do so, we compare the performance of models trained with code token sequence (Token for short) based code representation and AST-based code representation on three popular types of code-related tasks. Surprisingly, the overall quantitative statistical results demonstrate that models trained with AST-based code representation consistently perform worse across all three tasks compared to models trained with Token-based code representation. Our further quantitative analysis reveals that models trained with AST-based code representation outperform models trained with Token-based code representation in certain subsets of samples across all three tasks. We also conduct comprehensive experiments to evaluate and reveal the impact of the choice of AST parsing/preprocessing/encoding methods on AST-based code representation and subsequent code-related tasks. Our study provides future researchers with detailed guidance on how to select solutions at each stage to fully exploit AST.

Motivation & Objective

  • To quantitatively evaluate the effectiveness of AST-based code representation in facilitating downstream code-related tasks.
  • To identify why AST-based representations may underperform compared to token-based representations despite their theoretical advantages.
  • To investigate the impact of different AST parsing, preprocessing, and encoding methods on model performance across diverse code tasks.
  • To provide actionable, stage-specific guidance for researchers selecting AST-based representation techniques based on task context.

Proposed method

  • The study compares models trained on AST-based and token-based code representations across three code-related tasks: code clone detection, code search, and code summarization.
  • It evaluates four AST parsing methods, six AST preprocessing techniques, and four AST encoding methods commonly used in existing research.
  • Statistical analysis is performed to compare model performance, with subgroup analysis identifying cases where AST-based models outperform token-based models.
  • The AST parsing stage converts source code into abstract syntax trees using various tools and configurations.
  • The preprocessing stage applies techniques such as node normalization, subtree pruning, and structure simplification to prepare ASTs for encoding.
  • The encoding stage employs deep learning models including Transformers, GNNs, and tree-structured attention mechanisms to generate code embeddings from ASTs.

Experimental results

Research questions

  • RQ1How does AST-based code representation compare to token-based representation in terms of performance across code clone detection, code search, and code summarization tasks?
  • RQ2In which specific subsets of code samples does AST-based representation outperform token-based representation?
  • RQ3How do different choices in AST parsing, preprocessing, and encoding stages affect the final performance of code representation models?
  • RQ4What are the task-specific impacts of various AST representation pipeline components on downstream code intelligence tasks?

Key findings

  • Models trained with AST-based code representation consistently underperform models trained with token-based representation across all three tasks: code clone detection, code search, and code summarization.
  • Despite overall underperformance, AST-based models outperform token-based models in specific subsets of samples—up to 39% of samples in code summarization and 28% in code search.
  • The performance of AST-based representations is highly sensitive to the choice of parsing, preprocessing, and encoding methods, with varying impacts depending on the downstream task.
  • Subsets where ASTs outperform tokens often involve code with low textual similarity, such as clone pairs with structural similarity but lexical dissimilarity.
  • The study reveals that no single AST representation pipeline configuration universally outperforms others, underscoring the need for task-specific optimization.
  • The results suggest that current AST-based code representation learning lacks systematic guidance, and future work should focus on context-aware, pipeline-stage-aware design.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.