Towards Context-Aware Code Comment Generation

Xiaohan Yu, Quzhe Huang, Zheng Wang, Yansong Feng, Dongyan Zhao


Abstract
Code 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.
Anthology ID:
2020.findings-emnlp.350
Volume:
Findings of the Association for Computational Linguistics: EMNLP 2020
Month:
November
Year:
2020
Address:
Online
Venue:
Findings
SIG:
Publisher:
Association for Computational Linguistics
Note:
Pages:
3938–3947
Language:
URL:
https://aclanthology.org/2020.findings-emnlp.350
DOI:
10.18653/v1/2020.findings-emnlp.350
Bibkey:
Cite (ACL):
Xiaohan Yu, Quzhe Huang, Zheng Wang, Yansong Feng, and Dongyan Zhao. 2020. Towards Context-Aware Code Comment Generation. In Findings of the Association for Computational Linguistics: EMNLP 2020, pages 3938–3947, Online. Association for Computational Linguistics.
Cite (Informal):
Towards Context-Aware Code Comment Generation (Yu et al., Findings 2020)
Copy Citation:
PDF:
https://preview.aclanthology.org/ingestion-script-update/2020.findings-emnlp.350.pdf
Optional supplementary material:
 2020.findings-emnlp.350.OptionalSupplementaryMaterial.zip