arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2103.07164cs.SE
收藏

一种基于多模态transformer的智能合约代码摘要方法

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

摘要:

代码注释已经成为计算机程序的重要组成部分,极大地方便了对源代码的理解和维护。然而,高质量的代码注释通常在智能合约中不可用,智能合约是在区块链上运行的越来越受欢迎的程序。在本文中,我们提出了一种用于智能合约的基于多模态转换器(MMTrans)的代码摘要方法。具体地,MMTrans从抽象树(AST)的两种异构模态学习源代码的表示,即,基于结构的Traffic(SBT)序列和图。SBT序列提供了AST的全局语义信息,而图卷积则关注局部细节。MMTrans使用两个编码器分别从两个模态中提取全局和局部语义信息,然后使用联合解码器生成代码注释。编码器和解码器都采用了Transformer的多头注意力结构,以增强捕获代码令牌之间的长程依赖关系的能力。我们构建了一个包含超过30万对<method,comment>智能合约的数据集,并在其上对MMTrans进行了评估。实验结果表明,MMTrans在四个评估指标方面都大幅优于最先进的基线,并且可以生成更高质量的评论。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑