Grimoire
Sheet
pathadversarial/privacy
difficultyadvanced
timeO(N)
described2017
revised5w ago

Membership Inference

Members have lower loss than non-members. The attack is entirely in the calibration: some examples are simply easy, and an uncalibrated threshold measures difficulty rather than membership.

Theory

The naive attack thresholds the loss and achieves respectable average accuracy while being useless — it flags easy examples. LiRA calibrates per example by fitting Gaussians to the model-confidence statistic under shadow models trained with and without that example, then runs a likelihood-ratio test.

Λ(x,y)=p(ϕN(μin,σin2))p(ϕN(μout,σout2)),ϕ=ϕ(x,y)\Lambda(x, y) = \frac {p\bigl( \phi \mid \mathcal{N}(\mu_{\text{in}},\, \sigma_{\text{in}}^2) \bigr)} {p\bigl( \phi \mid \mathcal{N}(\mu_{\text{out}},\, \sigma_{\text{out}}^2) \bigr)}, \qquad \phi = \phi(x, y)
eq. 1 — φ the logit-scaled confidenceCarlini et al. §IV

Report TPR at low FPR, not accuracy or AUC. An attack that identifies 0.1% of the training set with near-certainty is a serious privacy failure and can sit at 51% average accuracy; the aggregate numbers hide exactly the regime that matters.

Implementation
python · numpy + scipy
import numpy as np
from scipy.stats import norm


def logit_confidence(p_correct: np.ndarray) -> np.ndarray:
    """Map confidence to an approximately normal statistic."""
    p = np.clip(p_correct, 1e-6, 1 - 1e-6)
    return np.log(p) - np.log1p(-p)


def lira_score(phi_target: float,
               phi_in: np.ndarray, phi_out: np.ndarray) -> float:
    """phi_in / phi_out: statistic from shadow models trained
    with and without the target example."""
    mu_in, sd_in = phi_in.mean(), phi_in.std() + 1e-8
    mu_out, sd_out = phi_out.mean(), phi_out.std() + 1e-8
    return (norm.logpdf(phi_target, mu_in, sd_in)
            - norm.logpdf(phi_target, mu_out, sd_out))

The logit transform is what makes the Gaussian assumption tenable; fitting normals directly to bounded confidences puts most of the mass against the boundary and the ratio becomes meaningless. Shadow models must match the target’s architecture and training recipe — a mismatched shadow calibrates against the wrong distribution and reads as a weaker attack than the data supports.

Related
References
[1]Shokri et al. — Membership Inference Attacks Against Machine Learning Models (2017)arXiv:1610.05820
[2]Carlini et al. — Membership Inference Attacks From First Principles (2021)arXiv:2112.03570
[3]Carlini et al. — Extracting Training Data from Large Language Models (2020)arXiv:2012.07805