Simple Algorithm
Artificial Intelligence · Hidden Layer · 22 min

Privacy & Security

Protecting data and models.

Strip the names from a dataset and it is still not anonymous: a ZIP code, a birth date and a sex single out most Americans, and a handful of movie ratings single out a Netflix subscriber. Models leak too, through their outputs, their parameters and even their gradients. This lesson shows why ad hoc anonymization fails, derives the guarantees of differential privacy, and maps the attacks a deployed model must withstand.

What you’ll learn

  • Explain linkage and reconstruction attacks, and prove that answering many queries too accurately reveals the data (Dinur–Nissim).
  • State (ε,δ)(\varepsilon,\delta)-differential privacy, and prove that randomized response and the Laplace mechanism satisfy it.
  • Apply composition and post-processing, and compare the accuracy cost of privacy in the local and central models.
  • Describe DP-SGD, federated averaging and the main attacks on models, and prove that differential privacy bounds every membership-inference attack.

Why anonymization fails

In 1997 Massachusetts released "anonymized" hospital records of state employees. Latanya Sweeney bought the Cambridge voter roll for twenty dollars and found the governor's record by joining the two tables on ZIP code, birth date and sex; she later estimated that 87% of Americans are unique on those three attributes (Sweeney, 2000). Narayanan & Shmatikov (2008) showed that in the Netflix Prize data, 8 movie ratings (2 of which may be wrong) with dates known to within 14 days single out 99% of subscribers, and matched some records to public IMDb reviews. In a mobility dataset of 1.5 million people, four location points single out 95% (de Montjoye et al., 2013).

Attributes that are harmless alone but identifying together are quasi-identifiers. The classic defense generalizes them until no record stands out:

It fails in several ways. Homogeneity: if all kk records in a group share a diagnosis, the table reveals it. Background knowledge narrows a group further; ℓ\ell-diversity (Machanavajjhala et al., 2006) and then tt-closeness were proposed in response. Composition: two kk-anonymous releases of overlapping data can be intersected (Ganta, Kasiviswanathan & Smith, 2008). High dimension: in sparse data such as ratings almost every record is unique, so hiding them destroys the data (Aggarwal, 2005). The deeper flaw is that these are properties of the output table relative to assumed attacker knowledge, not guarantees about the release process against every attacker.

Check your understanding

A hospital publishes a 5-anonymous table. Your neighbor is a 35-year-old woman in ZIP code 0213*, you know she is in the table, and all five records with those quasi-identifiers list "HIV positive". What have you learned?

  1. Nothing: 5-anonymity hides her among five people
  2. That she is HIV positive with probability 20%
  3. Her diagnosis, with certainty
  4. Only that she visited this hospital
Show the answer

C. Her diagnosis, with certainty

She is one of the five, and all five share the diagnosis. kk-anonymity hides which record is hers, not what the records say: the homogeneity attack.

DerivationProof of the first claim
  1. ∣ aS−∑i∈Sci∣≤Efor every S\Big|\,a_S-\sum_{i\in S}c_i\Big|\le E\quad\text{for every }S

    The adversary outputs any cc consistent with all the answers aSa_S; one exists, because dd itself is consistent:

  2. ∣S1∣=∑i∈S1ci−∑i∈S1di≤∣∑i∈S1ci−aS1∣+∣aS1−∑i∈S1di∣≤2E|S_1|=\sum_{i\in S_1}c_i-\sum_{i\in S_1}d_i\le\Big|\sum_{i\in S_1}c_i-a_{S_1}\Big|+\Big|a_{S_1}-\sum_{i\in S_1}d_i\Big|\le2E

    Let S1={i:ci=1, di=0}S_1=\{i:c_i=1,\ d_i=0\}. Both cc and dd are within EE of the same answer aS1a_{S_1}:

  3. Likewise S0={i:ci=0, di=1}S_0=\{i:c_i=0,\ d_i=1\} has ∣S0∣≤2E|S_0|\le2E. Since cc and dd differ exactly on S0∪S1S_0\cup S_1, they differ in at most 4E4E positions. □\square

Dwork & Roth call this the fundamental law of information recovery: overly accurate answers to too many questions destroy privacy, however the data were anonymized. The US Census Bureau ran such an attack on its own published 2010 tables. It reconstructed exact records (block, sex, age, race and ethnicity) for about 46% of the population, and linking them to commercial data correctly re-identified about 17% (Abowd et al., 2023). For 2020 it switched to differential privacy.

Differential privacy

Differential privacy says that whatever anyone concludes from the output, they would have concluded almost the same without your record, whatever else they know. In Bayesian terms (with δ=0\delta=0), the posterior odds of any hypothesis about your record, such as "she is in the data" or "her answer is yes", can exceed the prior odds by at most a factor eεe^\varepsilon. The slack δ\delta is a probability of failure, so it must be much smaller than 1/n1/n: a mechanism that publishes each record with probability δ\delta is (0,δ)(0,\delta)-DP, yet exposes about δn\delta n people.

Note what differential privacy does not hide: facts about the population. A study showing that smoking causes cancer reveals something about every smoker, whether or not they took part.

DerivationRandomized response is ε-DP
  1. Pr⁡(yes∣trait)=1+q2,Pr⁡(yes∣no trait)=1−q2\Pr(\text{yes}\mid\text{trait})=\frac{1+q}{2},\qquad\Pr(\text{yes}\mid\text{no trait})=\frac{1-q}{2}

    In randomized response (Warner, 1965) each person tells the truth with probability qq and otherwise answers with a fair coin:

  2. 1+q1−q=eε  ⟺  q=eε−1eε+1=tanh⁡ε2\frac{1+q}{1-q}=e^\varepsilon\iff q=\frac{e^\varepsilon-1}{e^\varepsilon+1}=\tanh\frac\varepsilon2

    For either answer, the likelihoods under the two possible truths differ by at most a factor (1+q)/(1−q)(1+q)/(1-q). Setting this to eεe^\varepsilon gives the truth probability for a target ε\varepsilon; two fair coins (q=12q=\tfrac12) give ε=ln⁡3\varepsilon=\ln3:

  3. π^=y^−(1−q)/2q,se⁡(π^)=1qP(1−P)n≈1εn\hat\pi=\frac{\hat y-(1-q)/2}{q},\qquad\operatorname{se}(\hat\pi)=\frac1q\sqrt{\frac{P(1-P)}{n}}\approx\frac1{\varepsilon\sqrt n}

    This is the local model: each answer is private on its own, and no one is trusted with the truth. With true rate π\pi, the yes-rate y^\hat y has mean P=qπ+1−q2P=q\pi+\frac{1-q}2, which gives an unbiased estimator and its standard error (q≈ε/2q\approx\varepsilon/2 and P≈12P\approx\tfrac12 for small ε\varepsilon):

Predict before you look

A survey of n=1000n=1000 people uses randomized response with ε=0.25\varepsilon=0.25, and the true rate is 30%. What is the standard error of π^\hat\pi, in percentage points?

Show the answer

12.7 pts

q=tanh⁡(0.125)≈0.124q=\tanh(0.125)\approx0.124 and P=0.124×0.3+0.438≈0.475P=0.124\times0.3+0.438\approx0.475, so se⁡=0.475×0.525/1000 / 0.124≈0.0158/0.124≈0.127\operatorname{se}=\sqrt{0.475\times0.525/1000}\,/\,0.124\approx0.0158/0.124\approx0.127. The approximation 1/(εn)=1/(0.25×31.6)≈0.1261/(\varepsilon\sqrt n)=1/(0.25\times31.6)\approx0.126 agrees. With two fair coins (ε=ln⁡3\varepsilon=\ln3) the same survey has standard error 3.1 points.

The Laplace mechanism

A trusted curator can do much better than randomized response, by adding noise once, to the answer. How much noise depends on how much one person can move the answer. The ℓ1\ell_1 sensitivity of a query ff with values in Rk\R^k is Δf=max⁡D,D′ neighbors∥f(D)−f(D′)∥1\Delta f=\max_{D,D'\ \text{neighbors}}\norm{f(D)-f(D')}_1. A count has Δf=1\Delta f=1; a histogram in which each person falls in one bin also has Δf=1\Delta f=1; a sum of values clipped to [0,B][0,B] has Δf=B\Delta f=B.

DerivationProof
  1. pD(z)pD′(z)=∏i=1kexp⁡(−ε∣fi(D)−zi∣/Δf)exp⁡(−ε∣fi(D′)−zi∣/Δf)=exp⁡(εΔf∑i=1k(∣fi(D′)−zi∣−∣fi(D)−zi∣))\frac{p_D(\mathbf z)}{p_{D'}(\mathbf z)}=\prod_{i=1}^k\frac{\exp\big(-\varepsilon\abs{f_i(D)-z_i}/\Delta f\big)}{\exp\big(-\varepsilon\abs{f_i(D')-z_i}/\Delta f\big)}=\exp\Big(\frac{\varepsilon}{\Delta f}\sum_{i=1}^k\big(\abs{f_i(D')-z_i}-\abs{f_i(D)-z_i}\big)\Big)

    Compare the output densities at any point z\mathbf z for neighbors DD and D′D':

  2. pD(z)pD′(z)≤exp⁡(ε ∥f(D)−f(D′)∥1Δf)≤eε\frac{p_D(\mathbf z)}{p_{D'}(\mathbf z)}\le\exp\Big(\frac{\varepsilon\,\norm{f(D)-f(D')}_1}{\Delta f}\Big)\le e^\varepsilon

    By the triangle inequality each term is at most ∣fi(D)−fi(D′)∣\abs{f_i(D)-f_i(D')}, and by the definition of sensitivity they sum to at most Δf\Delta f:

  3. Integrating the pointwise bound over any set SS gives Pr⁡[M(D)∈S]≤eεPr⁡[M(D′)∈S]\Pr[M(D)\in S]\le e^\varepsilon\Pr[M(D')\in S]. □\square

Accuracy follows from the Laplace tail: Pr⁡[∣Y∣≥t Δf/ε]=e−t\Pr\big[\abs Y\ge t\,\Delta f/\varepsilon\big]=e^{-t}, and the standard deviation is 2 Δf/ε\sqrt2\,\Delta f/\varepsilon. A count released at ε=0.5\varepsilon=0.5 is within ±5\pm5 of the truth with probability 1−e−2.5≈92%1-e^{-2.5}\approx92\%. The error does not grow with nn, so as a fraction it shrinks like 1/(εn)1/(\varepsilon n), against 1/(εn)1/(\varepsilon\sqrt n) for randomized response. For 1,000 people at ε=ln⁡3\varepsilon=\ln3, the Laplace mechanism has a standard deviation of 1.3 people (0.13 points) where randomized response has 3.1 points, about 24 times more. The price is trusting a curator with the raw data.

Composition, post-processing and private learning

DerivationProofs of post-processing and basic composition (pure DP, discrete outputs)
  1. Pr⁡[g(M(D))∈S]=Pr⁡[M(D)∈g−1(S)]≤eεPr⁡[M(D′)∈g−1(S)]=eεPr⁡[g(M(D′))∈S]\Pr[g(M(D))\in S]=\Pr[M(D)\in g^{-1}(S)]\le e^\varepsilon\Pr[M(D')\in g^{-1}(S)]=e^\varepsilon\Pr[g(M(D'))\in S]

    Post-processing: for a deterministic gg, the event g(M(D))∈Sg(M(D))\in S is the event M(D)∈g−1(S)M(D)\in g^{-1}(S), to which the DP inequality applies; a randomized gg is a mixture of deterministic ones.

  2. Pr⁡[(a,b)∣D]=Pr⁡[M1(D)=a] Pr⁡[M2(D;a)=b]≤eε1Pr⁡[M1(D′)=a]⋅eε2Pr⁡[M2(D′;a)=b]\Pr[(a,b)\mid D]=\Pr[M_1(D)=a]\,\Pr[M_2(D;a)=b]\le e^{\varepsilon_1}\Pr[M_1(D')=a]\cdot e^{\varepsilon_2}\Pr[M_2(D';a)=b]

    Composition: the second mechanism may depend on the first output aa, but for each fixed aa it is ε2\varepsilon_2-DP, so the joint probability of (a,b)(a,b) factorizes and the two ratios multiply:

Check your understanding

A system answers the same count 25 times, each time with fresh Laplace noise at ε=0.2\varepsilon=0.2. Under basic composition, what is the total privacy cost?

  1. ε=0.2\varepsilon=0.2, since each answer gets fresh noise
  2. ε=1\varepsilon=1, since 25×0.2=1\sqrt{25}\times0.2=1
  3. ε=5\varepsilon=5
  4. ε=0.008\varepsilon=0.008, since the noise averages out
Show the answer

C. ε=5\varepsilon=5

Basic composition adds the costs: 25×0.2=525\times0.2=5. The mean of the 25 answers really is about five times more accurate than one answer, which is exactly why the cost must add up. (Advanced composition gives about 5.9 here with δ′=10−5\delta'=10^{-5}; it pays off only for many queries with small ε\varepsilon.)

For vectors, the Gaussian mechanism adds N(0,σ2I)\mathcal N(0,\sigma^2I) with σ=Δ2f2ln⁡(1.25/δ)/ε\sigma=\Delta_2f\sqrt{2\ln(1.25/\delta)}/\varepsilon, where Δ2f\Delta_2f is the ℓ2\ell_2 sensitivity; this gives (ε,δ)(\varepsilon,\delta)-DP for ε<1\varepsilon<1. It is the workhorse of private machine learning, because a gradient's ℓ2\ell_2 norm is easy to bound by clipping:

text
DP-SGD(data of size N, steps T, expected batch L, clip C, noise multiplier σ, rate η):
    for t = 1 … T:
        B ← include each example independently with probability L/N
        for each example i in B:
            g_i ← ∇θ loss(θ; x_i)
            g_i ← g_i / max(1, ‖g_i‖₂ / C)          # clip: now ‖g_i‖₂ ≤ C
        g ← (Σ_i g_i + N(0, σ²C²·I)) / L            # Gaussian mechanism
        θ ← θ − η · g
    return θ, and the (ε, δ) spent, computed by a privacy accountant

DP-SGD (Abadi et al., 2016). Clipping bounds each example's influence, the noise is the Gaussian mechanism, random batches amplify privacy, and an accountant based on Rényi differential privacy (Mironov, 2017) tracks ε\varepsilon over thousands of steps far more tightly than basic composition.

Abadi et al. reached accuracies in the mid-90s on MNIST at single-digit ε\varepsilon (with δ=10−5\delta=10^{-5}), and later work narrowed the gap further by privately fine-tuning publicly pretrained models. The costs are per-example gradients, lower accuracy, and errors concentrated on rare examples and small groups. Deployed systems include the 2020 US Census and telemetry collected with local differential privacy by Google (RAPPOR; Erlingsson, Pihur & Korolova, 2014) and Apple.

Attacks on models, and federated learning

A trained model is itself a release of its training data. The main attacks:

  • Membership inference: decide from the model whether a given record was in its training set. Shokri et al. (2017) trained "shadow models" on similar data to learn what members look like; Evaluating Language Models frames the problem with the Neyman–Pearson lemma.
  • Model inversion: reconstruct typical inputs of a class, such as recognizable faces from a face-recognition model's confidence scores (Fredrikson, Jha & Ristenpart, 2015).
  • Training-data extraction: prompt a model to reproduce memorized text verbatim; Carlini et al. (2021) extracted hundreds of sequences from GPT-2, including names, phone numbers and email addresses.
  • Model stealing: copy a model's behavior or parameters through its prediction API (Tramèr et al., 2016).
  • Prompt injection: attack applications built on language models through the documents and web pages they read.

Federated learning (McMahan et al., 2017) keeps data on devices. Each round the server sends the current model to a sample of clients; each runs a few local SGD steps on its own data; the server averages the returned models, weighted by data size (FedAvg). It was deployed early for next-word prediction on phone keyboards (Hard et al., 2018). By itself it is not private, because updates leak: Zhu, Liu & Han (2019) reconstructed training images and text from shared gradients. Secure aggregation (Bonawitz et al., 2017) lets the server see only the sum of client updates, and clipping each client's update and adding Gaussian noise gives user-level differential privacy (McMahan et al., 2018).

text
FEDAVG(rounds R, clients per round m, local steps E, rate η):
    w ← initial model
    for r = 1 … R:
        S ← random sample of m clients
        for each client k in S, in parallel:
            w_k ← w;  repeat E times: w_k ← w_k − η ∇F_k(w_k; local mini-batch)
        w ← Σ_{k∈S} (n_k / n_S) · w_k            # n_k = client k's data size
    return w

Key takeaways

  • Removing names is not anonymization: quasi-identifiers and sparse high-dimensional records re-identify people, and kk-anonymity fails under homogeneity, background knowledge and composition.
  • Dinur–Nissim: answering all subset sums within error EE lets an attacker recover all but 4E4E bits, so privacy requires noise of order n\sqrt n or limits on queries.
  • (ε,δ)(\varepsilon,\delta)-differential privacy bounds how much any output can depend on one person; randomized response (q=tanh⁡(ε/2)q=\tanh(\varepsilon/2)) and the Laplace mechanism (scale Δf/ε\Delta f/\varepsilon) achieve it, with error about 1/(εn)1/(\varepsilon\sqrt n) in the local model versus 1/(εn)1/(\varepsilon n) in the central one.
  • Guarantees compose (basic composition adds the ε\varepsilon's), survive post-processing, and power DP-SGD: clip per-example gradients, add Gaussian noise, track the budget with an accountant.
  • Models leak through membership inference, inversion, extraction and gradients; DP caps every membership attack at TPR≤eε FPR+δ\text{TPR}\le e^\varepsilon\,\text{FPR}+\delta, and federated learning needs secure aggregation and DP to be private.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

You release the sum of a numeric attribute over all patients, with each value clipped to [0,50][0,50], using the Laplace mechanism at ε=0.5\varepsilon=0.5 (add/remove neighbors). What noise scale bb is needed?

  1. b=2b=2
  2. b=25b=25
  3. b=100b=100
  4. b=50b=50
Show the answer

C. b=100b=100

Adding or removing one patient changes the sum by at most 50, so Δf=50\Delta f=50 and b=Δf/ε=50/0.5=100b=\Delta f/\varepsilon=50/0.5=100. Clipping is what makes the sensitivity finite.

Question 2

A randomized-response survey tells the truth with probability q=0.8q=0.8 and otherwise flips a fair coin. What is its ε\varepsilon?

  1. ln⁡4≈1.39\ln4\approx1.39
  2. ln⁡9≈2.20\ln9\approx2.20
  3. 0.80.8
  4. ln⁡3≈1.10\ln3\approx1.10
Show the answer

B. ln⁡9≈2.20\ln9\approx2.20

Pr⁡(yes∣trait)=0.9\Pr(\text{yes}\mid\text{trait})=0.9 and Pr⁡(yes∣no trait)=0.1\Pr(\text{yes}\mid\text{no trait})=0.1, a ratio of 9=(1+q)/(1−q)9=(1+q)/(1-q), so ε=ln⁡9\varepsilon=\ln9.

Question 3

An analyst receives an ε\varepsilon-DP noisy count, rounds it, removes negative values and publishes a chart. How private is the chart?

  1. ε\varepsilon-DP: post-processing cannot increase privacy loss
  2. Less private, because rounding reduces the noise
  3. Not private, because the chart was not produced by a DP mechanism
  4. 2ε2\varepsilon-DP, because it was processed twice
Show the answer

A. ε\varepsilon-DP: post-processing cannot increase privacy loss

Any function of a DP output, applied without access to the data, is DP with the same parameters: if g(M(D))∈Sg(M(D))\in S then M(D)∈g−1(S)M(D)\in g^{-1}(S), and the DP inequality holds for that set.

Question 4

A model is trained with (ln⁡3,0)(\ln3,0)-differential privacy. A membership-inference attack falsely flags 10% of non-members. At most what fraction of members can it detect?

  1. 10%
  2. 75%
  3. 100%
  4. 30%
Show the answer

D. 30%

TPR≤eε FPR+δ=3×0.10=0.30\text{TPR}\le e^\varepsilon\,\text{FPR}+\delta=3\times0.10=0.30. Every attack, whatever its method, is confined below this line.

Question 5

A curator answers every subset-sum query on n=1000n=1000 secret bits, each answer within ±5\pm5 of the truth. In the worst case for privacy, how many bits can an attacker be guaranteed to get right?

  1. At least 980
  2. At least 500
  3. At least 995
  4. None: errors of 5 hide every bit
Show the answer

A. At least 980

Dinur–Nissim: any database consistent with all the answers differs from the truth in at most 4E=204E=20 bits, so at least 980 of 1,000 are recovered.

Go deeper

Further reading

  • C. Dwork & A. Roth, The Algorithmic Foundations of Differential Privacy (Foundations and Trends in Theoretical Computer Science, 2014).
  • I. Dinur & K. Nissim, "Revealing information while preserving privacy," PODS (2003).
  • A. Narayanan & V. Shmatikov, "Robust de-anonymization of large sparse datasets," IEEE Symposium on Security and Privacy (2008).
  • M. Abadi, A. Chu, I. Goodfellow, H. B. McMahan, I. Mironov, K. Talwar & L. Zhang, "Deep learning with differential privacy," ACM CCS (2016).