Papers
Topics
Authors
Recent
Search
2000 character limit reached

TriFusion-LLM: Prior-Guided Multimodal Fusion with LLM Arbitration for Fine-grained Code Clone Detection

Published 16 Mar 2026 in cs.SE | (2603.15004v1)

Abstract: Code clone detection (CCD) supports software maintenance, refactoring, and security analysis. Although pre-trained models capture code semantics, most work reduces CCD to binary classification, overlooking the heterogeneity of clone types and the seven fine-grained categories in BigCloneBench. We present Full Model, a multimodal fusion framework that jointly integrates heuristic similarity priors from classical machine learning, structural signals from abstract syntax trees (ASTs), and deep semantic embeddings from CodeBERT into a single predictor. By fusing structural, statistical, and semantic representations, Full Model improves discrimination among fine-grained clone types while keeping inference cost practical. On the seven-class BigCloneBench benchmark, Full Model raises Macro-F1 from 0.695 to 0.875. Ablation studies show that using the primary model's probability distribution as a prior to guide selective arbitration by a LLM substantially outperforms blind reclassification; arbitrating only ~0.2% of high-uncertainty samples yields an additional 0.3 absolute Macro-F1 gain. Overall, Full Model achieves an effective performance-cost trade-off for fine-grained CCD and offers a practical solution for large-scale industrial deployment.

Summary

  • The paper introduces TriFusion-LLM, which combines heuristic lexical priors, AST statistics, and CodeBERT embeddings through FiLM modulation and structural attention for seven-class code clone detection.
  • The model raises Macro-F1 from 0.695 for CodeBERT to 0.875, with especially strong gains for MT3, ST3, and VST3 clones while achieving 0.996 F1 on Type-4 clones.
  • The paper shows that confidence-triggered DeepSeek arbitration guided by Top-3 model probabilities reaches 63.74% accuracy on difficult cases, versus 43.31% for blind LLM reclassification, while invoking the LLM on under 0.2% of samples.

Motivation and problem statement

Code clone detection (CCD) has progressed from token-based matching to pre-trained transformer encoders, yet most published work frames the task as binary classification, which obscures the fine-grained similarity gradients that practitioners actually need for refactoring and security analysis. The paper addresses the seven-class taxonomy of BigCloneBench (Non-clone, Type-1, Type-2, VST3, ST3, MT3, WT3/Type-4) (2603.15004). The authors identify two failure modes of existing approaches: neural fusion models exhibit "semantic drift" because high-level embeddings lack grounding in quantitative similarity thresholds, while lexical/ML methods such as Toma act as stable anchors at low-to-medium similarity but fail on Type-4 semantic clones. When literal statistical evidence conflicts with semantic intuition at decision margins, existing architectures offer no arbitration mechanism.

The proposed system, TriFusion-LLM ("Full Model"), combines three feature sources—ML-based heuristic priors, AST-derived structural statistics, and CodeBERT semantic embeddings—with a confidence-triggered LLM arbitrator (DeepSeek-V3.2) invoked only on low-confidence samples.

Architecture

The framework proceeds in four stages:

  • Heterogeneous feature extraction: CodeBERT's final-layer [CLS] vector provides semantics; a LightGBM-integrated 7-dimensional lexical prior captures token overlap and identifier similarity; a 6-dimensional identifier-agnostic AST vector encodes depth, node count differences, and related structural metrics.
  • Heuristic-guided modulation: FiLM layers use the prior vector to generate per-dimension affine parameters (γ,β)(\gamma, \beta) that recalibrate the CodeBERT embedding, suppressing clone-indicative dimensions when lexical overlap is low.
  • Structural cross-attention: the modulated semantic vector serves as Query against AST statistics as Key/Value, followed by residual connection and LayerNorm.
  • Confidence-aware arbitration: when max(P)<τ\max(P) < \tau on the 7-way Softmax output, DeepSeek receives the raw code pair plus the Top-3 candidate labels with probabilities and returns a strict JSON classification.

Dataset construction

A notable methodological contribution is the preprocessing protocol over 4,781 Java projects: SHA-256 deduplication, filtering of snippets under 200 characters, and strict project-level isolation (70/10/20 train/validation/test splits) to prevent coding-style leakage. Training applies class caps (40,000 Non-clone; 25,000 WT3/T4) with exhaustive collection of rare classes; Type-4 diversity is maximized via length/complexity binning and greedy Jaccard-based selection. The test set preserves the real-world distribution entirely—934,677 samples dominated by 881,258 WT3/T4 pairs—which makes Macro-F1 particularly sensitive to minority-class behavior.

Main results (RQ1)

Against a CodeBERT baseline, the Full Model raises seven-class Macro-F1 from 0.695 ± 0.023 to 0.875 ± 0.008 (95% CI [0.865, 0.885], p<0.01p<0.01), an absolute gain of 0.180. The largest per-class improvements occur where the baseline is weakest: MT3 F1 rises from 0.201 to 0.627 (+0.426 relative), ST3 from 0.550 to 0.853, and VST3 from 0.533 to 0.819. Type-4 reaches F1 0.996 with precision 1.000 and recall 99.2%. The variance reduction is itself a substantive finding—the confidence interval width shrinks from 0.057 to 0.020—indicating that fusion acts as a decision-calibration mechanism rather than merely raising peak performance.

The ablation study attributes gains asymmetrically across the clone spectrum:

Variant Macro-F1 Δ
Full Model 0.875
Naive concatenation 0.861 −0.014
w/o AST branch 0.853 −0.022
ML-only (LightGBM) 0.834 −0.041
w/o ML-heuristics 0.807 −0.068
AST-only 0.291 −0.584
CodeBERT baseline 0.695 −0.180

Three conclusions follow directly. First, heuristic priors are the single most important component: removing them costs 0.068 Macro-F1, with MT3 F1 dropping by 0.231 and VST3 by 0.102. Second, AST features alone are nearly useless (F1 0.291) but contribute +0.132 F1 specifically on MT3 when fused, confirming their role as topological stabilizers rather than standalone detectors. Third, naive concatenation underperforms FiLM-modulated fusion by 0.014, which the authors attribute to "signal drowning" in high-dimensional spaces without an explicit interaction mechanism. Notably, the ML-only variant alone achieves 0.834—a strong result that implicitly questions how much of the full model's advantage derives from deep semantics versus classical statistics, though the full model still exceeds it by 0.041.

Adaptive arbitration (RQ2)

Validation-set analysis partitions classes into a stable cluster (Labels 0, 1, 6; mean confidence >90%, 57.7% of data) and an uncertain cluster (Labels 2–5, mean confidence near 70–87%). Global weighted Top-3 coverage of 99.94% motivates pruning the hypothesis space before LLM reasoning. A confidence-bin analysis identifies 0.6 as the inflection threshold: below it (only ~0.16% of the test set), the primary model's weighted Macro-F1 collapses to 0.311.

On this low-confidence subset, the guided-arbitration design proves decisively superior:

Strategy Accuracy Weighted/Macro-F1
Standalone primary model 7.45% poor (Label 5 precision 0.055)
Blind DeepSeek re-classification 43.31% Macro-F1 0.149 (majority-class bias)
Guided DeepSeek (Top-3 priors) 63.74% Weighted-F1 0.734 (~3× blind)

This comparison supports one of the paper's clearest claims: providing the primary model's probability distribution as context is essential; blind LLM reclassification amplifies majority-class bias and degrades minority categories. At industrial scale, arbitrating only low-confidence Label 5 instances yields +0.0034 global Macro-F1 while broad-spectrum replacement of all low-confidence predictions decreases Macro-Precision (−0.0051)—an instructive negative result showing that indiscriminate arbitration harms overall fidelity. Total LLM invocation covers fewer than 0.2% of instances, making the cost profile practical.

Limitations and open questions

The authors are explicit about several constraints. External validity is limited by BigCloneBench's Java-centricity and the absence of cross-language fine-grained benchmarks. Construct validity suffers from inherently ambiguous Type-3/Type-4 boundaries in the benchmark itself. Internally, the selective arbitration produces modest absolute gains (+0.0034 Macro-F1 globally); the mechanism's value rests primarily on targeted rectification of bottleneck categories rather than uniform improvement. Additional observations worth noting: the guided-arbitration accuracy of 63.74% on the hardest subset remains far from saturated, and the trigger threshold τ = 0.6 was derived from validation statistics whose transferability to other distributions or languages is untested. Whether the same prior-guidance benefit holds for LLMs other than DeepSeek-V3.2, and whether the FiLM modulation generalizes beyond Java, remain unresolved.

Conclusion

TriFusion-LLM demonstrates that fine-grained seven-class CCD benefits from explicitly fusing deterministic lexical priors, structural statistics, and semantic embeddings through learned modulation rather than naive concatenation, achieving 0.875 Macro-F1 on BigCloneBench with substantially reduced seed-to-seed variance. Its second contribution—an uncertainty-triggered LLM arbitrator conditioned on the primary model's probability distribution—establishes that informed arbitration dominates blind reclassification at negligible computational cost. The framework's dependence on Java-only benchmarks and its modest global arbitration gains define the boundaries within which these results should be interpreted.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.

Tweets

Sign up for free to view the 1 tweet with 0 likes about this paper.