CC2Vec:结合类型化Token与对比学习以实现有效的代码克隆检测
CC2Vec: Combining Typed Tokens with Contrastive Learning for Effective Code Clone Detection
AI总结:
本文提出CC2Vec代码编码方法,通过类型化Token和对比学习增强语义代码克隆检测能力,在保持简单克隆检测有效性的同时显著提升检测效率。
摘要:
随着开源社区的发展,代码经常在多个软件系统中被复制、传播和演化,这给软件系统带来了不确定性和风险(例如缺陷传播和版权侵权)。因此,进行代码克隆检测以发现相似代码对非常重要。已有许多方法被提出用于检测代码克隆,其中基于Token的工具能够扩展到大规模代码。然而,由于缺乏程序细节,它们无法处理更复杂的代码克隆,即语义代码克隆。在本文中,我们提出了CC2Vec,一种新颖的代码编码方法,旨在快速识别简单代码克隆,同时增强语义代码克隆检测能力。为了保留Token之间的程序细节,CC2Vec根据语法类型将它们划分为不同类别(即类型化Token),然后应用两个自注意力机制层对其进行编码。为了抵抗语义代码克隆中代码结构的变化,CC2Vec执行对比学习以减少不同代码实现引入的差异。我们在两个广泛使用的数据集(即BigCloneBench和Google Code Jam)上评估了CC2Vec,结果表明我们的方法能够有效检测简单代码克隆。此外,CC2Vec不仅通过简单的微调就能获得与广泛使用的语义代码克隆检测系统(如ASTNN、SCDetector和FCCA)相当的性能,而且在检测效率上显著超越了这些方法。
英文摘要:
With the development of the open source community, the code is often copied, spread, and evolved in multiple software systems, which brings uncertainty and risk to the software system (e.g., bug propagation and copyright infringement). Therefore, it is important to conduct code clone detection to discover similar code pairs. Many approaches have been proposed to detect code clones where token-based tools can scale to big code. However, due to the lack of program details, they cannot handle more complicated code clones, i.e., semantic code clones. In this paper, we introduce CC2Vec, a novel code encoding method designed to swiftly identify simple code clones while also enhancing the capability for semantic code clone detection. To retain the program details between tokens, CC2Vec divides them into different categories (i.e., typed tokens) according to the syntactic types and then applies two self-attention mechanism layers to encode them. To resist changes in the code structure of semantic code clones, CC2Vec performs contrastive learning to reduce the differences introduced by different code implementations. We evaluate CC2Vec on two widely used datasets (i.e., BigCloneBench and Google Code Jam) and the results report that our method can effectively detect simple code clones. In addition, CC2Vec not only attains comparable performance to widely used semantic code clone detection systems such as ASTNN, SCDetector, and FCCA by simply fine-tuning, but also significantly surpasses these methods in both detection efficiency.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。