Towards Context-Aware Code Comment Generation
32133Authors
nan
Abstract
AbstractCode comments are vital for software maintenance and comprehension, but many software projects suffer from the lack of meaningful and up-to-date comments in practice. This paper presents a novel approach to automatically generate code comments at a function level by targeting object-oriented programming languages. Unlike prior work that only uses information locally available within the target function, our approach leverages broader contextual information by considering all other functions of the same class. To propagate and integrate information beyond the scope of the target function, we design a novel learning framework based on the bidirectional gated recurrent unit and a graph attention network with a pointer mechanism. We apply our approach to produce code comments for Java methods and compare it against four strong baseline methods. Experimental results show that our approach outperforms most methods by a large margin and achieves a comparable result with the state-of-the-art method.
Keywords
Full Content
Findings of the Association for Computational Linguistics: EMNLP 2020, pages 3938–3947 November 16 - 20, 2020. c⃝2020 Association for Computational Linguistics 3938 Towards Context-Aware Code Comment Generation Xiaohan Yu, Quzhe Huang, Zheng Wang, Yansong Feng, Dongyan Zhao Wangxuan Institute of Computer Technology, Peking University, China School of Computing, University of Leeds, United Kingdom The MOE Key Laboratory of Computational Linguistics, Peking University, China {yuxiaohan,huangquzhe,fengyansong,zhaodongyan}@pku.edu.cn z.wang5@leeds.ac.uk Abstract Code comments are vital for software mainte- nance and comprehension, but many software projects suffer from the lack of meaningful and up-to-date comments in practice. This pa- per presents a novel approach to automatically generate code comments at a function level by targeting object-oriented programming lan- guages. Unlike prior work that only uses infor- mation locally available within the target func- tion, our approach leverages broader contex- tual information by considering all other func- tions of the same class. To propagate and inte- grate information beyond the scope of the tar- get function, we design a novel learning frame- work based on the bidirectional gated recur- rent unit and a graph attention network with a pointer mechanism. We apply our approach to produce code comments for Java methods and compare it against four strong baseline meth- ods. Experimental results show that our ap- proach outperforms most methods by a large margin and achieves a comparable result with the state-of-the-art method. 1 Introduction High-quality code comments are important for soft- ware maintenance. Yet, few software projects ade- quately document the code (Kajko-Mattsson, 2005). One way to overcome the lack of human-written comments, and guard against mismatch and obso- lete comments is to automatically generate them. Classical approaches for auto-comment genera- tion use hand-crafted templates to produce code de- scriptions (Sridhara et al., 2010; Cortes-Coy et al., 2014; Dawood et al., 2017), but suffer from poor scalability and high maintenance cost due to the expensive overhead of writing comment templates. More recent work takes a learning-based approach by employing neural network (NN) models devel- oped for natural language processing tasks like machine translation to automatically generate com- ments (Sutskever et al., 2014; Luong et al., 2015). Compared to hand-written templates, a learning- based approach based on empirical data is more scalable and sustainable. The key to generating high-quality comments is to utilize as much relevant information as pos- sible from the source code to infer the high-level algorithmic intents. Prior work achieves this by converting a representation of the program, e.g., an Abstract Syntax Tree (AST), into a sequential sequence where a sequential model like LSTM can be applied to translate the token sequence into nat- ural language descriptions (Hu et al., 2018a; Alon et al., 2019; LeClair et al., 2019). Some more re- cent work has employed the Graph Convolution Network (GCN) to directly operate on a graph rep- resentation, e.g., an adjacency matrix, of the AST (LeClair et al., 2020). While promising, all existing learning-based approaches only capture informa- tion from the target function (or method) to be commented but fail to capitalize on …
Content truncated to 500 words
Labeled Text
AbstractCode comments are vital for software maintenance and comprehension, but many software projects suffer from the lack of meaningful and up-to-date comments in practice. This paper presents a novel approach to automatically generate code comments at a function level by targeting object-oriented programming languages. Unlike prior work that only uses information locally available within the target function, our approach leverages broader contextual information by considering all other functions of the same class. To propagate and integrate information beyond the scope of the target function, we design a novel learning framework based on the bidirectional gated recurrent unit and a graph attention network with a pointer mechanism. We apply our approach to produce code comments for Java methods and compare it against four strong baseline methods. Experimental results show that our approach outperforms most methods by a large margin and achieves a comparable result with the state-of-the-art method.
Publication Details
- Paper ID:
- 32133
- Year:
- 2020
- Publication:
- TIPSTER
- Publication Type:
- conf
- DOI:
- nan