Abstract
Identifying semantic clones—code snippets that perform the same logic despite different syntax—is a cornerstone of software engineering. While monolingual clone detection is well-established, cross-lingual clone detection (e.g., matching a Python function to a C++ equivalent) remains a significant challenge. This paper introduces Cross-Consistency Training (CCT), a novel training procedure that aligns the "meaning" of code across different programming languages. By leveraging contrastive learning and a new multilingual dataset (XCD), the authors achieve state-of-the-art results in both detecting semantic code clones and performing natural language code searches.
Introduction
Existing models for code representation often cluster snippets by syntax (language-specific keywords) rather than semantics (the actual logic). This creates a "language gap" that hinders cross-lingual tasks. The authors aim to bridge this gap by creating a shared latent space where code snippets are grouped by their functionality, regardless of whether they are written in Java, Ruby, or C#.
Methodology
The core innovation is Cross-Consistency Training (CCT), a pre-training method based on Noise-Contrastive Estimation (NCE).
- Semantic Alignment: The model is trained to produce similar embeddings for code snippets that solve the same problem, even if they are in different languages.
- Hard Negative Mining: To make the model robust, the authors mined failed submissions from competitive programming platforms. These are snippets that look like they solve a problem (sharing variables and structure) but are logically incorrect. This forces the model to learn deep logic rather than surface-level patterns.
- Model Architectures: CCT was applied to both encoder-only models (starting from GraphCodeBERT) and decoder-only models (starting from DeepSeek-Coder), proving the technique is architecture-agnostic.
Datasets
The paper utilizes three primary benchmarks:
- POJ-104: A standard monolingual C++ clone detection dataset.
- AdvTest: A Python-only code search benchmark for natural language descriptions.
- XCD (New): A Cross-lingual Clone Detection dataset consisting of 55,000 code snippets across 5 languages (Python, Java, C#, C++, C) sourced from CodeForces, including metadata like error statuses for hard negative mining.
Key Results and Insights
The CCT-LM models established new benchmarks across the board. On the POJ-104 benchmark, the model achieved a 96.73% Mean Average Precision (MAP), while on AdvTest, it reached 47.18% Mean Reciprocal Rank (MRR).
A primary insight of the study is the reorganization of the latent space. Before CCT, models naturally clustered code by language. After CCT, the latent space reorganized to cluster snippets by the problem they solve, effectively making the model "language-blind" but "logic-aware."
Furthermore, the authors found that aligning different programming languages also significantly boosts performance in code search (text-to-code), suggesting that cross-lingual alignment helps align code with natural language descriptions.
Conclusion
CCT-Code demonstrates that training on logical "failures" and cross-lingual consistency can bridge the gap between syntax and semantics. While the study focused on popular C-style and interpreted languages within a 512-token context window, future work may explore more diverse paradigms like functional programming and the impact of longer context windows on real-world codebases.
Summary updated