Deciding whether two programs compute the same thing is hard in two opposite ways. Some pairs look almost identical but differ in one operator, and a flipped < changes what the program does. Other pairs share almost no tokens but solve the same problem, one with a loop and one with recursion. Models that read code as text are fooled by the first kind. Models that read code as a dependency graph, where statements are nodes and edges record which statement feeds or controls which, are fooled by the second, because the two graphs really do differ. Current multi-representation code models decide how much to trust each representation based on a single program, or on an external search query. We argue that the right amount of trust is a property of the pair. When two programs' token streams are nearly identical, their data-flow structure should decide the verdict. When their structures disagree but their library calls and token semantics agree, structure should be discounted.
We propose a Siamese clone detector, meaning two identical encoders with shared weights whose outputs are compared by a distance. It keeps a separate similarity per representation (token sequence, attention-weighted program dependency graph, and library-call "action" bag) and combines them with a small gate. The gate sees only symmetric statistics of the pair: how much the representations agree with each other, how much surface overlap there is, and how confident the graph attention was on each side. The central, falsifiable prediction is that the learned mixture reverses between near-duplicate hard negatives and implementation-divergent positives. It also predicts that this reversal yields gains on the benchmarks where the field is not yet saturated, specifically Google Code Jam and POJ-104, rather than on BigCloneBench.
Core Claim and How It Differs From Prior Work
Two systems frame the claim. HOLMES trains a weight-shared graph network with graph attention over program dependency graphs. Graph attention, or GAT, lets each statement weight its neighbors by content rather than by node degree, following Graph Attention Networks. HOLMES reports F1 0.98 on BigCloneBench but only 0.92 on Google Code Jam. The file attributes that drop to implementation divergence, which HypeCodeNet also names as its main failure mode, even though it moves syntax-tree embeddings into hyperbolic space. Both motivate our proposal: they show that a single structural view hits a ceiling on divergent solutions. MMAN supplies the method we build on. It attends over token, syntax-tree, and control-flow encoders, but its weights are conditioned on a natural-language query in an asymmetric retrieval model, and its graph encoder uses fixed propagation. CODE-MVP aligns five views contrastively but fuses them statically at inference.
Our proposal differs from all of these in one specific respect. The fusion weights are a symmetric function of the two programs jointly, so the similarity satisfies $S(A,B)=S(B,A)$ by construction. The weights are also driven by disagreement between representations, which no per-instance gate can observe.
DISCO plays a different role. It builds triplets whose positives are semantics-preserving rewrites and whose hard negatives are near-identical code with an injected bug, and it shows that text encoders confuse the two. We reuse its transformation recipe to build the stress slices on which the reversal must appear. Oreo supplies our third representation: its "action tokens" (library calls and field accesses) are cheap, work on uncompilable fragments, and tend to survive loop-to-recursion rewrites.
Mechanism
Each program $A$ is encoded by a shared token encoder, a shared GAT over its dependency graph, and a shared bag-of-actions encoder. This yields per-modality embeddings $e_m(A)$ for $m \in \{\text{tok}, \text{pdg}, \text{act}\}$ and per-modality similarities $s_m(A,B)=\cos(e_m(A), e_m(B))$. The final score is
$$S(A,B)=\sum_m w_m(A,B)\, s_m(A,B), \qquad w(A,B)=\sigma\big(g(z(A,B))\big),$$
where $g$ is a two-layer network and $\sigma$ is an elementwise sigmoid. We use a sigmoid rather than a softmax because MMAN found non-competitive weighting better for program graphs. That choice is also an ablation. The gate input $z(A,B)$ contains only symmetric quantities. The first is the vector of pairwise gaps $|s_m - s_{m'}|$, which measures cross-modal disagreement. The second is token-level Jaccard overlap. The third is the unordered pair of mean GAT attention entropies. High entropy means attention is spread diffusely across neighbors, which the file flags as an untested signal of structural ambiguity. The last is a parse-success flag. Because every per-item embedding can be cached, scoring a candidate pair costs three dot products and a tiny network. This preserves the embedding-index scalability that cross-encoders give up. We train with contrastive loss on $S$ and add small auxiliary contrastive losses on each $s_m$ so that no modality is starved of gradient. The file names such starvation, from gates converging early on a dominant modality, as a known failure of dynamic fusion.
Research Program
We first build the three encoders and the gate on Java (BigCloneBench, Google Code Jam) and C (POJ-104). For every benchmark we report how many programs yield a dependency graph at all. Next we construct two diagnostic slices from test pairs using DISCO-style transformations. The hard-negative slice contains pairs with token overlap above a high threshold and an injected semantic edit. The divergent-positive slice contains same-problem Code Jam and POJ-104 pairs with token overlap below Oreo's 70% "twilight zone" boundary. Finally we analyze the gate. We measure whether the dependency-graph weight is higher on hard negatives and the action and token weights higher on divergent positives, and whether GAT entropy predicts dependency-graph error. In a secondary experiment we artificially break parsing on a fraction of inputs to test graceful degradation.
Baselines
The naive reference point is the token-only Siamese encoder (CodeBERT fine-tuned with shared weights and cosine scoring). It shows what text alone achieves; CodeXGLUE reports CodeBERT at F1 96.5 on BigCloneBench (CodeXGLUE).
The strongest existing structural method is HOLMES. We reimplement it and train it on identical splits, reporting its published Code Jam F1 of 0.92 and BigCloneBench F1 of 0.98 as anchors (HOLMES). On POJ-104 the reference is DISCO at MAP@R 83.32% (DISCO).
The ablation baselines isolate the key ingredient. The first is static fusion, which uses the same three encoders with learned fixed weights. The second is instance-level gating in the MMAN and squeeze-and-excitation style, where weights come from each program separately and are symmetrized by averaging; Zhang et al. report 96.7% versus 89.1% true-positive rate over concatenation for this kind of gate in vision. The third is a post-hoc stacker, a logistic regression over frozen per-modality similarities plus the same pair statistics. The fourth is the gate with softmax normalization.
For fairness, all systems share encoder backbones, data splits, a fixed hyperparameter search budget per system, and matched total training steps. Beating the field means clear gains on both diagnostic slices simultaneously and on Code Jam F1 and POJ-104 MAP@R, with at least parity on BigCloneBench. The pair gate must also beat the instance gate specifically on the hard-negative slice. That slice is where a per-program gate cannot know the partner is a near-duplicate.
Why not just…?
Why not just fine-tune a large code encoder and skip graphs and gating? DISCO shows that CodeBERT and GraphCodeBERT treat one-operator edits as clones, and CODE-MVP's ablation shows performance drops without control-flow views. BigCloneBench, however, is near-saturated for text models (96.5 F1), so the token-only baseline is a real threat there. We therefore make our case on the hard-negative and divergent slices and on Code Jam. If the token baseline matches us on those, the claim fails.
Why not just fall back to tokens whenever the parser fails? That hard switch captures the missing-modality case, and we expect it to be competitive on the corrupted-parse experiment. It says nothing about pairs where both parses succeed but the structures disagree, which is the regime our claim concerns. The divergent-positive slice separates the two approaches.
Why not just stack per-modality scores with logistic regression? This is the most serious alternative, because it can use the same pair statistics. If it matches the jointly trained gate, the contribution reduces to the empirical finding that trust should be conditioned on pair-level disagreement. That finding is still new relative to MMAN and HOLMES, and we will report it as such. Joint training earns its place only if the dependency-graph encoder, trained under the gate, becomes measurably more accurate on hard negatives than when trained independently. That would indicate the encoders specialize once they are no longer penalized on pairs they cannot solve.
Why not a cross-encoder that reads both programs together? A cross-encoder is naturally pair-conditioned and may be more accurate. It costs full model inference per pair, which the file identifies as the quadratic bottleneck of pairwise similarity. We found no reported result on Lacuna for a cross-encoder on Google Code Jam. We will run one as an accuracy ceiling and report accuracy against pairs scored per second.
Decisive Checks
The idea stands or falls on three measurements. First, the mean dependency-graph gate weight must be significantly higher on the hard-negative slice than on the divergent-positive slice, with the action/token weight showing the opposite pattern. If the weights are flat across slices, the gate is doing nothing pair-specific. Second, the pair gate must beat instance-level gating on the hard-negative slice, as defined in the Baselines section. Third, the pair gate must improve Code Jam F1 over our HOLMES reimplementation and POJ-104 MAP@R over the DISCO reference under matched budgets. A secondary check is whether GAT attention entropy predicts dependency-graph errors (for example via area under the ROC curve on held-out pairs). If it does not, it is dropped from the gate, which answers the open question in the file's Gap 2 either way.
References
- Modeling Functional Similarity in Source Code With Graph-Based Siamese Networks
- Graph Attention Networks
- The Natural Geometry of Code: Hyperbolic Representation Learning for Program Reasoning
- Multi-modal Attention Network Learning for Semantic Source Code Retrieval
- CODE-MVP: Learning to Represent Source Code from Multiple Views with Contrastive Pre-Training
- Towards Learning (Dis)-Similarity of Source Code from Program Contrasts
- Oreo: detection of clones in the twilight zone
- CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generation
- A Dataset and Benchmark for Large-Scale Multi-Modal Face Anti-Spoofing