CAST: Enhancing Code Summarization with Hierarchical Splitting and Reconstruction of Abstract Syntax Trees
31776Authors
nan
Abstract
AbstractCode summarization aims to generate concise natural language descriptions of source code, which can help improve program comprehension and maintenance. Recent studies show that syntactic and structural information extracted from abstract syntax trees (ASTs) is conducive to summary generation. However, existing approaches fail to fully capture the rich information in ASTs because of the large size/depth of ASTs. In this paper, we propose a novel model CAST that hierarchically splits and reconstructs ASTs. First, we hierarchically split a large AST into a set of subtrees and utilize a recursive neural network to encode the subtrees. Then, we aggregate the embeddings of subtrees by reconstructing the split ASTs to get the representation of the complete AST. Finally, AST representation, together with source code embedding obtained by a vanilla code token encoder, is used for code summarization. Extensive experiments, including the ablation study and the human evaluation, on benchmarks have demonstrated the power of CAST. To facilitate reproducibility, our code and data are available at https://github.com/DeepSoftwareAnalytics/CAST.
Keywords
Full Content
Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pages 4053–4062 November 7–11, 2021. c⃝2021 Association for Computational Linguistics 4053 CAST: Enhancing Code Summarization with Hierarchical Splitting and Reconstruction of Abstract Syntax Trees Ensheng Shia,† Yanlin Wangb,†,§ Lun Dub Hongyu Zhangc Shi Hanb Dongmei Zhangb Hongbin Suna,§ aXi’an Jiaotong University bMicrosoft Research cThe University of Newcastle s1530129650@stu.xjtu.edu.cn, hsun@mail.xjtu.edu.cn {yanlwang, lun.du, shihan, dongmeiz}@microsoft.com hongyu.zhang@newcastle.edu.au Abstract Code summarization aims to generate concise natural language descriptions of source code, which can help improve program comprehen- sion and maintenance. Recent studies show that syntactic and structural information ex- tracted from abstract syntax trees (ASTs) is conducive to summary generation. However, existing approaches fail to fully capture the rich information in ASTs because of the large size/depth of ASTs. In this paper, we pro- pose a novel model CAST that hierarchically splits and reconstructs ASTs. First, we hi- erarchically split a large AST into a set of subtrees and utilize a recursive neural net- work to encode the subtrees. Then, we ag- gregate the embeddings of subtrees by recon- structing the split ASTs to get the representa- tion of the complete AST. Finally, AST rep- resentation, together with source code embed- ding obtained by a vanilla code token en- coder, is used for code summarization. Ex- tensive experiments, including the ablation study and the human evaluation, on bench- marks have demonstrated the power of CAST. To facilitate reproducibility, our code and data are available at https://github.com/ DeepSoftwareAnalytics/CAST. 1 Introduction Code summaries are concise natural language de- scriptions of source code and they are important for program comprehension and software mainte- nance. However, it remains a labor-intensive and time-consuming task for developers to document code with good summaries manually. Over the years, many code summarization meth- ods have been proposed to automatically summa- rize program subroutines. Traditional approaches such as rule-based and information retrieval- based approaches regard source code as plain †The first two authors contribute equally. §Yanlin Wang and Hongbin Sun are the corresponding authors. text (Haiduc et al., 2010a,b) without considering the complex grammar rules and syntactic structures exhibited in source code. Recently, abstract syntax trees (ASTs), which carry the syntax and structure information of code, are widely used to enhance code summarization techniques. For example, Hu et al. (2018a) propose the structure-based traversal (SBT) method to flatten ASTs and use LSTM to encode the SBT sequences into vectors. Hu et al. (2019) and LeClair et al. (2019) extend this idea by separating the code and AST into two input chan- nels, demonstrating the effectiveness of leveraging AST information. Alon et al. (2019a,b) extract paths from an AST and represent a given code snip- pet as a set of sampled paths. Other works (Wan et al., 2018; Zhang et al., 2019; Mou et al., 2016) use tree-based models such as Tree-LSTM, Re- cursive Neural Network (RvNN), and Tree-based CNN to model ASTs and improve code summariza- tion. We have identified some limitations of the exist- ing AST-based approaches, which lead to …
Content truncated to 500 words
Labeled Text
AbstractCode summarization aims to generate concise natural language descriptions of source code, which can help improve program comprehension and maintenance. Recent studies show that syntactic and structural information extracted from abstract syntax trees (ASTs) is conducive to summary generation. However, existing approaches fail to fully capture the rich information in ASTs because of the large size/depth of ASTs. In this paper, we propose a novel model CAST that hierarchically splits and reconstructs ASTs. First, we hierarchically split a large AST into a set of subtrees and utilize a recursive neural network to encode the subtrees. Then, we aggregate the embeddings of subtrees by reconstructing the split ASTs to get the representation of the complete AST. Finally, AST representation, together with source code embedding obtained by a vanilla code token encoder, is used for code summarization. Extensive experiments, including the ablation study and the human evaluation, on benchmarks have demonstrated the power of CAST. To facilitate reproducibility, our code and data are available at
Publication Details
- Paper ID:
- 31776
- Year:
- 2021
- Publication:
- TIPSTER
- Publication Type:
- conf
- DOI:
- nan