Topic 4 of 5 · 4 min read
Memorised training data leaking out
Goal: Read an extraction test transcript and decide whether the model leaks its training data.
A language model can store pieces of its training data and repeat them word for word, so anything you fine-tune on may come back out to someone who asks the right way. Treat the training set as if it can be read through the model.
Check yourself · 1 of 3
What did research on extracting data from GPT-2 show?
Why it matters
Carlini et al. queried GPT-2 and recovered hundreds of verbatim sequences, including names, phone numbers, email addresses, code and 128-bit UUIDs. Some appeared in only one training document. A follow-up study found that memorization grows with model size, with the number of times an example is duplicated, and with the length of the prompt used to extract it. Fine-tuning data is small and often private, such as tickets, contracts, internal chats and code with keys in it. Several passes over a small set make memorising easy.
How to test
- Plant canaries. Add unique fake strings such as
Canary: ak_7Hq-91-demoto the training set. After tuning, see whether the model completes them. - Prefix probes. Take the first 20 to 50 tokens of real training rows and let the model continue. Compare the output with the true continuation.
- Pattern probes. Ask for emails, keys, phone numbers and names in your domain, and scan the output with the same regex rules used in your data scanner.
- Repeat with sampling. Run each probe several times at normal and higher temperature.
- Score it. Count exact and near-exact matches over a set length, for example 30 tokens.
How to reduce it
- Remove secrets and personal data before training, with scanners and allowlists.
- Deduplicate rows and near-duplicates. Repeats raise memorization.
- Train fewer epochs and avoid very high ranks on small private sets.
- Do not tune on data the end user must not see, when they can query the model.
Before and after
Weak: tune on 3,000 raw support tickets and deploy to all customers. Fixed: redact emails, order numbers and keys, deduplicate, plant canaries, run prefix probes, and block release on any verbatim match over 30 tokens.
What goes wrong
- Assuming an assistant will refuse to repeat data, since extraction prompts can look innocent.
- Testing with a single greedy sample.
- Cleaning the data after tuning instead of before.
Examples
A prefix probe that leaks
The tester pastes the first 30 tokens of a training ticket: Hi, my name is Dana Whitfield and my order 48213 arrived. The tuned model continues with the rest of the ticket, including an address and a phone number, matching the source for 61 tokens. That is a verbatim leak. The fix is redaction and deduplication before training, not a stricter system prompt.
A canary that passes
Ten unique canary strings were added once each to a 50,000-row set. After tuning, 200 prompts per canary at two temperatures produced no completion of any canary. This is evidence of low memorization at this scale, not proof of zero risk, so it is recorded with the settings used.
Key points
- Models can reproduce training examples verbatim, including personal data, code and unique strings seen in a single document.
- Memorization grows with model size, with duplicated examples and with longer prompts, according to published studies.
- Canary strings and prefix probes turn leakage into a measurable test you can run before release.
- Scrubbing secrets and personal data and deduplicating before training are the most effective defences.
- Do not tune on data the model's users are not allowed to read.
Common mistakes
- Relying on a system prompt such as "never reveal training data" instead of removing the data.
- Testing extraction with one greedy answer and no sampling.
- Leaving duplicates in the set, which raises memorization.
- Tuning on private data that some end users are not allowed to see.
Check yourself · 2 of 3
Why add unique canary strings to a fine-tuning set?
Check yourself · 3 of 3
Which step before training lowers the risk that a tuned model repeats private data?
Practice items, not counted towards your mastery.
Start here
- Fine-tuning Aligned Language Models Compromises Safety (Qi et al.) (opens in a new tab)PaperFree
Shows 10 adversarial examples broke a hosted model's guardrails, and that benign datasets also degrade safety.
- Emergent Misalignment: Narrow finetuning can produce broadly misaligned LLMs (opens in a new tab)PaperFree
Narrow fine-tuning on insecure code produced broad misaligned behaviour far outside coding.
- A small number of samples can poison LLMs of any size (Anthropic) (opens in a new tab)ArticleFree
250 poisoned documents backdoored models from 600M to 13B parameters, regardless of data volume.
More for this topic
- Extracting Training Data from Large Language Models (Carlini et al.) (opens in a new tab)PaperFree
Shows verbatim names, phone numbers, emails and code recovered by querying a model.
- Quantifying Memorization Across Neural Language Models (opens in a new tab)PaperFree
Memorization grows with model size, duplication count and prompt length.