Start studying
Module 15 · AI Security Module contents
Module 15  ·  Card 8 / 16advanced

Membership Inference and Model Inversion

These are privacy attacks that pull training data back out of a trained model.

Membership inference asks whether one specific record was in the training set.

Model inversion is more ambitious and reconstructs features of the data itself.

Both exploit a model behaving more confidently on examples it has already seen.

Adding noise during training, returning labels instead of scores and rate limiting reduce the signal.

Learn in depth ↓
Module 15 · AI Security · 16 concepts
In depth  /  15 lines

Membership Inference and Model Inversion, in more detail

Membership inference and model inversion are privacy attacks aimed at the training data rather than the application.

They matter because a trained model is, in part, a lossy record of everything it was trained on.

Membership inference asks one narrow question, which is whether a particular record was in the training set.

That alone can be a serious disclosure when the dataset is a list of patients, defaulters or subscribers.

The attack works because models behave measurably differently on data they have already seen.

Confidence tends to run higher and loss lower on training examples than on genuinely new ones.

An attacker compares the model's response on a candidate record against that expected pattern.

Model inversion is more ambitious and tries to reconstruct the underlying data itself.

Given a label and enough queries, it can gradually recover features typical of that class.

Overfitted models leak considerably more than well-regularised ones, because they memorised more.

Small training sets and rare records are the most exposed, since the model effectively saw them as individuals.

Adding calibrated noise during training bounds how much any single record can influence the result.

Returning a label instead of a full confidence score removes most of the signal an attacker relies on.

Rate limiting matters as well, because both attacks need a great many queries to work at all.

Deduplicate and minimise what you collect, since data you never held cannot be recovered from your model.

Deep dive

What is underneath Membership Inference and Model Inversion

The model remembers, and the loss says so

L(xtrain)<L(xtest)\mathcal{L}(\mathbf{x}_{\mathrm{train}}) < \mathcal{L}(\mathbf{x}_{\mathrm{test}})

A model fits its training data better than anything else, and that gap is the whole attack surface.

member if L(x)<τ\text{member if } \mathcal{L}(\mathbf{x}) < \tau

Membership inference asks whether a specific record was in the training set, and the simplest version is a threshold on the loss.

advantage=P(correct∣member)−P(wrong∣non-member)\text{advantage} = P(\text{correct} \mid \text{member}) - P(\text{wrong} \mid \text{non-member})

The attack is only meaningful above chance, and it is measured as the true positive rate at a very low false positive rate rather than as an average accuracy.

Knowing that one person's record was used to train a medical model is a disclosure even when the record itself is never recovered.

Why overfitting is the direct cause

The wider the generalisation gap, the better the attack works.

A model whose training and test losses are equal leaks nothing through this channel, because there is no signal to threshold.

The stronger version trains copies of the model on known data, learns what a member's loss looks like, and applies that classifier to the target.

Duplicated records are the worst case. A sequence appearing many times in the corpus is memorised rather than learned, and it can be extracted verbatim.

Model inversion, which goes further

max⁡x  pθ(y=c∣x)−λ R(x)\max_{\mathbf{x}} \; p_{\theta}(y = c \mid \mathbf{x}) - \lambda \, \mathcal{R}(\mathbf{x})

Inversion optimises an input to maximise a class score, reconstructing a representative example of that class rather than testing a specific record.

On a face recognition model that produces a recognisable average face for a named person, from the weights alone.

For language models the equivalent is simpler: a prefix from the training data often causes the model to continue it verbatim, including keys, addresses and personal details.

One defence, in order

  1. Deduplicate the training corpus, which removes most of the memorisation at no accuracy cost.
  2. Scrub secrets and identifiers before training, not after.
  3. Regularise and stop early, so the generalisation gap stays small.
  4. Train with differential privacy if the data is genuinely sensitive.
  5. Test by attacking your own model, since the attacks are published and cheap to run.

Differential privacy, and what it costs

P(M(D)∈S)≤eε P(M(D′)∈S)+δP\big(M(D) \in S\big) \leq e^{\varepsilon} \, P\big(M(D') \in S\big) + \delta
  • D,D′D, D': datasets differing in one record.
  • ε\varepsilon: the privacy budget, smaller being stronger.

The guarantee is that the output distribution barely changes when any single record is added or removed, which bounds what any attack can learn about that record.

g←gmax⁡(1,∥g∥/C)+N(0,σ2C2I)\mathbf{g} \leftarrow \frac{\mathbf{g}}{\max(1, \|\mathbf{g}\|/C)} + \mathcal{N}(0, \sigma^2 C^2 I)

DP-SGD implements it by clipping each example's gradient and adding calibrated noise, so no single example can move the weights far.

ε≈1 to 10\varepsilon \approx 1 \text{ to } 10

The cost is accuracy and compute, and per-example gradient clipping is several times slower than ordinary training, which is why it is reserved for data that warrants it.

Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
What does a membership inference attack try to establish?
AI Security

16 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close