Skip to main content
QUICK REVIEW

[論文レビュー] Detecting Code Clones with Graph Neural Networkand Flow-Augmented Abstract Syntax Tree

Wenhan Wang, Ge Li|arXiv (Cornell University)|Feb 20, 2020
Software Engineering Research参考文献 23被引用数 32
ひとこと要約

この論文は FA-AST を提案し、流れを拡張した AST グラフ表現を用いて、GGNN と GMN のグラフニューラルネットワークを適用し、セマンティックコードクローンを検出して GCJ と BigCloneBench データセットで最先端の結果を達成します。

ABSTRACT

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)を提案する。
  • コードクローン検出のための2つの GNN モデル(GGNN と GMN)を開発・比較する。
  • 2つの Java データセット(Google Code Jam と BigCloneBench)で評価し、AST ベースのベースラインより性能向上を示す。

提案手法

  • AST に制御フローエッジ(If、While、For)とデータフローの手掛かり(NextUse、NextToken)を付加して FA-AST を構築する。
  • プログラムをグラフとして表現し、GGNN を適用して MLP ベースのメッセージと GRU ベースの更新でグラフ埋め込みを学習する。
  • GMN を適用して、クロスグラフアテンション機構を用いてコード対の埋め込みを共同で学習し、GGNN に類似したリードアウトでグラフレベルのベクトルを得る。
  • 同一性予測の MSE 損失で訓練し、グラフ埋め込みのコサイン類似度をクローン判定に用いる。
  • 検証データで閾値を調整し、GCJ と BigCloneBench でデ baselines と比較する(DECKARD、RtvNN、CDLH、ASTNN)。

実験結果

リサーチクエスチョン

  • RQ1FA-AST はコード断片の構文的構造と意味的フロー情報の両方を効果的にエンコードできるか。
  • RQ2グラフニューラルネットワーク(GGNN と GMN)はコードクローン検出において AST ベースの深層学習手法より優れているか。
  • RQ3GMN のクロスグラフアテンションは、コードペア間の意味的クローン検出に有益か。
  • RQ4提案手法は異なるデータセット(GCJ と BigCloneBench)におけるタイプ4/意味的クローンでどのように性能を示すか。

主な発見

データセットモデル精度再現率F1
GCJDECKARD0.450.440.44
GCJRtvNN0.200.900.33
GCJASTNN0.980.930.95
GCJFA-AST+GGNN0.961.000.97
GCJFA-AST+GMN0.990.970.98
BigCloneBenchDeckard0.930.020.03
BigCloneBenchRtvNN0.950.010.01
BigCloneBenchCDLH0.920.740.82
BigCloneBenchASTNN0.920.940.93
BigCloneBenchFA-AST+GGNN0.850.900.88
BigCloneBenchFA-AST+GMN0.960.940.95
  • FA-AST+GMN は Google Code Jam で precision0.99、recall0.97、F10.98 を達成し、ASTNN や他のベースラインを上回る。
  • FA-AST+GGNN は Google Code Jam で precision0.96、recall1.0、F10.97 を達成し、ほとんどのベースラインを上回るが GMN に比べやや下回る。
  • BigCloneBench では FA-AST+GMN が precision0.96、recall0.94、F10.95 を達成し、ASTNN や他のベースラインを上回る。
  • GMN モデルは一般に GGNN モデルよりも上回る傾向があり、クロスグラフアテンションがクローン検出性能を向上させることを示唆する。
  • FA-AST+GMN は意味的(WT3/T4)クローンにおいて強力な性能を示し、これらの難しいケースで ASTNN を上回る。

より良い研究を、今すぐ始めましょう

論文設計から論文執筆まで、研究時間を劇的に削減しましょう。

クレジットカード登録不要

このレビューはAIが作成し、人間の編集者が確認しました。