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 -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 records in a group share a diagnosis, the table reveals it. Background knowledge narrows a group further; -diversity (Machanavajjhala et al., 2006) and then -closeness were proposed in response. Composition: two -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.
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?
- Nothing: 5-anonymity hides her among five people
- That she is HIV positive with probability 20%
- Her diagnosis, with certainty
- 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. -anonymity hides which record is hers, not what the records say: the homogeneity attack.
The adversary outputs any consistent with all the answers ; one exists, because itself is consistent:
Let . Both and are within of the same answer :
Likewise has . Since and differ exactly on , they differ in at most positions.
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 ), 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 . The slack is a probability of failure, so it must be much smaller than : a mechanism that publishes each record with probability is -DP, yet exposes about 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.
In randomized response (Warner, 1965) each person tells the truth with probability and otherwise answers with a fair coin:
For either answer, the likelihoods under the two possible truths differ by at most a factor . Setting this to gives the truth probability for a target ; two fair coins () give :
This is the local model: each answer is private on its own, and no one is trusted with the truth. With true rate , the yes-rate has mean , which gives an unbiased estimator and its standard error ( and for small ):
A survey of people uses randomized response with , and the true rate is 30%. What is the standard error of , in percentage points?
Show the answer
12.7 pts
and , so . The approximation agrees. With two fair coins () 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 sensitivity of a query with values in is . A count has ; a histogram in which each person falls in one bin also has ; a sum of values clipped to has .
Compare the output densities at any point for neighbors and :
By the triangle inequality each term is at most , and by the definition of sensitivity they sum to at most :
Integrating the pointwise bound over any set gives .
Accuracy follows from the Laplace tail: , and the standard deviation is . A count released at is within of the truth with probability . The error does not grow with , so as a fraction it shrinks like , against for randomized response. For 1,000 people at , 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
Post-processing: for a deterministic , the event is the event , to which the DP inequality applies; a randomized is a mixture of deterministic ones.
Composition: the second mechanism may depend on the first output , but for each fixed it is -DP, so the joint probability of factorizes and the two ratios multiply:
A system answers the same count 25 times, each time with fresh Laplace noise at . Under basic composition, what is the total privacy cost?
- , since each answer gets fresh noise
- , since
- , since the noise averages out
Show the answer
C.
Basic composition adds the costs: . 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 ; it pays off only for many queries with small .)
For vectors, the Gaussian mechanism adds with , where is the sensitivity; this gives -DP for . It is the workhorse of private machine learning, because a gradient's norm is easy to bound by clipping:
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 accountantDP-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 over thousands of steps far more tightly than basic composition.
Abadi et al. reached accuracies in the mid-90s on MNIST at single-digit (with ), 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).
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 wKey takeaways
- Removing names is not anonymization: quasi-identifiers and sparse high-dimensional records re-identify people, and -anonymity fails under homogeneity, background knowledge and composition.
- Dinur–Nissim: answering all subset sums within error lets an attacker recover all but bits, so privacy requires noise of order or limits on queries.
- -differential privacy bounds how much any output can depend on one person; randomized response () and the Laplace mechanism (scale ) achieve it, with error about in the local model versus in the central one.
- Guarantees compose (basic composition adds the '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 , 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.
You release the sum of a numeric attribute over all patients, with each value clipped to , using the Laplace mechanism at (add/remove neighbors). What noise scale is needed?
Show the answer
C.
Adding or removing one patient changes the sum by at most 50, so and . Clipping is what makes the sensitivity finite.
A randomized-response survey tells the truth with probability and otherwise flips a fair coin. What is its ?
Show the answer
B.
and , a ratio of , so .
An analyst receives an -DP noisy count, rounds it, removes negative values and publishes a chart. How private is the chart?
- -DP: post-processing cannot increase privacy loss
- Less private, because rounding reduces the noise
- Not private, because the chart was not produced by a DP mechanism
- -DP, because it was processed twice
Show the answer
A. -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 then , and the DP inequality holds for that set.
A model is trained with -differential privacy. A membership-inference attack falsely flags 10% of non-members. At most what fraction of members can it detect?
- 10%
- 75%
- 100%
- 30%
Show the answer
D. 30%
. Every attack, whatever its method, is confined below this line.
A curator answers every subset-sum query on secret bits, each answer within of the truth. In the worst case for privacy, how many bits can an attacker be guaranteed to get right?
- At least 980
- At least 500
- At least 995
- 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 bits, so at least 980 of 1,000 are recovered.
Go deeper
- Differential Privacy · A mathematical definition of privacy, and its cost.
- Federated Learning · Training without centralizing data.
- Attacks on Models · Membership inference, extraction and prompt injection.
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).