Introduction
Detecting "functional clones"—code snippets that perform the same task but differ significantly in appearance—remains a formidable challenge in software engineering. While Types 1 through 3 clones (lexical or structural variations) are relatively easy to identify, Type-4 functional clones (e.g., bubble sort vs. quick sort) share almost no syntactical similarity. This paper introduces CDPU, a framework that addresses two primary hurdles: the scarcity of labeled clone data and the "near-miss" trap, where syntactically similar code performs different functions due to minor character changes.
Methodology: The CDPU Framework
CDPU (Clone Detection with Positive-Unlabeled learning) integrates several advanced techniques to bridge the gap between syntax and semantics.
AST-based Feature Learning
Instead of treating code as raw text, CDPU parses it into an Abstract Syntax Tree (AST). A specialized Long Short-Term Memory (LSTM) network processes the tree from leaves to root, capturing both structural logic and the semantic meaning of individual tokens.
Adversarial Training for Robustness
To combat the "near-miss" problem—where a single character change (like changing a + to a *) alters functionality—the authors employ adversarial training. By injecting small, calculated perturbations into feature representations during training, the model learns to become robust, distinguishing between superficial similarity and true functional equivalence.
Unbiased PU-AUC Optimization
In real-world scenarios, labeled "non-clones" are rare. CDPU treats clone detection as a Positive-Unlabeled (PU) learning problem. By optimizing for Rank Loss (PU-AUC), the model treats unlabeled data as a noisy negative set. This allows it to learn to rank true clones higher than unlabeled pairs without requiring a predefined class prior.
Deep Hashing for Efficiency
To ensure the detection process remains fast even in massive codebases, CDPU integrates a hashing layer directly into the end-to-end learning process. The model maps complex code representations into short binary "hash codes," which are computationally much cheaper to compare than raw high-dimensional neural embeddings.
Evaluation and Results
The researchers evaluated CDPU on BigCloneBench (Java) and OJClone (C). In BigCloneBench, the authors simulated a real-world scenario by stripping away most labels, leaving only 0.021% of the data labeled as clones.
Superior Performance on Type-4 Clones
CDPU significantly outperforms traditional and unsupervised deep learning tools, particularly on the most difficult clone types. As shown in the results, CDPU achieved an F1-score of 0.51 for Type-4 clones on BigCloneBench, whereas tools like Deckard (0.02) and DLC (0.00) almost entirely failed to detect them.
Label Efficiency and Robustness
The framework proved highly efficient, reaching near-peak performance using only ~3% of available labeled data. Furthermore, the inclusion of adversarial training was critical; removing it (CDPU vs. CDPU⁻) dropped the overall F1-score from 0.51 to 0.44 on BigCloneBench, confirming its role in distinguishing "near-miss" non-clones.
Conclusion
CDPU demonstrates that combining PU learning with adversarial training effectively addresses the challenges of functional clone detection. By focusing on functional essence rather than superficial syntax and leveraging unlabeled data, it sets a new state-of-the-art for identifying Type-4 clones. Future work may extend this framework to other software engineering tasks like bug detection and semantic code search.
Summary updated