Counterfactual memorization in neural language modelsCounterfactual Memorization in Neural Language Models
The authors propose a counterfactual memorization metric, estimated by training 400 models on three text datasets, and claim it can distinguish rare from common memorization and trace the source of predictions.
- Language models memorize training data, but existing extraction methods and memorization measures are strongly correlated with a sample's occurrence count in the training set, making it difficult to distinguish memorization of common text from that of rare information.
- The authors extend Feldman (2020)'s definition of label memorization to language models: comparing the expected difference in model performance when the same document appears versus does not appear in the training set, and empirically estimate it by training 400 models on 25% subsets for each of three datasets.
- The authors report that rare memorized samples exist in all three datasets; in RealNews, the Pearson correlation between repetition count and counterfactual memorization is -0.39; high-influence train-validation pairs are mostly near-duplicate text; the deduplicated dataset C4-NEARDUP shows no clear difference in memorization distribution from C4.
- The authors note that the study is limited to English datasets, that the model and training-set scale are several orders of magnitude smaller than GPT-3 and others, and that the analysis of training dynamics is only preliminary; the experiments use a T5-base-level model with about 112M parameters and the first 2^21 documents of each dataset.
- Evaluated models
- T5-base (decoder-only)
- Benchmarks
- RealNewsC4Wiki40B:enC4-NEARDUP
- Metrics
- counterfactual memorizationcounterfactual influenceper-token accuracySpearman's RPearson correlation
Researchers propose the concept of counterfactual memorization, which characterizes the degree to which a document is memorized by the change in model predictions when that document is omitted during training, and use it to study the risk of language models memorizing sensitive information in training data. Most previous memorization metrics are strongly correlated with the number of times a sample appears in the training set, capturing repeated content such as common phrases, public knowledge, and template text; how to filter out such common memorization was an unsolved problem in prior research. The paper identifies counterfactually memorized samples on standard text datasets and estimates the influence of each memorized training sample on the validation set and generated text, thereby providing direct evidence of the source of memorization at test time.
Paper analysis
What problem does this paper attempt to solve?
How to distinguish language models' memorization of common text from that of rare information; the authors propose a counterfactual memorization measure.
Core question: how to filter out "common" memorization and identify language models' memorization of rare, isolated training information.
- Problem setting: the authors note that modern neural language models may memorize sensitive user information or copyrighted content in training data, raising privacy and copyright concerns in real-world applications.
- Shortcomings of existing methods: the authors state that prior extraction attacks mainly identify strings that are common and frequent in the training set; Lee et al. [2021]'s analysis shows near-duplicate samples account for most memorized content, and prior work could only use heuristic rules to distinguish memorization of high-frequency sequences from that of isolated information.
- Core observation: drawing on the distinction in psychology between episodic memory and semantic memory, the authors argue that we want models to acquire semantic memory and avoid episodic memory; deleting a text that is common across many documents has little effect on model predictions, so "whether deleting that document changes the prediction" can characterize memorization of rare information.
- What the paper proposes: the authors extend Feldman [2020]'s definition of label memorization for classification models to neural language models, proposing counterfactual memorization, and further propose counterfactual influence for tracing the information sources of model predictions; they conduct empirical analyses on three standard text datasets: RealNews, C4, and Wiki40B:en.
What related research exists?
Related work covers training data extraction and memorization measures, influence estimation methods, and leave-one-out ideas; the authors state that this paper provides a principled perspective.
Training Data Extraction and Memorization Measures
- Carlini et al. [2020] and Ziegler [2021] analyzed language models' memorization of sensitive information in training data (such as phone numbers); Carlini et al. [2019], Henderson et al. [2017], Thakkar et al. [2020], and Thomas et al. [2020] studied memorization using synthetically injected "canaries."
- Lee et al. [2021] found that near-duplicate samples are very common in standard text corpora and that common phrases account for most memorized text; the paper notes that prior work used various heuristic rules to distinguish "common" from "rare" memorization.
- Carlini et al. [2022], Kandpal et al. [2022], and others use the "generation-time memorization" definition, measuring memorization by text overlap between generated text and training documents; the paper notes that such measures are strongly correlated with occurrence count and compares them with this paper's measure in Section 5.
Causal Estimation of Memorization and Influence
- Feldman [2020] proposed a definition of label memorization in classification models, and Feldman and Zhang [2020] conducted an empirical study in computer vision; this paper's mathematical formulation is borrowed from Feldman [2020] and adapted to language models.
- The datamodel of Ilyas et al. [2022] can predict model outputs after training on a specific training subset, but the paper notes that this method requires training a large number of models (e.g., 300,000 on CIFAR-10), which is computationally infeasible for language models at this paper's scale.
Influence Functions and Data Attribution
- Koh and Liang [2017] and Koh et al. [2019] applied influence functions to analyze neural network predictions; the paper notes that this estimator has been found to be computationally expensive and fragile [Basu et al., 2021].
- Pruthi et al. [2020] estimate training-sample influence by tracking gradient updates during training; Elazar et al. [2022] use data statistics such as co-occurrence counts (without model retraining) to infer causal effects on language model predictions.
Leave-One-Out and Related Ideas
- The paper mentions the connection between cross-validation, leave-one-out stability, and generalization [Mukherjee et al., 2006], and the worst-case difference between "adjacent datasets" in differential privacy [Dwork et al., 2014]; the paper notes that these works mostly pursue aggregate measures, whereas this paper characterizes the behavior of individual samples.
Positioning: the authors state that this paper directly formalizes counterfactual influence using subset sampling (rather than leave-one-out), extends the estimation to generated text, and provides a principled perspective for distinguishing "common" from "rare" memorization.
How does the paper address this problem?
Using 400 models trained on 25% random subsets, compare the per-token accuracy difference for samples when in versus out of the training set.
Overall approach: define "memorization" as a causal quantity—the expected difference in the model's performance on a document depending on whether that document appears in the training set—characterized by counterfactual memorization; then generalize it to counterfactual influence, measuring the influence of one training sample on another sample's prediction.
Definition of Counterfactual Memorization
- Given a training algorithm A, a dataset D, and a performance measure M, the counterfactual memorization of training sample x is
mem(x) \triangleq E_{S\subset D, x\in S}[M(A(S), x)] - E_{S\subset D, x\notin S}[M(A(S), x)], i.e., the difference in expected performance on x between models trained on subsets containing x and models trained on subsets not containing x. - Throughout the paper, M is per-token accuracy: given the true prefix, predict the next token, and average the 0-1 loss of the argmax prediction.
Empirical Estimation Procedure
- Train m models, each on an independently sampled equal-sized subset S_i (|S_i| = r|D|); for each x, divide the models into an IN group (x ∈ S_i) and an OUT group (x ∉ S_i), average performance in each, and subtract.
- The same set of m models can be reused for estimating all samples, with no need to retrain for each sample.
- Experimental setup: m = 400, r = 0.25; a hash-based filtering mechanism approximates random subsampling in practice (Appendix G), and Figure 11 verifies its consistency with numpy.random.choice.
Counterfactual Influence
- Defined as
infl(x \Rightarrow x') \triangleq E_{S\subset D, x\in S}[M(A(S), x')] - E_{S\subset D, x\notin S}[M(A(S), x')], where x' can be a validation-set sample, a test-set sample, or generated text; mem(x) = infl(x ⇒ x), i.e., memorization is self-influence. - Empirical estimation is the same as for memorization, reusing the same set of models; the authors use it to trace the information sources of validation-set predictions and generated text.
Model and Training Configuration
- The model is a decoder-only T5-base-level Transformer with about 112M parameters; the first 2^21 documents of each dataset are taken as the training set.
- Each model is trained for 60 epochs with the Adam optimizer, learning rate 0.1, and weight decay 10^-5; the authors explain that because the subsets are small, more epochs are needed for the model to fit sufficiently to study memorization.
- Near-duplicate detection uses MinHash [Broder, 1997], with normalized edit similarity greater than 0.7 treated as duplicate (definition in Appendix I).
Analysis Methods
- Visualize the memorization distribution with a two-dimensional histogram (memorization score × "simplicity", i.e., the sum of IN/OUT accuracy); analyze memorization profiles of RealNews and C4 by domain.
- Assess the sensitivity of the estimate to m by partitioning the 400 models into multiple m-model subsets and computing Spearman's R between subsets.
- Given a training algorithm A, a dataset D, and a performance measure M, the counterfactual memorization of training sample x is
What experiments did the paper conduct?
Train 400 models on each of three datasets to estimate the memorization distribution, and analyze repetition count, training epochs, domain and test-time influence.
Experimental Setup
- Model under test: decoder-only T5-base-level Transformer, about 112M parameters; 400 models trained per dataset, each on a 25% random subset.
- Datasets: RealNews, C4, Wiki40B:en, taking the first 2^21 documents of each; Appendix C additionally compares against deduplicated C4-NEARDUP.
- Metrics: counterfactual memorization (difference in per-token accuracy between IN and OUT models), counterfactual influence, Spearman's R, Pearson correlation.
- Training details: 60 epochs, Adam, learning rate 0.1, weight decay 10^-5; C4/RealNews/Wiki40B:en models converge to training-set average per-token accuracy of 44.21%/47.59%/66.35%, validation set 27.90%/31.09%/49.55%; overfitting begins around epoch 5.
- Generated-text analysis: uses the 24,576 generated texts publicly released by Grover-Mega (p=0.96) on RealNews.
- Number of repetitions: in the sensitivity analysis, the 400 models are partitioned into up to 10 m-model partitions (m from 6 to 192).
Main Results
The paper has no aggregated numerical main table; the main results are spread across Figure 1–4 and Table 1–2:
Result Value/phenomenon Source Highest-memorization RealNews sample mem = 0.6546 (all-uppercase text) Table 1 RealNews near-duplicate sample pair mem = 0.0361 and 0.0356 (templated options coverage) Table 1 Correlation of repetition count with memorization Pearson = -0.39 (about 38,000 near-duplicate samples) Section 5 Memorization grows with training 59% of samples' memorization keeps rising; 85% never exceed 0.2; 0.5% never exceed 0.1 Section 4.3 Highest-influence train-validation pair infl = 0.3780 (texts nearly identical) Table 2 - The authors state that high-memorization samples are mostly unconventional text (all-uppercase, structured formats such as tables, multilingual text), medium-to-high-memorization samples are mostly news reports of specific events, and templated documents with many near-duplicates have low memorization (Table 1).
- Figure 1 shows simple samples have low memorization, peak memorization occurs at medium simplicity, and the hardest samples also have low memorization; the memorization histograms of the three datasets are broadly similar in shape, with Wiki40B:en's range slightly compressed.
- The authors state that counterfactual memorization and generation-time memorization measure different types of memorization: the latter is strongly correlated with occurrence count, while the former automatically becomes smaller when there are many repetitions (Section 5).
Domain-Level Memorization Profiles
- What was measured: for RealNews and C4, the relationship between 95th-percentile memorization score and document count by domain (Figure 2a, 2b), plus distributions for representative domains (Figure 2c, 2d).
- Results: large domains with many documents have smaller variance in 95th-percentile values, while small domains vary widely; in RealNews, reuters.com has the most documents but low average memorization, digitallibrary.un.org has high memorization, zap2it.com (TV listings) has high memorization, and hotair.com's memorization distribution is low; in C4, blogspot.com has many documents and medium memorization, zh.wikipedia.org and buckinghamautos.com.au have high memorization, and a certain postcode-template website has very low memorization.
- Authors' interpretation: the authors believe low-frequency tokens such as foreign languages and all-uppercase text, and flattened structured text, tend to cause high memorization; hotair.com often quotes other news, and the authors suspect repeated text causes its lower memorization.
Test-Time Influence Analysis
- Validation-set influence: Figure 4a shows random validation samples receive influence close to zero from all training samples, while high/medium-influence samples each have one to a few strong influence sources; Figure 4b shows large influence generally requires the training sample itself to have high memorization, but samples with memorization above 0.4 have lower maximum influence instead, which the authors suggest may be because many high-memorization samples are low-quality text.
- What influence pairs contain: Table 2 shows the highest-influence pairs are nearly identical (only surface differences such as quotation marks and dashes), medium-influence pairs are mostly different reports of the same event, and low-influence pairs are mostly templated text or shared prefixes/common-sense substrings; pairs with influence below 0.02 have no perceptible relationship.
- Generated-text influence: the histogram of maximum influence for Grover-Mega generated texts (Appendix Figure 10) decays faster and has half the range of the validation set; the authors give two reasons: only 24,576 public generated texts exist (prior work generated 100,000+), and Grover was trained on the full RealNews while this paper analyzes only the first 2M documents.
Other Ablations and Analyses
- Number of models m: Figure 3a shows that with 96 models, the between-partition Spearman's R begins to approach 1; Appendix Figure 8 shows that with 192 models, Spearman's R with the 400-model result is at least 0.992; Figure 9 shows that the variance of memorization scores decreases as m increases.
- Training epochs: Figure 3b, 3c show total memorization and the proportion of high-memorization samples grow with epochs; the authors state they did not observe samples whose memorization clearly decreased.
- Effect of deduplication: Appendix C compares the memorization distributions of C4 and C4-NEARDUP (Figure 7); the authors report no clear difference and suggest one possible reason is that the deduplication criterion is conservative, removing only about 3% of samples; the high-memorization tail is essentially unaffected by text deduplication.
- Logit-scaled measure: Appendix H replaces raw accuracy with logit(per-token accuracy); Spearman's ρ with the unscaled version is 0.947/0.903/0.944 (RealNews/C4/Wiki40B:en), and the paper uses the unscaled version throughout.
What are some points that can be further explored?
The authors note limitations to English, small model and data scale, and only preliminary analysis of training dynamics, and propose directions such as scaling up.
Limitations and future directions noted by the authors
- Language coverage: the study focuses mainly on English datasets; the authors believe new patterns may emerge in multilingual data or more structured domains such as programming languages (Section 7 Limitations).
- Scale: the language models and training sets used are several orders of magnitude smaller than modern standards such as GPT-3, GPT-4 and PaLM-2; the authors believe the framework needs to be extended to larger models and datasets (Section 7).
- Training dynamics: only a preliminary study of the dynamics of counterfactual memorization during training was conducted (Section 7).
- Semantic-level influence: currently high-influence pairs can usually be explained by high text overlap between training and test samples; the authors suspect stronger models may show strong influence between documents that are semantically similar but have no direct text overlap (Section 7).
- New datasets: the authors propose that a dataset of document pairs that are semantically similar but textually different needs to be constructed, one possible source being versioned Wikipedia articles with large time spans or edit distances (Section 7).
- Locating privacy risk: the authors note that the privacy risk of this analysis is low, because conducting the analysis requires already having access to the dataset and being able to train models (Section 7).
Scope of experiments
- The model tested is a roughly 112M-parameter decoder-only T5-base-level Transformer, with 400 models trained per dataset.
- The datasets are RealNews, C4 and Wiki40B:en, each taking the first 2^21 documents; Appendix C additionally compares C4-NEARDUP.
- The generated-text influence analysis uses the 24,576 generated texts publicly released by Grover-Mega (p=0.96), without generating texts themselves.
- The near-duplicate analysis covers about 38,000 samples in the RealNews training set that have at least one near-duplicate (out of 2.01M).
- The paper does not report the total compute or time for training 400 models, only stating that it ran on an internal cluster and that the main compute consumption was model training (Appendix F).
Summarize the main content of the paper
The authors propose counterfactual memorization and influence measures, identify rare memorized samples on three datasets, and trace prediction sources.
An analysis paper on language model memorization: the authors extend Feldman [2020]'s definition of label memorization to neural language models and propose counterfactual memorization—comparing the expected difference in model performance when a document appears versus does not appear in the training set, thereby distinguishing memorization of rare information from common text.
- Problem addressed: previous extraction attacks and generation-time memorization metrics are strongly correlated with sample occurrence counts, mainly capturing common phrases, public knowledge and template text, and require heuristic rules for filtering; the authors claim counterfactual memorization handles near-duplicates automatically without heuristics.
- Method highlights: on each dataset (RealNews, C4, Wiki40B:en, each taking the first 2^21 documents), train 400 T5-base-level models (each on a 25% random subset), estimating memorization using the per-token accuracy difference between IN/OUT models; further define counterfactual influence, measuring the influence of training samples on predictions for validation samples and Grover-Mega generated text.
- Main results: rare memorized samples exist in all three datasets, and high-memorization samples are mostly all-caps, structured or multilingual text (RealNews highest mem = 0.6546, Table 1); among RealNews near-duplicate samples, the Pearson correlation between repetition count and memorization is -0.39, opposite to the positive correlation with generation-time memorization; memorization grows with training epochs, and 85% of samples never exceed 0.2 memorization; the highest-influence training-validation pairs have nearly identical text (infl = 0.3780, Table 2); no clear difference is seen between the memorization distributions of C4 and deduplicated C4-NEARDUP.
- Authors' conclusions: the authors claim counterfactual influence can locate the source of information for test-time predictions, and that the observed near-duplicate training-validation pairs are consistent with recent research on internet corpus data contamination; the authors believe the framework needs to be extended to larger models and a dataset of document pairs that are semantically similar but textually different needs to be constructed.