Droid: A Resource Suite for AI-Generated Code Detection

Daniil Orel, Indraneil Paul, Iryna Gurevych, Preslav Nakov · DOI

Abstract

The proliferation of AI coding assistants has necessitated robust methods for distinguishing human-authored code from machine-generated outputs. This paper presents Droid, a comprehensive resource suite designed to advance the state of AI-generated code detection. Droid includes DroidCollection, a massive dataset of over 1 million samples across seven programming languages and 43 LLMs, and DroidDetect, a suite of high-performance detectors. By incorporating adversarial "humanized" code and multi-task learning objectives, DroidDetect achieves a 99% F1-score in binary classification and demonstrates superior resilience against adversarial attacks compared to existing benchmarks.

1. Introduction

The integration of AI coding assistants like GitHub Copilot and Cursor into the software development lifecycle has transformed the industry. However, this shift introduces significant challenges regarding academic integrity, software supply chain security, and the risk of "model collapse"—a phenomenon where future AI models degrade by training on their own synthetic outputs. Reliable detection of AI-generated code is no longer a niche requirement but a critical infrastructure need.

Existing detection tools often suffer from limited scope, focusing on a narrow set of languages or specific models. Furthermore, they frequently fail to account for "co-authored" code—where humans and AI collaborate—or adversarial techniques designed to mimic human coding styles. To address these gaps, we introduce Droid, a resource suite that provides both the data and the modeling framework necessary for robust, real-world code attribution.

2. The DroidCollection Dataset

DroidCollection represents the largest open-source effort to date for AI code detection. It addresses the "narrow vision" of previous benchmarks through scale and diversity.

2.1 Scale and Diversity

The dataset comprises 1.06 million code samples, covering seven major programming languages: C++, C#, Go, Java, JavaScript, Python, and C. It includes outputs from 43 different LLMs, ranging from open-weight models like Llama 3 to proprietary systems like GPT-4o. This diversity ensures that detectors trained on DroidCollection can generalize across different model architectures and coding paradigms.

2.2 Generation Strategies

To capture the nuance of real-world code, DroidCollection utilizes three distinct generation strategies:

  • Inverse Instruction: Researchers extracted human code and used LLMs to reconstruct the likely prompts that would have generated it. These prompts were then used to generate machine counterparts, creating a direct "human vs. machine" comparison for the same functional task.
  • Persona-Based Generation: To simulate different developer profiles, the suite uses "programmer personas." This ranges from junior developers who might omit comments to researchers who write highly modular, specialized code.
  • Adversarial Tuning (DroidCollection-Pref): A specialized subset of 157,000 pairs was created using Direct Preference Optimization (DPO). This "red team" data specifically trains models to generate code that evades detection by mimicking human stylistic quirks.

3. DroidDetect: Architecture and Methodology

The DroidDetect suite utilizes a fine-tuned ModernBERT (an encoder-only transformer) as its backbone. The training process incorporates several advanced techniques to improve reliability:

  • Multi-Task Learning: Instead of a simple binary classifier, the model is trained on a multi-task objective that includes domain classification and language identification, which helps the model learn more robust features.
  • Metric Learning: Using triplet loss, the researchers ensured that human, AI-generated, and AI-refined code occupy distinct clusters within the model's internal representation space. This is particularly effective for the "ternary" task of distinguishing between pure machine code and machine-refined human code.
  • Uncertainty Filtering: To maintain high data quality, the team employed MC Dropout to identify and prune noisy or ambiguous samples from the training set, ensuring the model learns from clear, high-signal examples.

4. Key Insights and Results

The evaluation of DroidDetect revealed several critical findings for the field of AI forensics.

4.1 The Generalization Gap

The study confirmed that code detectors are often fragile. A detector trained exclusively on Python, for instance, performs poorly on JavaScript. Similarly, models trained on general GitHub repositories struggle with the specific syntax and logic of competitive programming. Droid’s multi-language, multi-domain training set is essential for overcoming this fragility.

4.2 The Threat of "Humanization"

One of the most significant findings is the effectiveness of adversarial prompting. When an LLM is prompted to "write like a human," the recall of standard detectors can drop from 90% to as low as 10%. However, the researchers found that including even a small percentage of adversarial samples in the training data significantly restores the detector's performance.

4.3 Performance Metrics

DroidDetect-Large sets a new state-of-the-art across multiple benchmarks:

  • Binary Classification: Achieved a weighted F1-score of ~99% (Human vs. Machine).
  • Ternary Classification: Maintained an F1-score of ~93% when distinguishing between human, machine-generated, and machine-refined code.
  • Adversarial Robustness: While commercial tools like GPT-Zero struggled against humanized AI code, DroidDetect maintained a recall of over 0.92.

5. Conclusion and Future Directions

Droid provides a robust foundation for the next generation of AI code detectors. By moving beyond simple binary classification and addressing the threat of adversarial "humanization," it offers a more realistic toolset for developers and researchers.

Future work will focus on expanding the dataset to include newer "reasoning" models (e.g., OpenAI o1, DeepSeek-R1) and additional programming languages such as Rust, Ruby, and PHP. As AI models continue to evolve, the Droid suite will serve as an essential evolving benchmark in the ongoing effort to maintain transparency in software authorship.

Summary updated

BibTeX
@misc{orel2025droid,
  author = {Daniil Orel and Indraneil Paul and Iryna Gurevych and Preslav Nakov},
  title = {{Droid: A Resource Suite for AI-Generated Code Detection}},
  year = {2025},
  eprint = {2507.10583},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.10583},
}
Figure