Skip to content
mentoor

Topic 5 of 5 · 5 min read

Testing a model for training-data leakage

Goal: Design a pre-release test that inserts canaries into training data and measures whether the model reproduces them.

Before a model ships, test whether it leaks: plant fake secrets in the training data, try to get them back, and compare behavior on training and unseen text. A model that passes your scrubbing step can still repeat things you did not expect.

Check yourself · 1 of 3

What is a canary in leak testing?

Choose one answer

Why it matters

Scrubbing and DP reduce risk but do not prove anything about the finished model. Leak tests give evidence. They also give you a number to track from one version to the next, and a clear gate for release.

Three tests

  1. Canaries. Insert unique, fake secrets into the training data, for example canary-7f3a-pilot-9921 inside a realistic sentence. They must be random enough that the model cannot guess them. After training, prompt with the prefix and see if the model completes the secret. The Secret Sharer paper describes this and an exposure score that ranks how much more likely the model finds the canary than random guesses. Insert the same canary a different number of times (1, 10, 100) to see how repetition changes recall.
  2. Extraction prompts. Write prefixes that look like your data: "Dear customer, your account number is". Sample many completions at a few temperatures and search them for real training strings, for patterns such as emails and phone numbers, and for any of your canaries.
  3. Membership inference. Compare the model's loss on a sample of training records with its loss on similar held-out records. A big gap means the model treats training text differently and an attacker can exploit it.

A release gate

Decide the pass rule before you run: for example, no canary inserted once is reproduced, no verbatim span longer than a set length from training appears in extraction output, and the loss gap on a held-out set is below a stated limit. Run the test on every candidate model, and store results with the model version.

def canary_hit(model, prefix, secret, n=50):
    outs = [model.generate(prefix, temperature=0.8) for _ in range(n)]
    return sum(secret in o for o in outs) / n

What goes wrong

  • Canaries that are too guessable, such as "12345".
  • One greedy sample. Leaks often show up only across many samples.
  • Testing only the final model. Test the checkpoints you might ship.

Examples

A canary run

A team adds three canaries to a 5,000-row set: one inserted once, one 10 times and one 100 times. After fine-tuning, 50 samples per prefix show hits of 0, 3 and 41 out of 50. The result says what repetition does, and the team removes duplicates and retrains until the 10x canary also reads 0 hits.

Extraction sweep

Prefixes such as "Order confirmation for" and "Call me on" are sampled 200 times each. A script scans every output for emails, phone patterns and any 40-character span found in the training file. Any match fails the release.

Key points

  • Plant unique fake secrets in the training data and test whether the model completes them.
  • Insert canaries at different repeat counts to see how repetition changes recall.
  • Sample many completions from data-like prefixes and search them for training text and PII patterns.
  • Compare loss on training and held-out records to estimate membership-inference risk.
  • Fix the pass rule before testing and keep results with each model version.

Common mistakes

  • Using guessable canaries such as sequential numbers.
  • Testing with a single greedy output.
  • Deciding what counts as a pass after seeing the results.
  • Skipping the test because the data was scrubbed.

Check yourself · 2 of 3

Why sample many completions in an extraction test?

Choose one answer

Check yourself · 3 of 3

When should you set the pass rule for a leak test?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic

Where to go in your country