A Multi-Modal Transformer-based Code Summarization Approach for Smart Contracts

Zhen Yang, Jacky Keung, Xiao Yu, Xiaodong Gu, Zhengyuan Wei, Xiaoxue Ma, Miao Zhang

Research output: Chapter in Book/Report/Conference proceedingConference contributionpeer-review

58 Citations (Scopus)

Abstract

Code comment has been an important part of computer programs, greatly facilitating the understanding and maintenance of source code. However, high-quality code comments are often unavailable in smart contracts, the increasingly popular programs that run on the blockchain. In this paper, we propose a Multi-Modal Transformer-based (MMTrans) code summarization approach for smart contracts. Specifically, the MMTrans learns the representation of source code from the two heterogeneous modalities of the Abstract Syntax Tree (AST), i.e., Structure-based Traversal (SBT) sequences and graphs. The SBT sequence provides the global semantic information of AST, while the graph convolution focuses on the local details. The MMTrans uses two encoders to extract both global and local semantic information from the two modalities respectively, and then uses a joint decoder to generate code comments. Both the encoders and the decoder employ the multi-head attention structure of the Transformer to enhance the ability to capture the long-range dependencies between code tokens. We build a dataset with over 300K <method, comment> pairs of smart contracts, and evaluate the MMTrans on it. The experimental results demonstrate that the MMTrans outperforms the state-of-The-Art baselines in terms of four evaluation metrics by a substantial margin, and can generate higher quality comments.

Original languageEnglish
Title of host publicationProceedings - 2021 IEEE/ACM 29th International Conference on Program Comprehension, ICPC 2021
Pages1-12
Number of pages12
ISBN (Electronic)9781665414036
DOIs
Publication statusPublished - May 2021
Externally publishedYes
Event29th IEEE/ACM International Conference on Program Comprehension, ICPC 2021 - Virtual, Online
Duration: 20 May 202121 May 2021

Publication series

NameIEEE International Conference on Program Comprehension
Volume2021-May

Conference

Conference29th IEEE/ACM International Conference on Program Comprehension, ICPC 2021
CityVirtual, Online
Period20/05/2121/05/21

Keywords

  • Code Summarization
  • Graph Convolution
  • Smart Contracts
  • Structure-based Traversal
  • Transformer

Fingerprint

Dive into the research topics of 'A Multi-Modal Transformer-based Code Summarization Approach for Smart Contracts'. Together they form a unique fingerprint.

Cite this