CC2Vec: Combining Typed Tokens with Contrastive Learning for Effective Code Clone Detection

Author:

Dou Shihan1ORCID,Wu Yueming2ORCID,Jia Haoxiang3ORCID,Zhou Yuhao1ORCID,Liu Yan1ORCID,Liu Yang2ORCID

Affiliation:

1. Fudan University, Shanghai, China

2. Nanyang Technological University, Singapore, Singapore

3. Huazhong University of Science and Technology, Wuhan, China

Abstract

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.

Publisher

Association for Computing Machinery (ACM)

Reference62 articles.

1. [n. d.]. RMSProp Optimizer. https://www.cs.toronto.edu/ tijmen/csc321/slides/lecture_slides_lec6.pdf

2. 2017. Google Code Jam. https://code.google.com/codejam/past-contests

3. 2020. BigCloneBench. https://github.com/clonebench/BigCloneBench

4. 2021. Open Source Technology Trends 2021 – What’s there for you? https://www.hiddenbrains.com/blog/open-source-technology-trends.html

5. 2021. What the 2021 OSSRA report tells us about the state of open source in commercial software. https://www.synopsys.com/blogs/software-security/open-source-trends-ossra-report/

同舟云学术

1.学者识别学者识别

2.学术分析学术分析

3.人才评估人才评估

"同舟云学术"是以全球学者为主线,采集、加工和组织学术论文而形成的新型学术文献查询和分析系统,可以对全球学者进行文献检索和人才价值评估。用户可以通过关注某些学科领域的顶尖人物而持续追踪该领域的学科进展和研究前沿。经过近期的数据扩容,当前同舟云学术共收录了国内外主流学术期刊6万余种,收集的期刊论文及会议论文总量共计约1.5亿篇,并以每天添加12000余篇中外论文的速度递增。我们也可以为用户提供个性化、定制化的学者数据。欢迎来电咨询!咨询电话:010-8811{复制后删除}0370

www.globalauthorid.com

TOP

Copyright © 2019-2024 北京同舟云网络信息技术有限公司
京公网安备11010802033243号  京ICP备18003416号-3