Generalization or Memorization: Data Contamination and Trustworthy Evaluation for Large Language Models

Yihong Dong, Xue Jiang, Huanyu Liu, Zhi Jin, Bin Gu, Mengfei Yang, Ge Li

Abstract

As Large Language Models (LLMs) are trained on increasingly massive datasets, the risk of "data contamination"—the inclusion of test benchmarks in training data—has grown significantly. This contamination inflates evaluation scores, masking a model's true generalization capabilities with rote memorization. This paper proposes two novel frameworks: CDD (Contamination Detection via output Distribution) and TED (Trustworthy Evaluation via output Distribution). By identifying "peaked" output distributions where a model repeatedly generates nearly identical responses, these methods can detect leaks and provide more accurate performance assessments, even for black-box models. Our results show that CDD improves detection accuracy by up to 30.2% over traditional methods, while TED effectively restores honest performance metrics.

Introduction

The rapid advancement of LLMs relies on vast, often opaque training sets. A critical consequence is data contamination, where test questions from benchmarks like HumanEval or GSM8K are inadvertently leaked into the training corpus. This leads to a "memorization trap": models achieve high scores by recalling specific training examples rather than learning underlying logic. Current detection efforts face three major hurdles: the opacity of training data, the black-box nature of commercial models like GPT-4, and "implicit contamination" where rephrased or translated test data bypasses simple exact-match filters.

Methodology

The core hypothesis of this work is that training on specific data "peaks" the model's output distribution toward that text. While an uncontaminated model might generate diverse, valid solutions to a prompt, a contaminated model's distribution collapses toward the specific version it encountered during training.

Conceptual illustration of how training data creates an abnormal "peak" in the output distribution compared to a normal, diverse distribution.

To leverage this, the researchers developed:

  1. CDD (Contamination Detection via output Distribution): This method calculates the token-level edit distance between multiple sampled outputs for the same prompt. A high frequency of near-zero edit distances (exact or near-exact matches) flags the data as leaked.
  2. TED (Trustworthy Evaluation via output Distribution): A mitigation strategy that discards "greedy" (most likely memorized) outputs and filters redundant samples to restore a "clean" evaluation score.

Experimental Setup

The methods were validated using standard benchmarks (HumanEval, GSM8K) and two newly created datasets:

  • DETCON: 2,224 tasks for testing detection across explicit (exact) and implicit (rephrased) leaks.
  • COMIEVAL: 560 tasks to evaluate mitigation effectiveness.

Additionally, the authors tested commercial models on HumanEval_R (a rephrased version of HumanEval) and CodeForces2305 (new programming problems released after ChatGPT's training cutoff) to find real-world evidence of contamination.

Results and Insights

A key finding is that memorization destroys output diversity. In a contaminated model, the density of "zero edit distance" samples increases dramatically after exposure to the test data. CDD proves robust against implicit contamination because the underlying distributional "peak" remains even when text is rephrased.

Performance comparison of CDD against N-gram and LLM-based baselines under explicit (a) and implicit (b) contamination scenarios.

As shown in the figures, CDD achieves relative improvements of 21.8% to 30.2% over existing baselines in Accuracy and AUC. Furthermore, TED successfully reduced performance inflation by up to 66.9%. Analysis of ChatGPT revealed a "Leak Ratio" of approximately 41.5% on HumanEval, evidenced by its significantly lower performance on the rephrased HumanEval_R benchmark.

Conclusion

CDD and TED provide powerful, model-agnostic tools for ensuring the integrity of LLM evaluations. While the current study focuses on code and logic, and acknowledges the computational cost of high-frequency sampling, it sets a new standard for identifying memorization in the age of massive, opaque training sets. Future work will focus on optimizing sampling efficiency and expanding these techniques to broader NLP domains.

Summary updated

BibTeX
@inproceedings{dong2024generalization,
  author = {Yihong Dong and Xue Jiang and Huanyu Liu and Zhi Jin and Bin Gu and Mengfei Yang and Ge Li},
  title = {{Generalization or Memorization: Data Contamination and Trustworthy Evaluation for Large Language Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.716},
}
Figure