Memorization vs. Generalization: Quantifying Data Leakage in NLP Performance Evaluation

Aparna Elangovan, Jiayuan He, Karin Verspoor

TL;DR

Data leakage caused by overlapping training and test sets is artificially inflating performance metrics across popular NLP benchmarks, rewarding models for rote memorization rather than true generalization. By proposing a framework to quantify this overlap, the authors demonstrate that correcting for data leakage or evaluating models on low-overlap test instances leads to dramatic performance drops of over 10 F1 points.

What Problem Does This Paper Address?

When building machine learning models for Natural Language Processing (NLP), the standard practice is to evaluate generalizability using a held-out test set. However, if the test set contains sentences, phrases, or entities that closely mirror the training set, a model can score highly simply by acting as an exact-match lookup table.

This paper addresses the hidden issue of train-test data leakage in public NLP datasets. When datasets are split randomly without considering the broader context (like whether two sentences originated from the same source document), highly similar instances bleed across the split. As a result, researchers inadvertently measure a model's capacity to memorize rather than its ability to generalize to unseen, real-world data.

Examples of high train-test overlap across different NLP tasks

Methods

The authors introduce a straightforward framework to quantify data leakage and evaluate its impact on model performance:

  1. Overlap Quantification: They use a simple bag-of-words approach to measure text similarity. Every test instance is compared against the entire training set using cosine similarity across unigrams, bigrams, and trigrams (excluding stopwords).
  2. Stratified Test Splits: To see how similarity affects performance, they split test sets in two ways:
  3. Interval-based: Grouping test instances into fixed similarity threshold ranges (e.g., [0-0.25), [0.25-0.50), [0.50-0.75), [0.75-1.0]).
  4. Quartile-based: Dividing the test set into four equal-sized bins based on similarity ranking.
  5. Controlled Splitting: They compare standard random splitting against a stricter document-level unique split (where all sentences from a single source document are kept strictly within one split).

They evaluate these effects across multiple standard architectures, including BiLSTMs, Convolutional Residual Networks (ConvRes), and BERT/BioBERT.

Datasets

The study evaluates train-test overlap across five widely used public NLP benchmarks spanning three distinct tasks:

  • Relation Extraction (REL): AIMed (protein-protein interactions).
  • Named Entity Recognition (NER): BC2GM (BioCreative II gene mentions) and ChEMU (chemical reactions from patents).
  • Text Classification (CLS): BC3ACT (protein interaction classification) and SST2 (Stanford Sentiment Treebank).

For AIMed, the authors specifically contrast a standard random split (AIMed (R)) with their newly structured unique document split (AIMed (U)).

Key Insights and Ideas

  • The Illusion of Progress: High performance on popular benchmarks might be a mirage. In datasets like AIMed (R), unigram similarity between the train and test sets reaches a staggering 96.95%, meaning the test set is virtually identical to what the model has already seen.
  • Task-Dependent Fragility: Data leakage is particularly severe in labor-intensive, domain-specific tasks like biomedical NER and relation extraction. For instance, 70.77% of gene names in the BC2GM test set overlap with the training set, and 2,308 genes are exact matches.
  • Memorization vs. Generalization: When models are forced to evaluate on truly novel text (low-similarity intervals), their performance plummets. This indicates that state-of-the-art models rely heavily on sequence memorization rather than robust linguistic understanding.

Key Results

The quantitative impact of data leakage is stark across all tasks and models:

  • The Splitting Penalty: When switching from a random split (AIMed (R)) to a document-unique split (AIMed (U)), F1-scores across BiLSTM, ConvRes, and BioBERT dropped by more than 10 points due to the reduction in train-test overlap.
Performance drop when moving from random (R) to unique document (U) splits
  • Similarity-Driven Performance: As the similarity between the test instances and the training set increases, model performance increases predictably. For example, on the ChEMU dataset, BERT's F1-score climbs from 85.6 in the low-similarity interval (2I) to a near-perfect 96.7 in the highest-similarity interval (4I).
Table 2: Train-test similarity using unigrams (uni), bi- grams (bi), trigrams (tri). BC2GM and ChEMU are in BRAT standoff format and their similarities are shown for their text files (“text”) and annotation files (“ann”). Similarities beyond 60.0 are highlighed in bold.

Limitations and Future Work

The primary limitation acknowledged by the authors is their reliance on a simple bag-of-words approach for similarity measurement. While highly effective at catching literal text duplication, it fails to capture deeper semantic shifts. For example, in sentiment analysis, the phrases "good movie" and "it's still not a good movie" share high unigram overlap but possess completely opposite meanings.

The authors suggest that future work should incorporate more sophisticated Semantic Textual Similarity (STS) methods into dataset splitting workflows. However, they caution against a potential "chicken-and-egg" dilemma if machine learning models are used to evaluate the semantic similarity of data meant to train those very same models.

Summary updated

BibTeX
@inproceedings{elangovan2021memorization,
  author = {Aparna Elangovan and Jiayuan He and Karin Verspoor},
  title = {{Memorization vs. Generalization: Quantifying Data Leakage in NLP Performance Evaluation}},
  booktitle = {EACL},
  year = {2021},
  doi = {10.18653/v1/2021.eacl-main.113},
}
Figure