Test Set Leakage in LLMs: How to Detect and Prevent Inflated Benchmark Scores

    Benchmark scores for large language models can be misleading when test questions leak into training data. This article explains why test set leakage happens, how to detect whether a model is merely reciting memorized answers, how to decontaminate training data using n-gram matching and MinHash/LSH deduplication, how to evaluate models with perplexity checks and perturbation tests, and how enterprises can build private, dynamic benchmarks to avoid choosing models that score high but perform poorly in real scenarios.

    Introduction: Why Benchmark Scores Get Inflated

    When a large language model is released, its developers typically publish a set of benchmark scores. These scores make cross-model comparison easy, but only if the test questions never appeared in the model’s training data. If the model has already seen the questions and their reference answers, the score measures memorization rather than problem-solving ability. This problem is known as test set leakage, or data contamination.

    1. How LLMs Are Trained and Where Leakage Comes From

    Large language models generally go through three stages:

    1. Pre-training: The model reads massive volumes of web pages, books, forum discussions, and open-source code to produce a base model. This stage learns the statistical patterns of language and knowledge.
    2. Post-training: Through supervised fine-tuning (SFT) and reinforcement learning from human feedback (RLHF), the model learns to follow instructions, write code, and perform reasoning tasks.
    3. Evaluation: The team scores the model using public, standardized test sets.

    The root cause of leakage lies in the public test sets themselves. Once benchmark questions and reference answers are published on the internet, web crawlers may scrape them. Teams assembling instruction-tuning data may also mix them into the training set. As a result, the model may have encountered the exam questions during training.

    2. How to Tell Whether a Model Is “Reciting”

    There have been reports that a certain code model could reproduce most test questions and their reference answers verbatim, and that its score dropped noticeably once those questions were excluded. Such phenomena deserve attention, but this article does not cite the specific figures. The reason is that the model versions, test sets, sampling parameters, and judging criteria in those tests were not disclosed, making the results impossible for outside parties to reproduce.

    To make a reliable judgment, “recitation” must first be defined. One workable standard is:

    • Use the first several characters of a question as the prompt, with no additional instructions.
    • Let the model continue the text and compare its output against the reference original, character by character.
    • If the character-level overlap between the continuation and the original exceeds a set threshold (for example, 90%), count it as one recitation.

    For sampling, use greedy decoding with temperature set to 0 and a fixed prompt template, so that results can be repeatedly verified under identical conditions.

    As long as the judging criteria are clearly stated, “the score after excluding recited questions” is a useful reference metric. However, it remains an estimate. Some questions may have been solved correctly through reasoning and merely happen to resemble the original text; excluding them would be a misjudgment.

    3. On the Training Side: Clean Data at the Source

    Before training data enters the model, text that heavily overlaps with evaluation questions should be removed. Common practices include:

    1. Extract n-grams. The GPT-3 paper used 13-grams for overlap detection, which serves as a reasonable starting point.
    2. Exact matching: If any 13-gram in the training corpus is identical to one from an evaluation question, flag that document.
    3. Near-deduplication: Use MinHash with locality-sensitive hashing (LSH) to find paraphrased or slightly modified duplicates, set a Jaccard similarity threshold (for example, 0.8), and adjust it based on sampling results.
    4. Manual review: Sample the flagged documents to estimate the false-positive rate, and record the IDs of removed documents for later auditing.

    There is no universally fixed threshold. Teams need to calibrate repeatedly against a small batch of data confirmed to be clean.

    4. On the Evaluation Side: Detecting Whether the Model Has Seen the Questions

    When training-data cleaning is incomplete, detection is still possible at the evaluation stage. Two methods are commonly used.

    The first is perplexity-based detection. For each test question, compute the model’s average cross-entropy loss on the question text, or compute perplexity directly. This requires token-level logits and length normalization by token count. If the loss on a particular question is significantly lower than on comparable new questions, the model may have seen it before. Closed-source APIs do not necessarily return logprobs, so this method requires the model service to expose the appropriate interface.

    The second is perturbation testing. Keep the logic of a question unchanged while modifying variable names, background descriptions, or example values, then compare scores before and after the perturbation. A sharp drop in score suggests the model relies on the surface form of the original question rather than on generalizable problem-solving ability.

    Both methods require statistical testing. For example, compute the score difference before and after perturbation for each question, then use a paired test (such as the Wilcoxon signed-rank test) to determine whether the difference is significant. The result of a single question is not enough to draw a conclusion.

    5. For Enterprises: Build Your Own Evaluation System

    For enterprise users, the most reliable approach is to use a private evaluation set that closely reflects their own business. The following principles are recommended:

    • Keep questions confidential, and never let them enter any training or fine-tuning data.
    • Add new questions regularly, prioritizing real business samples generated after the model’s release.
    • For coding tasks, use scripts to generate variants with different inputs but the same assessment points, and score them automatically with unit tests. Generated questions need manual spot-checking to avoid incorrect reference answers.
    • When reporting results, provide the mean and variance across multiple runs, and record the model version, prompt template, and sampling parameters.

    Relying on a single public leaderboard makes it easy to mistake “has seen the questions” for “can solve the questions.” Only private, dynamic, reproducible evaluation can reveal how a model performs in real-world scenarios.

    Conclusion

    Test set leakage strips public scores of their reference value. Rigorous deduplication on the training side, perplexity and perturbation testing on the evaluation side, and private dynamic benchmarks on the enterprise side must work together to reduce the risk of selecting a model that scores high but performs poorly. Whether a model can truly solve problems ultimately depends on whether it can answer questions it has never seen, consistently and reliably.