Code Clone Detection via an AlphaFold-Inspired Framework

Changguo Jia, Yi Zhan, Tianqi Zhao, Hengzhi Ye, Minghui ZhouarXiv 2025 · DOI

Introduction

Code clone detection—identifying identical or functionally equivalent code fragments—is a cornerstone of modern software maintenance and bug propagation analysis. However, the field faces a persistent "single-sequence challenge": extracting deep semantic logic from flat, linear sequences of code tokens.

Existing approaches generally fall into two categories. Token-based methods are efficient and language-agnostic but often fail to detect "Type-4" clones, which perform the same function using entirely different syntax. Conversely, Intermediate Representation (IR)-based methods utilize Abstract Syntax Trees (ASTs) or Control Flow Graphs (CFGs) to capture deeper semantics. While more accurate, these methods are computationally expensive and fragile, often breaking when faced with legacy code or syntax that third-party parsers cannot handle.

The Biological Inspiration

The authors of AlphaCC observed a striking parallel between software engineering and structural biology. Predicting the 3D structure of a protein from its 1D amino acid sequence mirrors the challenge of inferring a program's high-level logic from its 1D token stream. In both domains, the "meaning" of an individual element (an amino acid or a variable) is defined by its context and relationship to its neighbors.

The analogy between protein sequences and code token sequences.

By leveraging the core breakthroughs of AlphaFold—specifically Multiple Sequence Alignment (MSA) and dual-attention mechanisms—AlphaCC aims to bridge the gap between the speed of token-based methods and the semantic depth of IR-based approaches.

The AlphaCC Framework

AlphaCC introduces a three-stage pipeline that adapts the AlphaFold architecture for source code analysis.

Comparison of the AlphaFold architecture and the proposed AlphaCC framework.

1. Code MSA (Multiple Sequence Alignment)

Just as AlphaFold analyzes evolutionarily related proteins to understand a target sequence, AlphaCC employs a retrieval-augmentation strategy. For any input code fragment, the system searches a massive codebase (comprising over 10,000 GitHub repositories) for lexically similar "neighbors." By aligning these fragments, the model can distinguish between essential logic and superficial syntactic noise.

2. Token Semantic Enhancer

To move beyond raw text, AlphaCC categorizes tokens into 15 distinct types, such as Identifiers, Operators, and Keywords. These are projected into specialized semantic spaces, ensuring the model recognizes that an if statement and a + operator serve fundamentally different structural roles.

3. Codeformer Encoder

The heart of the system is the Codeformer, a dual-attention module inspired by AlphaFold’s Evoformer. It consists of:

  • Inner-Sequence Attention: This models the internal logic, data flow, and control flow within a single function.
  • Inter-Sequence Attention: This identifies functional commonalities across the aligned sequences in the MSA, allowing the model to "see" the underlying computational skeleton shared by different implementations.

The pipeline concludes with a Late Interaction layer and Margin Loss, which compare code fragments at the token level to establish a clear decision boundary between clones and non-clones.

Experimental Evaluation

The authors evaluated AlphaCC against three major benchmarks:

  • GCJ (Google Code Jam): Java snippets solving identical problems.
  • BigCloneBench (BCB): A large-scale Java dataset spanning Type-1 to Type-4 clones.
  • OJClone: A C language dataset of student submissions, characterized by high syntactic diversity.

Key Results

AlphaCC achieved state-of-the-art performance, recording F1 scores of 97.4% on GCJ, 96.0% on BigCloneBench, and 98.6% on OJClone. Notably, it is the first token-based framework to outperform top-tier IR-based models (such as PNIAT+CFG) in semantic clone detection.

Beyond accuracy, AlphaCC demonstrated significant efficiency gains. It processed one million code pairs in approximately 10,622 seconds for preprocessing—a fraction of the time required by many graph-based methods. Furthermore, its token-based nature makes it highly robust; in tests where standard parsers like tree-sitter failed, AlphaCC maintained a 95.8% F1 accuracy.

Conclusion and Future Work

AlphaCC represents a significant shift in code clone detection by demonstrating that biological sequence analysis techniques can solve complex software engineering problems. By replacing fragile parsers with retrieval-augmented attention, it achieves deep semantic understanding without sacrificing efficiency.

Future research will focus on expanding the framework's language support beyond Java and C and exploring how the quality of the retrieval pool (the Code MSA) impacts detection performance across diverse software domains.

Summary updated

BibTeX
@misc{jia2025code,
  author = {Changguo Jia and Yi Zhan and Tianqi Zhao and Hengzhi Ye and Minghui Zhou},
  title = {{Code Clone Detection via an AlphaFold-Inspired Framework}},
  year = {2025},
  eprint = {2507.15226},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.15226},
}
Figure