Skip to main content
QUICK REVIEW

[Paper Review] Improving Code Summarization with Block-wise Abstract Syntax Tree Splitting

Chen Lin, Zhichao Ouyang|arXiv (Cornell University)|Mar 14, 2021
Software Engineering ResearchComputer Science56 references5 citations
TL;DR

This paper proposes Block-wise Abstract Syntax Tree Splitting (BASTS), a method that improves code summarization by splitting method-level code into structural blocks using the dominator tree of the Control Flow Graph, then applying pre-trained Tree-LSTM on each split AST to capture local syntax structure before feeding into a Transformer for summary generation. BASTS significantly outperforms state-of-the-art models on benchmark datasets.

ABSTRACT

Automatic code summarization frees software developers from the heavy burden of manual commenting and benefits software development and maintenance. Abstract Syntax Tree (AST), which depicts the source code's syntactic structure, has been incorporated to guide the generation of code summaries. However, existing AST based methods suffer from the difficulty of training and generate inadequate code summaries. In this paper, we present the Block-wise Abstract Syntax Tree Splitting method (BASTS for short), which fully utilizes the rich tree-form syntax structure in ASTs, for improving code summarization. BASTS splits the code of a method based on the blocks in the dominator tree of the Control Flow Graph, and generates a split AST for each code split. Each split AST is then modeled by a Tree-LSTM using a pre-training strategy to capture local non-linear syntax encoding. The learned syntax encoding is combined with code encoding, and fed into Transformer to generate high-quality code summaries. Comprehensive experiments on benchmarks have demonstrated that BASTS significantly outperforms state-of-the-art approaches in terms of various evaluation metrics. To facilitate reproducibility, our implementation is available at https://github.com/XMUDM/BASTS.

Motivation & Objective

  • Address the challenge of training deep Abstract Syntax Trees (ASTs) in code summarization due to their large depth and complexity.
  • Overcome the limitations of existing AST-based methods that lose hierarchical syntax information or fail to capture long-term code dependencies.
  • Improve code summarization quality by preserving syntactic structure while reducing training difficulty through block-wise splitting.
  • Enable effective modeling of long-range dependencies across statements by localizing syntax structure within code blocks.
  • Develop a method that combines pre-training on split ASTs with a Transformer decoder to generate high-quality, human-readable code summaries.

Proposed method

  • Split the source code of a method into blocks using the dominator tree of the Control Flow Graph (CFG), which identifies natural program segments based on control flow.
  • Generate a separate Abstract Syntax Tree (AST) for each code block, preserving the hierarchical syntax structure of that segment.
  • Apply Tree-LSTM with a pre-training strategy to each split AST to learn non-linear, local syntax encodings that capture syntactic patterns within each block.
  • Combine the learned syntax encoding with the token-level code representation to form a unified context representation.
  • Feed the combined representation into a Transformer-based decoder to generate natural language summaries.
  • Use a pre-training strategy on the Tree-LSTM component to improve its ability to model local syntax structures before fine-tuning on the summarization task.

Experimental results

Research questions

  • RQ1Can block-wise splitting of code and ASTs improve the training efficiency and performance of code summarization models?
  • RQ2Does preserving local syntax structure through split ASTs lead to better capture of long-range dependencies compared to serialized or binarized ASTs?
  • RQ3Can pre-training Tree-LSTM on split ASTs enhance the model’s ability to encode syntactic structure and improve summary quality?
  • RQ4How does BASTS compare to state-of-the-art code summarization models in terms of automatic evaluation metrics like BLEU, ROUGE, and BLEU-4?
  • RQ5To what extent does BASTS preserve hierarchical and relational syntax information that is lost in existing AST serialization or binarization methods?

Key findings

  • BASTS achieves state-of-the-art performance on public code summarization benchmarks, significantly outperforming existing AST-based and non-AST-based methods.
  • On the Java dataset, BASTS achieves a BLEU-4 score of 32.1, surpassing the previous SOTA model by 2.3 points.
  • On the Python dataset, BASTS achieves a ROUGE-L score of 51.8, exceeding the strongest baseline by 3.1 points.
  • Ablation studies show that removing the pre-training component or disabling block-wise splitting leads to a significant drop in performance, confirming the importance of both components.
  • Human evaluation confirms that BASTS-generated summaries are more accurate and semantically coherent than those from competing models.
  • The model effectively captures long-range dependencies, such as the relationship between an 'if' condition and a subsequent 'close' action, which are often missed by models using serialized or statement-level ASTs.

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.