NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

CONCORD: Clone-Aware Contrastive Learning for Source Code

Yangruibo Ding, Saikat Chakraborty, Luca Buratti, Saurabh Pujar, Alessandro Morari, Gail E. Kaiser, Baishakhi Ray · DOI · OpenReview

TL;DR

This paper introduces CONCORD, a novel self-supervised pre-training method for source code that explicitly models developer coding habits like copy-pasting. By training models to recognize benign code clones as similar and buggy "deviant" clones as dissimilar, CONCORD significantly improves performance on tasks like clone detection and bug finding, even with less training data and resources.

What Problem Does This Paper Address?

Modern deep learning models excel at understanding source code, but they often struggle to capture the nuances of how developers actually write code. A common practice is copy-pasting existing code snippets (creating "clones") and then adapting them. While this is efficient, it can also introduce subtle errors, leading to "deviant" clones that are functionally different and potentially buggy. Existing code models, which primarily focus on lexical or syntactic properties (like tokens or Abstract Syntax Trees), fail to effectively distinguish between these benign clones and harmful deviants. This leads to inaccurate code representations that can't reliably identify semantically equivalent code or detect bugs.

Methods

CONCORD tackles this by incorporating developer coding behaviors into its pre-training strategy through a three-stage process:

  1. Data Augmentation: This is a key innovation. Instead of relying on generic data augmentation, CONCORD uses carefully crafted heuristics to generate two types of variants for each code snippet:
  2. Benign Clones: These are functionally equivalent to the original code but may have different identifiers, types, or statement structures, mimicking how developers adapt copied code.
  3. Buggy Deviants: These are syntactically similar to the original code but contain subtle bugs (e.g., incorrect operators, data type mismatches) that alter their behavior, reflecting common human errors during code adaptation.
  4. Two-Phase Pre-training:
    • Phase I (Masked Language Model - MLM): This standard phase helps the model learn general code text understanding by predicting masked tokens.
  5. Phase II (Multi-task Contrastive Learning): This phase leverages the augmented data. It uses a contrastive learning objective to pull representations of the original code and its benign clones closer together in the embedding space, while pushing the representations of the original code and its buggy deviants further apart. Additionally, a Local Tree Structure Prediction (LTSP) objective is used to help the model understand code syntax and structure.
  6. Fine-tuning: The pre-trained CONCORD model is then fine-tuned for specific downstream tasks like clone detection and bug detection.

Datasets

CONCORD was pre-trained on a multi-lingual corpus of C, C++, and Java code collected from popular GitHub repositories. For evaluation, it was tested on several standard datasets:

  • Semantic Clone Detection: CodeXGLUE-POJ104 (C/C++) and CodeNet-Java250 (Java).
  • Bug Detection: REVEAL (RV), D2A, and CodeXGLUE-Devign (CXG-DV) (all C/C++).
  • Code Search: CodeSearchNet (Java).

Key Insights and Ideas

  • Developer Behavior is Key: The paper strongly argues that understanding how developers actually code, including their tendency to copy-paste and the errors they introduce, is crucial for building effective code understanding models.
  • Benign Clones vs. Buggy Deviants: The core idea of treating benign clones as positive examples and buggy deviants as negative examples in contrastive learning is a powerful way to teach models semantic similarity and dissimilarity.
  • Heuristic-driven Augmentation: CONCORD's custom data augmentation, inspired by real-world coding practices, proves more effective and controllable than generic deep learning-based augmentation methods.
  • Efficiency Matters: CONCORD achieves state-of-the-art results with significantly less training data and fewer training steps compared to existing models, making it more resource-efficient.

Key Results

  • Superior Performance: CONCORD achieved state-of-the-art results on semantic clone detection (91.5% MAP@R on CodeXGLUE-POJ104) and bug detection (best F1 scores across three benchmarks), outperforming models trained with much larger datasets.
  • Improved Existing Models: When CONCORD's pre-training strategy was applied to existing models like CodeBERT and GraphCodeBERT, their performance on downstream tasks improved significantly (e.g., MAP@R for clone detection increased from 82.7% to 89.3% for CodeBERT).
  • Better Representations: Visualizations (using PCA) showed that CONCORD-enhanced models produced code representations with clearer boundaries between different coding challenges, indicating a better grasp of semantic similarity.
  • Efficiency: CONCORD was pre-trained with only 1.55 GB of code for 40k steps, a fraction of the data and steps used by models like CodeBERT and GraphCodeBERT.

Limitations and Future Work

  • Data Augmentation Scope: While CONCORD's heuristics are carefully crafted, they may not cover all possible developer coding patterns. Future work could explore other developer behaviors like variable naming conventions.
  • Cross-lingual Clones: The current data augmentation generates variants within the same programming language. Extending this to detect cross-lingual semantic clones is a potential future direction.
  • Hard Negative Guarantee: While deviants are designed to be buggy, it's difficult to guarantee they will always exhibit malicious behavior. The assumption that in-batch samples are random negatives might not always hold.
  • Weight Tuning: The optimal weights for the different loss functions (MLM, LTSP, CLR) were not exhaustively searched due to the cost of pre-training. Further tuning could potentially yield even better results.
  • Multi-modal Extension: The paper suggests that CONCORD's framework can be extended to multi-modal tasks (like code search with natural language) by leveraging pre-trained multi-modal models.

Summary updated

BibTeX
@inproceedings{ding2023concord,
  author = {Yangruibo Ding and Saikat Chakraborty and Luca Buratti and Saurabh Pujar and Alessandro Morari and Gail E. Kaiser and Baishakhi Ray},
  title = {{CONCORD: Clone-Aware Contrastive Learning for Source Code}},
  booktitle = {ISSTA},
  year = {2023},
  doi = {10.1145/3597926.3598035},
}
Figure