Telling Memorization from Domain Learning in Contamination Audits of Specialized Language Models

Models that are further trained on law, medicine or finance are usually evaluated on benchmarks built from the same public sources they were trained on: court filings, contract databases, PubMed abstracts. Checking whether a benchmark score reflects skill or a leaked test set therefore matters most in these domains. It is also where the standard tests are least trustworthy. The best tests that use only the model itself flag a passage as "seen during training" when its tokens are unusually probable. Domain training makes domain text unusually probable whether or not the specific passage was seen. This effect is concentrated in words the domain uses in a technical sense, such as "consideration" in contracts or "expression" in biology. Measuring meaning shift is exactly what lexical semantic change detection does: it compares how a word's typical contexts differ between two bodies of text.

We propose to measure this confound directly and to correct for it. First, we build domain-trained models with test items injected at known rates, and we test whether false alarms on never-seen domain items rise with the share of words used in their domain sense. Second, we calibrate each token's membership score against how the same word, in the same sense, scores in text the model provably never saw. The sense-matched reference text is itself screened with a second semantic-change test, so that meaning drift after the training cutoff does not create spurious "unseen" signals. The two-sentence version: domain learning looks like memorization to current detectors, and the look-alike is concentrated in domain-shifted word senses. Comparing each word-sense against its own behavior on unseen domain text should remove the look-alike while keeping the real memorization signal.

Core Claim

Reference-free membership detectors are systematically miscalibrated on domain-adapted models in a measurable way. On test items the model never saw, the detector score should increase with the density of tokens used in domain-specific senses. This is the "false member" problem. Separately, for temporally split evaluations, items using senses that emerged after the cutoff should score as spuriously unseen. This is the "false non-member" problem.

Both claims are testable before any fix is proposed. If they hold, a calibration that conditions on word sense, rather than only on position or on the whole document, should restore detection quality on domain models. Meeting this standard means close to the AUROC that the same detector achieves on a general-domain model with the same injection rate. If the claims do not hold, the existing detectors are adequate for domain audits, and showing that is itself a useful result.

Grounding in Prior Work

The motivating evidence comes from three places. First, Min-K%++ shows that maximum-likelihood training pushes training sequences toward local maxima of the next-token distribution. It turns each token's log-probability into a z-score against the whole vocabulary at that position, and reports gains of 6.2% to 10.5% AUROC over the runner-up on WikiMIA. That normalization runs across the vocabulary at one position. It cannot tell apart a token that is a local maximum because the passage was memorized from one that is a local maximum because the model learned the domain's usage of the word. Its predecessor, MIN-K% PROB, which averages the lowest-probability tokens, has the same blind spot.

Second, Su et al. cluster contextual embeddings of words across time slices and score shift with Jensen-Shannon divergence. They find that roughly 10% of vocabulary shifts substantially and accounts for a disproportionate share of model degradation. We reuse their clustering-and-divergence machinery, but point it at detector calibration rather than at choosing which tokens to mask during training.

Third, A Wind of Change showed that meaning shift between a general and a specialized corpus (German general text versus cooking text, the SURel benchmark) is detectable and correlates well with human judgments. This supports treating domain sense shift as a measurable, word-level quantity.

Other work constrains the design. Jiang et al. and their companion study pretrained GPT-2 models with deliberately injected test data. Three of their findings shape our setup:

  • Injecting prompt-plus-answer pairs inflates scores far more than injecting inputs alone.
  • Gains peak around 10 repetitions.
  • N-gram filtering both misses influential contamination and deletes clean text.

We adopt their injection protocol and repetition range, and we treat n-gram filtering as a weak reference point rather than a competitor. The Data Contamination Quiz and CAP detect contamination by perturbing items with synonyms or paraphrases. In technical registers, a synonym swap such as "indemnity" to "compensation" changes the meaning. A model's sensitivity to the swap can therefore reflect domain competence rather than rote recall. This is why we focus on likelihood-based detection, and why we report the perturbation methods with that caveat attached. CAP's finding that fine-tuned descendants inherit contamination from their base models also tells us that auditing the domain-trained base is the right level.

The stakes come from the domain side. SaulLM continued pretraining on 520B legal tokens, including EDGAR and FreeLaw, and reports 75.34% balanced accuracy on LegalBench-Instruct versus 73.35% for GPT-4. LegalBench itself draws tasks from sources such as CUAD and MAUD. PubMedQA turns PubMed article titles into questions and abstract conclusions into answers, which is ground-truth exposure for any model trained on PubMed. ClinicBench found that on drugs approved after training cutoffs, nearly half of the evaluated clinical models did worse than random guessing. That result is consistent with exam scores being propped up by exposure. None of these papers audits membership in the domain model.

Research Program

Sense inventory. For every word type in a benchmark's vocabulary, we collect usages from a general corpus and from the domain corpus. We encode them with hidden states from the model before domain training and cluster the usages per word, following Su et al. Each cluster gets a domain ratio, and clusters dominated by domain-corpus usages are marked as domain senses. Every token occurrence in a benchmark item is then assigned to its nearest cluster. This gives each item a domain-sense density.

We validate the procedure on SURel. Our word-level divergence must reach a Spearman correlation with human rankings comparable to the static-embedding baseline before we trust it in the legal and biomedical domains. That baseline is SGNS + OP+, i.e. skip-gram vectors aligned with mean-centered orthogonal Procrustes, at ρ = 0.851 in A Wind of Change. Given SemEval-2020's finding that static vectors beat BERT (SemEval-2020 Task 1), we keep SGNS + OP+ as a fallback word-level signal if contextual clusters underperform.

Sense-conditioned calibration. Let $s_t$ be the Min-K%++ score of token $t$, where word $w$ is used in sense cluster $c$. Let $m_{w,c}$ and $v_{w,c}$ be the mean and standard deviation of $s$ over usages of $w$ in sense $c$ in a reference set of domain text the model has not seen. The calibrated token score is

$$\tilde{s}_t = \frac{s_t - m_{w,c}}{v_{w,c}},$$

and the item score is the mean of the lowest $k\%$ of $\tilde{s}_t$, as in Min-K%++. For word-senses with too few reference usages, we back off to word-level and then to position-level statistics.

Reference set.

  • In the controlled experiments, the reference set is a held-out split of the domain corpus.
  • In real audits, it must come from domain documents published after the model's cutoff, for example FreeLaw opinions or PubMed abstracts.
  • Diachronic screening: post-cutoff reference text is screened with a second semantic-change test on the same words before versus after the cutoff. Words whose sense distribution shifted over time are removed from the reference statistics. Otherwise genuine diachronic drift would make post-cutoff usages look anomalously improbable and bias the reference set.

Controlled testbed. We continue pretraining an open base model at the scale used by Jiang et al. (GPT-2 Large) and at roughly 1B parameters, under two domain settings:

  • Biomedical: about 3B tokens of PubMed abstracts with PubMedQA PQA-L items injected.
  • Legal: a FreeLaw and EDGAR subset with items from CUAD- and MAUD-derived LegalBench tasks injected.

Injection is at 0, 1, 3 and 10 repetitions, in input-only and input-plus-answer forms. Half of each benchmark's items are injected; the other half are guaranteed unseen. A matched general-domain run, which injects the same items into a general web corpus, separates the effect of domain training from the effect of injection.

Baselines

The naive reference points are two. The first is n-gram overlap: we flag an item if any 13-gram appears in the training corpus. This is only computable in the controlled setting, and we expect it to be weak given Jiang et al. The second is a model-free text classifier, logistic regression on bag-of-words features, trained to separate member from non-member items. If it does well, the membership split is confounded by surface distribution differences and no likelihood-based result on that split can be trusted. In the controlled setting the members are a random half, so this classifier should sit at chance. In real temporally split audits it is the key sanity check.

The strongest existing method is Min-K%++ run directly on the domain model. Its reported result is a 6.2% to 10.5% AUROC gain over the runner-up on WikiMIA, averaged over five models, and parity with reference-based methods on MIMIR. No absolute AUROC is reported in the file, and no reported result was found on Lacuna for Min-K%++ on domain-continued-pretrained models or on PubMedQA or LegalBench membership. We will therefore establish its numbers ourselves. MIN-K% PROB and raw perplexity run alongside it as the lineage it improves upon.

The strongest reference-based competitor scores the item as the difference between the domain model's Min-K%++ score and the pre-domain base model's score. This removes general fluency but not domain learning.

The ablations isolate the key ingredient. Each one uses the same reference text, token budget and choice of $k$, tuned on the same validation split with an identical grid:

  • document-level calibration, which subtracts the mean item score on unseen domain text;
  • word-level calibration, which conditions on $w$ but not on sense $c$;
  • sense-level calibration without diachronic screening;
  • the full method.

Beating Min-K%++ means a higher AUROC and true-positive rate at 5% false-positive rate on the domain model, averaged over seeds, with non-overlapping bootstrap intervals. The headline criterion is that, among never-seen items, the gap between high and low domain-sense-density items shrinks to near zero.

Why not just…?

Why not just use the pre-domain checkpoint as a reference model? This difference score removes the likelihood that general pretraining gives to fluent English. But domain training raises likelihood on all domain text, seen or unseen, so the difference should still rise with domain-sense density among never-seen items. This is a direct prediction. If the difference score shows no such slope in the controlled testbed, it is sufficient, and we will report that it matches our method.

Why not just calibrate per document against unseen domain text, without any word-sense machinery? This is the most serious threat. If domain lift were uniform across tokens, subtracting a domain-wide mean would suffice. Our hypothesis is that the lift is concentrated in shifted senses, which vary in density from item to item, so a single offset will over-correct some items and under-correct others. The document-level and word-level ablations settle this. If word-level calibration matches sense-level, we drop the clustering and recommend the simpler word-conditioned version. Polysemous words like "consideration", which appear in both senses within domain text, are where sense conditioning has to earn its keep, and we report results on that subset separately.

Why not just use perturbation-based black-box tests like the Data Contamination Quiz or CAP? These need no log-probabilities, which is a real advantage for closed models. However, their premise that synonym swaps preserve meaning fails in exactly the registers at issue. We run both on the controlled models and measure how often domain-expert-rated perturbations change an item's correct answer. We expect their false-positive rate on never-seen items to also rise with domain-sense density. If it does not, they become the recommended tool for closed models.

Why not just deduplicate with n-grams before domain training? Jiang et al. found that n-gram filtering left inflated scores in place while deleting clean text. Yao et al. found that translated benchmarks raised MathQA from 42.01% to over 95% with no n-gram flags. Filtering also does nothing for auditing models whose corpora are not public.

Proposed Experiments and Decisive Checks

First check: does the confound exist? On the controlled models, we plot Min-K%++ scores for never-seen items against domain-sense density. We do this for the domain model and for the matched general model. A positive slope on the domain model and a flat one on the general model confirm the confound. A flat slope on both refutes the premise, and we would report it as such.

Second check: does detection recover? We report AUROC and true-positive rate at 5% false-positive rate for all baselines and ablations:

  • across repetition levels 1, 3 and 10, and across input-only versus input-plus-answer injection;
  • with the estimated contamination rate compared against the known 50% injection.

We also measure the accuracy inflation each injection level produces on PubMedQA and LegalBench, using Jiang et al.'s protocol. This shows which levels matter for scores.

Third check: the diachronic false-non-member effect. We build a temporally split variant of each domain benchmark from pre- and post-cutoff documents. We test whether post-cutoff items rich in diachronically shifted senses receive spuriously "unseen" scores, and whether screening the reference set removes the effect.

Real audits. Only after these checks do we audit open-weight domain models: SaulLM where weights are available, and Meditron or PMC-LLaMA on PubMedQA, MedQA and ClinicBench (via the ClinicBench repository). Each audit reports per-task estimated contamination with and without sense calibration, alongside the model-free text classifier's accuracy on the same split.

The outcome that would most change practice is a set of LegalBench or PubMedQA tasks that uncalibrated Min-K%++ flags as contaminated but that clear under sense calibration, or the reverse.