使用基于BERT的最近邻方法进行可扩展克隆检测
Using a Nearest-Neighbour, BERT-Based Approach for Scalable Clone Detection
AI总结:
本文提出SSCD,一种基于BERT嵌入和最近邻搜索的克隆检测方法,避免两两比较瓶颈,在3.2亿行BigCloneBench上三小时内高效检测Type 3和Type 4克隆,优于SAGA和SourcererCC。
摘要:
代码克隆会对软件维护产生不利影响,而在非常大的代码库中手动检测它们是不切实际的。此外,自动化方法在检测Type 3和Type 4(不精确)克隆时面临很大挑战。虽然最新的人工深度神经网络(例如基于BERT的人工神经网络)在检测此类克隆方面似乎非常有效,但它们对目标系统中的每一对代码进行两两比较,效率低下,并且在大型代码库上扩展性差。因此,我们引入了SSCD,一种基于BERT的克隆检测方法,旨在实现大规模下对Type 3和Type 4克隆的高召回率(符合我们工业合作伙伴的要求)。该方法通过为每个代码片段计算一个代表性的嵌入向量,并使用最近邻搜索来查找相似片段。SSCD因此避免了其他神经网络方法的两两比较瓶颈,同时利用并行、GPU加速的搜索来解决可扩展性问题。本文详细介绍了该方法以及在工业环境中配置和评估该方法的实证评估。配置分析表明,较短的输入长度和仅基于文本的神经网络模型在SSCD中表现出更好的效率,同时仅略微降低有效性。评估结果表明,SSCD比SAGA和SourcererCC等最先进的方法更有效。它也非常高效:在其最优设置下,SSCD能在不到三小时内有效地在包含3.2亿行代码的BigCloneBench(一个标准的克隆检测基准)中定位克隆。
英文摘要:
Code clones can detrimentally impact software maintenance and manually detecting them in very large codebases is impractical. Additionally, automated approaches find detection of Type 3 and Type 4 (inexact) clones very challenging. While the most recent artificial deep neural networks (for example BERT-based artificial neural networks) seem to be highly effective in detecting such clones, their pairwise comparison of every code pair in the target system(s) is inefficient and scales poorly on large codebases. We therefore introduce SSCD, a BERT-based clone detection approach that targets high recall of Type 3 and Type 4 clones at scale (in line with our industrial partner's requirements). It does so by computing a representative embedding for each code fragment and finding similar fragments using a nearest neighbour search. SSCD thus avoids the pairwise-comparison bottleneck of other Neural Network approaches while also using parallel, GPU-accelerated search to tackle scalability. This paper details the approach and an empirical assessment towards configuring and evaluating that approach in industrial setting. The configuration analysis suggests that shorter input lengths and text-only based neural network models demonstrate better efficiency in SSCD, while only slightly decreasing effectiveness. The evaluation results suggest that SSCD is more effective than state-of-the-art approaches like SAGA and SourcererCC. It is also highly efficient: in its optimal setting, SSCD effectively locates clones in the entire 320 million LOC BigCloneBench (a standard clone detection benchmark) in just under three hours.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。