Droid: A Resource Suite for AI-Generated Code Detection
Daniil Orel, Indraneil Paul, Iryna Gurevych, Preslav Nakov
Presenter: Daniil Orel (daniil.orel@mbzuai.ac.ae)
Problem Statement
Current tools for detecting AI-generated code rely on narrow datasets-limited models, languages, and domains-making them unreliable. As post-training methods advance, code copilots may even be optimized to evade such detectors. This calls for more robust approaches to identify human, AI, hybrid authorship, and adversarial generations across diverse scenarios.
| Size | Domains | Models | Vary Sampling | Machine Refined | Adversarially Humanized |
GPT-Sniffer | 7.4K | 1 | 1 | ❌ | ❌ | ❌ |
CodeGPTSensor | 1.1M | 1 | 1 | ❌ | ❌ | ❌ |
Whodunit | 1.6K | 1 | 1 | ❌ | ❌ | ❌ |
CoDet-M4 | 501K | 2 | 5 | ❌ | ✅ | ❌ |
CodeMirage | 210K | 1 | 10 | ❌ | ✅ | ❌ |
DroidCollection | 1.06M | 3 | 43 | ✅ | ✅ | ✅ |
Building DroidCollection (AI-Generated data)
Open-Source Datasets: TACO, CodeNet, StarCoderData, etc
Problem
Statement
Docstring
Comments
Source
Code
Solution
Implementation
Inverse
Instruction
Implementation
DroidCollection
Building DroidCollection (Unconditional Data)
Programmer
Description
Potential
Tasks
Solution
We generate programmer descriptions based on: primary programming language, field of work (web, DS/ML, IoT, game development, etc), code commenting style, error-proneness, debugging strategies, documentation habits, function length.
Building DroidCollection (Hybrid Data)
We take human-written code and:
Code
Sample
Rewritten
Code
Incomplete
Code
Code Completion
Building DroidCollection (Adversarial Data)
We collected a preference dataset (DroidCollection-Pref) of 157K Human-AI authored code pairs. Then we run LoRA DPO training to make models prefer Human-like code over AI-styled one
Original
LLM
DPO
Fine-Tuning
Adversarial
Code
Human-Like
LLM
Varying Sampling Parameters
Previous work [1] has shown that AI-generated code detection with greedy decoding is easier than detection with varied sampling strategies. That is why we vary sampling strategies in our dataset.
[1] Daphne Ippolito, Daniel Duckworth, Chris Callison-Burch, and Douglas Eck. 2020. Automatic Detection of Generated Text is Easiest when Humans are Fooled. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 1808–1822.
Strategy | Attribute | Range |
Greedy | - | - |
Sampling | Temperature | {0.1, 0.4, 0.7, 1.0, 1.5, 2.0} |
Top-k | {10, 50, 100} | |
Top-p | {1.0, 0.95, 0.9, 0.8} | |
Beam Search | Beam width | {2, 4, 6, 8} |
Data Filtering
To ensure that the data quality is high, we apply a series of filters to the dataset.
We did not filter out human-written codes that appear after the spark of AI-driven code copilots
Do we really need a large dataset?
Model | 2-class (avg.) | 3-class (avg.) | ||
Domain | Language | Domain | Language | |
GPT-Sniffer | 41.07 | 52.40 | 38.95 | 49.96 |
CoDet-M4 | 54.49 | 47.97 | 47.80 | 41.28 |
M4 | 50.92 | 52.40 | 55.27 | 57.92 |
GPT-Sniffer | 91.56 | 97.22 | 82.75 | 85.16 |
CoDet-M4 | 93.63 | 99.08 | 83.25 | 89.60 |
M4 | 85.45 | 91.63 | 73.50 | 76.57 |
DroidDetect-Base | 95.00 | 99.11 | 86.76 | 93.56 |
DroidDetect-Large | 97.00 | 99.23 | 88.78 | 93.66 |
Zero-Shot
Fine-Tuned
Ours
Is adversarial data challenging?
| Human | Adversarial |
FastDetectGPT | 0.84 | 0.48 |
GPTSniffer | 0.65 | 0.49 |
M4 | 0.40 | 0.73 |
CoDet-M4 | 0.38 | 0.63 |
GPT-Zero | 0.53 | 0.10 |
Human | Adversarial |
0.91 | 0.67 |
0.97 | 0.55 |
0.96 | 0.51 |
0.93 | 0.92 |
0.98 | 0.92 |
Zero-Shot
Fine-Tuned
We see that recall of zero-shot models on adversarial data is very low. Only M4 and CoDet-M4 show recall over 0.5, but they are just biased towards positive class
Training DroidDetect
Model Variant | 2-class | 3-class | 4-class | |||
Base | Large | Base | Large | Base | Large | |
DroidDetect | 99.18 | 99.25 | 94.36 | 95.17 | 92.95 | 94.30 |
[-]Resampling | 99.15 | 99.22 | 93.86 | 94.43 | 92.52 | 93.14 |
[-] Metric Learning | 99.14 | 99.18 | 90.51 | 94.07 | 89.63 | 92.65 |
How input length affects performance?
We observe that while other models tend to perform worse on larger inputs (likely because they were trained on short code snippets), our model performs better with longer inputs
Model | Input Length | ||
128 | 256 | 512 | |
GPT-Sniffer | 57.05 | 57.20 | 56.64 |
M4 | 59.69 | 53.10 | 51.13 |
CoDet-M4 | 72.28 | 70.62 | 61.68 |
DroidDetect-Base | 91.90 | 96.25 | 99.18 |
DroidDetect-Large | 94.91 | 98.31 | 99.25 |
Can our model generalize?
We evaluate our model on 15k samples from unseen datasets:
Model | Swallow-Code | The Heap |
DroidDetect-Base | 98.95 | 94.14 |
DroidDetect-Large | 99.11 | 96.28 |
Conclusion
We introduce DroidCollection, a large, diverse dataset suite designed for training and evaluating robust AI-generated code detectors. It supports common LLM code copilot scenarios—code completion, rewriting, and adversarial uses—and offers broader coverage than existing public corpora in terms of generators, generation settings, programming languages, and domains. Using DroidCollection, we developed DroidDetect, a family of detection models (base and large), which outperform existing approaches across multiple tasks. We also conducted extensive ablation studies to identify the most effective training strategies.
Dataset & Paper & Contact
Contact
Paper
Dataset
mbzuai.ac.ae
Mohamed bin Zayed University of Artificial Intelligence
Masdar City, Abu Dhabi, United Arab Emirates
Thank you