用多图注意力融合语法语义,提升代码克隆检测准确率
MAGNET: A Multi-Graph Attentional Network for Code Clone Detection
- 构建AST/CFG/DFG三图联合建模,通过自注意力捕捉代码长程依赖
- 在BigCloneBench和Google Code Jam上分别达96.5%和99.2%的F1分数
- 适合软件安全、代码审计及自动化重构场景使用
代码克隆检测是软件工程中的基础任务,支撑重构、调试、抄袭识别与漏洞分析。现有方法多依赖单一表示如抽象语法树(AST)、控制流图(CFG)和数据流图(DFG),仅捕获代码语义的部分信息。混合方法虽出现,但融合策略常为手工设计且效果有限。本文提出MAGNET,一种多图注意力框架,联合利用AST、CFG与DFG表示,以捕捉源码的语法与语义特征。MAGNET结合残差图神经网络与节点级自注意力,学习局部与长程依赖;引入门控交叉注意力机制实现细粒度跨图交互;采用Set2Set池化将多图嵌入融合为统一程序级表征。在BigCloneBench与Google Code Jam上的大量实验表明,MAGNET达到96.5%与99.2%的总体F1分数,优于当前最优水平。消融实验证明多图融合及各注意力组件的关键作用。代码已开源:https://github.com/ZixianReid/Multigraph_match
原文摘要 · Abstract (English)
Code clone detection is a fundamental task in software engineering that underpins refactoring, debugging, plagiarism detection, and vulnerability analysis. Existing methods often rely on singular representations such as abstract syntax trees (ASTs), control flow graphs (CFGs), and data flow graphs (DFGs), which capture only partial aspects of code semantics. Hybrid approaches have emerged, but their fusion strategies are typically handcrafted and ineffective. In this study, we propose MAGNET, a multi-graph attentional framework that jointly leverages AST, CFG, and DFG representations to capture syntactic and semantic features of source code. MAGNET integrates residual graph neural networks with node-level self-attention to learn both local and long-range dependencies, introduces a gated cross-attention mechanism for fine-grained inter-graph interactions, and employs Set2Set pooling to fuse multi-graph embeddings into unified program-level representations. Extensive experiments on BigCloneBench and Google Code Jam demonstrate that MAGNET achieves state-of-the-art performance with an overall F1 score of 96.5\% and 99.2\% on the two datasets, respectively. Ablation studies confirm the critical contributions of multi-graph fusion and each attentional component. Our code is available at https://github.com/ZixianReid/Multigraph_match
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。