[论文解读] Detecting Code Clones with Graph Neural Networkand Flow-Augmented Abstract Syntax Tree
本文提出 FA-AST,即流量增强的 AST 图表示,并将 GGNN 和 GMN 图神经网络应用于检测语义代码克隆,在 GCJ 和 BigCloneBench 数据集上达到最先进的结果。
Code clones are semantically similar code fragments pairs that are syntactically similar or different. Detection of code clones can help to reduce the cost of software maintenance and prevent bugs. Numerous approaches of detecting code clones have been proposed previously, but most of them focus on detecting syntactic clones and do not work well on semantic clones with different syntactic features. To detect semantic clones, researchers have tried to adopt deep learning for code clone detection to automatically learn latent semantic features from data. Especially, to leverage grammar information, several approaches used abstract syntax trees (AST) as input and achieved significant progress on code clone benchmarks in various programming languages. However, these AST-based approaches still can not fully leverage the structural information of code fragments, especially semantic information such as control flow and data flow. To leverage control and data flow information, in this paper, we build a graph representation of programs called flow-augmented abstract syntax tree (FA-AST). We construct FA-AST by augmenting original ASTs with explicit control and data flow edges. Then we apply two different types of graph neural networks (GNN) on FA-AST to measure the similarity of code pairs. As far as we have concerned, we are the first to apply graph neural networks on the domain of code clone detection. We apply our FA-AST and graph neural networks on two Java datasets: Google Code Jam and BigCloneBench. Our approach outperforms the state-of-the-art approaches on both Google Code Jam and BigCloneBench tasks.
研究动机与目标
- 激发检测语义(类型-4)代码克隆超越语法相似性的挑战。
- 提出一种图表示(FA-AST),编码语法、控制流和数据流。
- 开发并比较两种 GNN 模型(GGNN 和 GMN)用于代码克隆检测。
- 在两个 Java 数据集(Google Code Jam 和 BigCloneBench)上评估,并展示相对于基于 AST 的基线的性能改进。
提出的方法
- 通过用控制流边(If、While、For)和数据流线索(NextUse、NextToken)来增强 AST 来构造 FA-AST。
- 将程序表示为图并应用 GGNN,通过基于 MLP 的消息传递和基于 GRU 的更新来学习图嵌入。
- 应用 GMN 对代码对进行联合嵌入学习,使用跨图注意机制,读取与 GGNN 类似的向量以获得图级向量。
- 在相似性预测上使用均方误差损失进行训练,并使用图嵌入的余弦相似度来做克隆判定。
- 在 GCJ 和 BigCloneBench 上对照基线(DECKARD、RtvNN、CDLH、ASTNN),在验证数据上调节阈值。
实验结果
研究问题
- RQ1FA-AST 是否能够有效编码代码片段的语法结构和语义流信息?
- RQ2图神经网络(GGNN 和 GMN)是否在代码克隆检测中优于基于 AST 的深度学习方法?
- RQ3GMN 中的跨图注意是否有益于检测跨代码对的语义克隆?
- RQ4所提方法在不同数据集(GCJ 和 BigCloneBench)上的类型-4/语义克隆表现如何?
主要发现
- FA-AST+GMN 在 Google Code Jam 上达到精确度0.99、召回率0.97、F1 0.98,优于 ASTNN 及其他基线。
- FA-AST+GGNN 在 Google Code Jam 上达到精确度0.96、召回率1.0、F1 0.97,优于多数基线但略低于 GMN。
- 在 BigCloneBench 上,FA-AST+GMN 的精确度0.96、召回率0.94、F1 0.95,超过 ASTNN 和其他基线。
- GMN 模型总体上优于 GGNN,表明跨图注意提高了克隆检测性能。
- FA-AST+GMN 在语义(WT3/T4)克隆方面表现强劲,优于 ASTNN 的这些更难案例。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。