arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2311.10388cs.SE
收藏

基于大语言模型与上下文学习的智能合约注释自动生成

Automatic Smart Contract Comment Generation via Large Language Models and In-Context Learning

Junjie Zhao, Xiang Chen, Guang Yang, Yiheng Shen

AI总结:

本文提出SCCLLM方法,利用大语言模型和上下文学习,通过检索语法、语义和词法相似的top-k代码片段作为演示,自动生成智能合约代码注释,并在Etherscan.io语料库上验证了其优于基线方法的性能。

摘要:

以往的智能合约代码注释(SCC)生成方法可分为两类:基于微调范式的方法和基于信息检索的方法。然而,对于基于微调范式的方法,其性能可能受到为下游任务收集的数据集质量的限制,并且可能存在知识遗忘问题。而对于基于信息检索的方法,如果历史仓库中不存在相似代码,则难以生成高质量的注释。因此,我们希望利用大语言模型(LLMs)中与SCC生成相关的领域知识来缓解这两类方法的不足。在本研究中,我们提出了一种基于LLMs和上下文学习的方法SCCLLM。具体而言,在演示选择阶段,SCCLLM通过考虑语法、语义和词法信息,从历史语料库中检索top-k代码片段。在上下文学习阶段,SCCLLM利用检索到的代码片段作为演示,这有助于利用该任务的相关知识。我们选取来自智能合约社区Etherscan.io的大型语料库作为实验对象。大量实验结果表明,在自动评估和人工评估中,SCCLLM与基线方法相比具有有效性。

英文摘要:

The previous smart contract code comment (SCC) generation approaches can be divided into two categories: fine-tuning paradigm-based approaches and information retrieval-based approaches. However, for the fine-tuning paradigm-based approaches, the performance may be limited by the quality of the gathered dataset for the downstream task and they may have knowledge-forgetting issues. While for the information retrieval-based approaches, it is difficult for them to generate high-quality comments if similar code does not exist in the historical repository. Therefore we want to utilize the domain knowledge related to SCC generation in large language models (LLMs) to alleviate the disadvantages of these two types of approaches. In this study, we propose an approach SCCLLM based on LLMs and in-context learning. Specifically, in the demonstration selection phase, SCCLLM retrieves the top-k code snippets from the historical corpus by considering syntax, semantics, and lexical information. In the in-context learning phase, SCCLLM utilizes the retrieved code snippets as demonstrations, which can help to utilize the related knowledge for this task. We select a large corpus from a smart contract community Etherscan.io as our experimental subject. Extensive experimental results show the effectiveness of SCCLLM when compared with baselines in automatic evaluation and human evaluation.

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

↑