Detecting Data Contamination in LLMs via In-Context Learning
Michał Zawalski, Meriem Boubdir, Klaudia Bałazy, Besmira Nushi, Pablo Ribalta
TL;DR
CoDeC introduces a model- and dataset-agnostic method for detecting training-data contamination in LLMs by measuring how in-context examples from a suspect dataset affect predictions, identifying memorization signals through negative shifts in log-probability. The approach yields a dataset-level contamination score with near-perfect separation between seen and unseen data (AUC around $99.9\%$) across diverse models, baselines, and benchmarks, and it remains robust to training dynamics and finetuning. Empirical results show contamination signals arise early in training, intensify with finetuning, and transfer to related distributions, while larger models tend to exhibit lower contamination due to improved generalization. CoDeC is efficient (two forward passes per sample, gray-box access) and provides actionable guidance for fair benchmark evaluation and model development, enabling ongoing trust in published results.
Abstract
We present Contamination Detection via Context (CoDeC), a practical and accurate method to detect and quantify training data contamination in large language models. CoDeC distinguishes between data memorized during training and data outside the training distribution by measuring how in-context learning affects model performance. We find that in-context examples typically boost confidence for unseen datasets but may reduce it when the dataset was part of training, due to disrupted memorization patterns. Experiments show that CoDeC produces interpretable contamination scores that clearly separate seen and unseen datasets, and reveals strong evidence of memorization in open-weight models with undisclosed training corpora. The method is simple, automated, and both model- and dataset-agnostic, making it easy to integrate with benchmark evaluations.
