Type-IV Code Clone Detection via Layer-Wise Non-Contrastive Representation Learning

📄 arXiv: 2609.17338v1 📥 PDF

作者: Luciano Marchezan, Kevin Delcourt, Eugene Syriani, Houari Sahraoui

分类: cs.SE, cs.LG

发布日期: 2026-09-15


💡 一句话要点

提出LWVIC4Code以解决Type-IV代码克隆检测问题

🎯 匹配领域: 支柱二:RL算法与架构 (RL & Architecture) 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 代码克隆 非对比学习 语义分析 深度学习 软件维护 机器学习

📋 核心要点

  1. 现有的Type-IV克隆检测方法主要依赖对比学习,面临负样本选择困难和潜在偏差的问题。
  2. LWVIC4Code通过非对比表示学习,结合层级监督和跨层一致性正则化,提升了语义信息的提取能力。
  3. 实验结果显示,LWVIC4Code在多个数据集上表现优异,尤其在Python到其他语言的迁移学习中展现了强大的泛化能力。

📝 摘要(中文)

软件克隆是指相似或功能等价的代码片段,给维护、重构和错误检测带来挑战。Type-IV克隆的检测尤为困难,因为它们在语法上可能不同但语义上等价。传统的基于token或语法的方法难以有效识别。本文提出LWVIC4Code,一种专为Type-IV克隆检测设计的非对比表示学习方法。该方法基于方差-不变性-协方差正则化(VICReg)框架,引入跨层一致性正则化和深度依赖层加权,逐步提炼语义信息,生成稳健且具有区分性的代码表示。实验证明,LWVIC4Code在Python和多语言数据集上表现出色,且无需负样本,具有良好的泛化能力。

🔬 方法详解

问题定义:本文旨在解决Type-IV代码克隆检测中的语义等价性识别问题。现有方法多依赖对比学习,面临负样本选择的复杂性和潜在的偏差,导致检测效果不理想。

核心思路:LWVIC4Code采用非对比表示学习,利用方差-不变性-协方差正则化(VICReg)框架,通过跨层一致性正则化和深度依赖层加权,逐步提炼和增强代码的语义表示。

技术框架:该方法的整体架构包括数据预处理、层级特征提取、跨层正则化和最终的代码表示生成。每个阶段都旨在优化语义信息的提取和表示。

关键创新:LWVIC4Code的主要创新在于引入了非对比学习的策略,避免了负样本的使用,同时通过层级监督机制提升了模型的表现力和泛化能力。

关键设计:在模型设计中,采用了层级加权机制,以适应不同层次的语义信息,同时使用了特定的损失函数以确保跨层一致性,增强了模型的鲁棒性。该方法在多个编程语言上均表现出色。

🖼️ 关键图片

img_0
img_1
img_2

📊 实验亮点

实验结果表明,LWVIC4Code在Python和多语言数据集上均表现优异,相较于对比学习基线,性能提升显著,尤其在无需负样本的情况下,展现出更强的泛化能力,特别是在Java和C#等语言上也取得了良好效果。

🎯 应用场景

LWVIC4Code的研究成果在软件维护、重构和错误检测等领域具有广泛的应用潜力。通过提高Type-IV克隆的检测能力,可以有效降低软件开发中的技术债务,提升代码质量和可维护性。未来,该方法还可以扩展到其他编程语言和更复杂的代码分析任务中。

📄 摘要(原文)

Software clones are fragments of code that are similar or functionally equivalent to each other. They pose significant challenges for maintenance, refactoring, and bug detection. Detecting Type-IV clones, which are semantically equivalent but may differ syntactically, is particularly difficult for traditional token- or syntax-based methods. Recent machine learning approaches rely on contrastive learning, which requires careful negative sampling and can introduce bias. In this paper, we propose LWVIC4Code, a non-contrastive representation learning approach specifically designed for Type-IV clone detection. Building on the Variance-Invariance-Covariance Regularization (VICReg) framework and prior layer-wise VICReg training, LWVIC4Code introduces cross-layer consistency regularization and depth-dependent layer weighting to progressively refine semantic information across transformer layers, producing robust and discriminative code representations. We conduct an empirical study comparing LWVIC4Code against a contrastive learning baseline and zero-shot large language models on Python (Kamino) and multi-language (GPTCloneBench) datasets. Results show that LWVIC4Code achieves competitive or superior performance without negative samples, benefits from layer-wise supervision, and generalizes effectively from Python to other languages, particularly Java and C#. These results demonstrate that non-contrastive, layer-wise representation learning is a promising direction for robust semantic code clone detection.