LLMSniffer: Detecting LLM-Generated Code via GraphCodeBERT and Supervised Contrastive Learning
Mahir Labib Dihan, Abir Muhtasim
TLDR
LLMSniffer detects AI-generated code using GraphCodeBERT and supervised contrastive learning, achieving significant accuracy improvements on benchmark datasets.
Key contributions
- Introduces LLMSniffer, a framework for detecting LLM-generated code.
- Uses GraphCodeBERT fine-tuned with two-stage supervised contrastive learning and comment removal.
- Boosts accuracy to 78% on GPTSniffer and 94.65% on Whodunit, significantly beating baselines.
- Releases model checkpoints, datasets, code, and an interactive demo to foster further research.
Why it matters
Distinguishing AI-generated code is crucial for academic integrity, code quality, and security. LLMSniffer offers a robust solution, setting a new benchmark for detection accuracy. This work provides valuable tools and insights for the evolving landscape of AI in software development.
Original Abstract
The rapid proliferation of Large Language Models (LLMs) in software development has made distinguishing AI-generated code from human-written code a critical challenge with implications for academic integrity, code quality assurance, and software security. We present LLMSniffer, a detection framework that fine-tunes GraphCodeBERT using a two-stage supervised contrastive learning pipeline augmented with comment removal preprocessing and an MLP classifier. Evaluated on two benchmark datasets - GPTSniffer and Whodunit - LLMSniffer achieves substantial improvements over prior baselines: accuracy increases from 70% to 78% on GPTSniffer (F1: 68% to 78%) and from 91% to 94.65% on Whodunit (F1: 91% to 94.64%). t-SNE visualizations confirm that contrastive fine-tuning yields well-separated, compact embeddings. We release our model checkpoints, datasets, codes and a live interactive demo to facilitate further research.
📬 Weekly AI Paper Digest
Get the top 10 AI/ML arXiv papers from the week — summarized, scored, and delivered to your inbox every Monday.