Quantifying the privacy risk of masked language models using membership inference attacksQuantifying Privacy Risks of Masked Language Models Using Membership Inference Attacks
The authors propose a likelihood-ratio-based membership inference attack for masked language models, raising AUC from the baseline's 0.662 to 0.900 on ClinicalBERT-Base (Table 2).
The attacker can access the target model Mθ and can train a reference model MθR using independently sampled data from the population distribution p; the goal is to determine, with a 0.5 prior, whether a given sample s belongs to the target model's training set D. The victim system is the ClinicalBERT family of masked language models pretrained on MIMIC-III medical notes.
- Prior conclusions from membership inference on masked language models (MLMs) using the target model loss were unclear, and MLMs were even considered more private than generative models; the authors argue the problem is that the loss mixes in the sample's inherent complexity as a confounding factor.
- The MLM is treated as an energy-based sequence probability model, the sequence likelihood is approximated with the energy formulation over 15% masking, and a likelihood-ratio test is then computed against a reference model trained on the population distribution, with the threshold selected according to the distribution over population data to decide membership.
- On ClinicalBERT models trained on MIMIC-III, sample-level attack AUC rises from the baseline 0.662 to 0.900, and recall at 10% FPR rises from 15.6% to 79.2% (Table 2); patient-level attack AUC reaches up to 1.000; long samples and name-insertion samples leak more.
- In the Limitations section, the authors note that membership inference alone is insufficient for a complete data privacy analysis and must be extended to reconstruction attacks and property inference attacks. The experiments were conducted only on the ClinicalBERT family of models and two reference models on MIMIC-III medical notes.
- Evaluated models
- ClinicalBERT-BaseClinicalBERT++ClinicalBERT-LargeClinicalBERT-large++ClinicalBERT-b (Base-b)
- Benchmarks
- MIMIC-IIIi2b2
- Metrics
- AUCPrecisionRecallTPRFPR
The paper proposes a membership inference attack based on a likelihood ratio hypothesis test, using an additional reference MLM to more accurately quantify the memorization leakage of masked language models on training data. The authors note that prior membership inference results relying only on model scores were not clear enough, and therefore designed this stronger attack. On a model trained on medical records, the attack raises AUC from 0.66 to 0.90 and achieves an attack strength 51 times that of prior work at a 1% false positive rate.
Paper analysis
What problem does this paper attempt to solve?
The authors argue that prior membership inference attacks on MLMs had unclear conclusions because they used only the target model loss, and propose a stronger likelihood-ratio-based attack to quantify their privacy leakage.
Core question: how to accurately quantify training data leakage of masked language models (MLMs) after training on sensitive data, i.e., determine whether an individual sample has been memorized by the model.
- Setting and importance: BERT-family MLMs are widely used in sensitive domains such as disease diagnosis and insurance analysis (as listed by the authors); the training data is sensitive, and the authors argue that a framework for systematically evaluating their training data leakage is needed.
- Shortcomings of existing methods: The authors state that prior membership inference and reconstruction attacks on MLMs either reached inconclusive findings (Lehman et al., 2021) or (incorrectly) concluded that MLMs memorize little and are more private than autoregressive models; the authors attribute this to these attacks using only the target model's loss on each sample as the signal, while loss is confounded by factors such as the sample's intrinsic complexity, leading to high false negatives or high false positives.
- Core hypothesis: A likelihood-ratio test using a reference model can calibrate away spurious differences caused by the sample's intrinsic complexity; the difficulty is that MLMs, unlike generative models, cannot directly compute sequence likelihood, which the authors address by treating the MLM as an energy-based probabilistic model (Goyal et al., 2022).
- What the paper proposes: A likelihood-ratio membership inference attack framework for MLMs, evaluated on a suite of ClinicalBERT models trained on medical notes, reporting AUC improving from a baseline of 0.66 to 0.90 (abstract; 0.662 to 0.900 in Table 2).
- Threat model (Section 2.1):
- Goal: Determine whether a given sample s belongs to the training set D of the target model Mθ (membership inference).
- Knowledge: The attacker has access to the target model Mθ; it is assumed that a reference model MθR can be trained on independently sampled data from the population distribution p.
- Capability: Compute the energy under the target model and the reference model for a sample and make a threshold decision; in the experiments, the attacker is challenged with samples drawn from the training set or the population with probability 0.5.
- Victim system: ClinicalBERT-family models pretrained on MIMIC-III medical notes.
What related research exists?
Related work falls into two categories: membership inference and training data extraction; this paper is closest to the loss-threshold attack of Jagannatha et al. (2021) but introduces a reference model and the energy formulation.
Membership inference attacks (MIA)
- Shokri et al. (2017), Yeom et al. (2018)—propose membership inference attacks that determine whether a target sample was used to train the target model; the paper frames these as privacy risk analysis tools.
- Shadow-model-based attacks (Jayaraman et al., 2021; Song and Shmatikov, 2018; Mahloujifar et al., 2021; Hisamoto et al., 2020; Shejwalkar et al., 2021)—rely on training multiple shadow models, applied respectively to LSTM text generation, word embeddings, machine translation, and Transformer classification models; the paper notes that such attacks are usually costly because they require training multiple shadow models and obtaining sufficient shadow data.
- Loss-only threshold attacks (Yeom et al., 2018; Song and Raghunathan, 2020; Jagannatha et al., 2021)—use only the target model's loss on the target sample for threshold decisions; among these, Jagannatha et al. (2021) is called by the paper the closest work to this paper, using a loss threshold attack on MLMs. The paper notes that this paper differs by using a reference model for a likelihood ratio test and computing likelihood with an energy formula, thereby achieving higher AUC.
Training data extraction
- Carlini et al. (2021b)—sampled over 500,000 samples from different GPT-2 models, used membership inference to filter out 1800 suspected memorized samples, and found through web checking that more than 600 of them were verbatim training samples (Appendix A.4).
- Lehman et al. (2021)—applied the same data extraction attack to MLMs, but the paper states its conclusions are unclear: only 4% of the generated sentences containing patient names also contained their actual medical conditions; their other extraction attacks used only target model signals, and frequency-based baselines were instead more successful.
Baselines and benchmarks
- Baseline methods: Model loss baseline (Yeom et al., 2018, etc.), with two threshold variants—µ threshold (using the mean loss of training samples as the threshold) and population threshold (taking the threshold corresponding to a 10% false positive rate on population samples).
- Data/setting: Follows the preprocessed data and pretrained models of Lehman et al. (2021); the target model's training set is MIMIC-III, and non-members come from the MIMIC-III holdout set or i2b2.
Positioning of this paper
The authors state that this paper is closest to Jagannatha et al. (2021) but differs in two points: (a) using a reference model for a likelihood ratio test, and (b) computing likelihood with an energy function formula; the authors state these two points are the reason the attack achieves higher AUC (Appendix A.4).
How does the paper address this problem?
MLM is treated as an energy-based sequence probability model; the energy difference between the target model and the reference model is used to construct a likelihood ratio test, and membership is determined by selecting a threshold according to the quantile on the population distribution.
Overall idea: membership inference via a likelihood-ratio test—rather than looking directly at the target model's loss, look at the ratio of the sample's likelihood under the target model to that under a reference model, using the reference model to calibrate the sample's intrinsic complexity; to make likelihood computable for MLMs, treat the MLM as an energy-based probabilistic model.
Problem formalization (Sections 2.1, 2.2)
- Setting: The target model Mθ is trained on dataset D (sampled from population distribution p); the attacker has access to Mθ and can train a reference model MθR on independent data from p.
- Hypothesis test: The null hypothesis Hout is that sample s is independent of D and comes from the population p; the alternative hypothesis Hin is that s comes from D. The test statistic is L(s) = log (p(s; θR))/(p(s; θ)), i.e., the log-likelihood ratio of the sample under the reference model versus the target model; if L(s) ≤ t, Hout is rejected and the sample is judged a member.
- Success measures: The attacker's power (true positive rate, TPR) and error (false positive rate, FPR); ROC curves and AUC are used for threshold-independent overall comparison.
Energy formulation for MLMs (Section 2.3)
- Energy perspective: Viewing the MLM as an energy model p(s;θ) = e^(−E(s;θ))/Zθ, substitution gives L(s) = E(s;θ) − E(s;θR) + constant; the difference in partition functions is a global constant and can be ignored, so only the energy difference between the two models is needed.
- Energy definition: Given that MLM training masks 15% of tokens, for a sequence of length T, take l = ⌊0.15×T⌋ masked positions, and define the energy as the negative of the average, over all masking combinations, of the log-probabilities at the masked positions: E(s; θ) = −1/(|C|) ∑I ∈ C ∑i ∈ I log pmlm(si | s∖ I; θ).
- Approximation: Exact computation requires |C| = C(T, l) forward passes, which is costly; the paper approximates by summing over K random masking patterns, K ≪ |C| (Appendix A.3.2 mentions 15% masking and an average of 10 times in practice).
Attack procedure and threshold selection (Section 2.4, Figures 1, 2)
- For a sample s to be judged, compute its energy under the target model and the reference model using the energy formulation, and subtract to obtain L(s).
- Choose a false positive rate α (10% in the main experiments), empirically estimate the distribution of L on samples from the population distribution, and take the corresponding quantile as the threshold t (Figure 2a).
- If L(s) ≤ t, judge as a member; otherwise judge as a non-member; sweeping all thresholds gives the ROC curve (Figure 2b).
Experimental subjects and reference models (Section 3, Appendix A.2)
- Target models: 4 ClinicalBERT variants pretrained on MIMIC-III (Base, Base++, Large, Large++, with training steps and sequence lengths in Table 1), plus a name-insertion model Base-b (each training sample is prefixed with a patient surrogate name).
- Reference models: Primarily PubMed-BERT (trained on PubMed text in the same domain as MIMIC-III but not containing its training data); the ablation uses the general-domain bert-base-uncased.
- Target sample pools: Members come from the MIMIC-III training set (4072 sequences subsampled from 99 patients, averaged over 10 repetitions); non-members are from the MIMIC-III held-out set (89 patients, 4072 sequences) or i2b2 (99 patients, 18561 sequences); the population data used for threshold selection is disjoint from the non-member sets.
- Decision method: Pure threshold-rule decisions, with no human or LLM review; metrics are AUC, precision, recall (threshold set at α = 10%).
What experiments did the paper conduct?
Sample-level and patient-level attacks on 5 ClinicalBERT models, with AUC rising from a baseline of 0.662 to 0.900, and analysis of the effects of sample length, model scale, reference model, and name insertion.
Experimental setup
- Models tested: ClinicalBERT-Base, Base++, Large, Large++ (Table 1), and the name-insertion model Base-b (Appendix A.2.3), all trained on MIMIC-III.
- Data: Members are a subsample of the MIMIC-III training set (99 patients, 4072 sequences, repeated 10 times and averaged); non-members are the MIMIC-III holdout set (89 patients, 4072 sequences) or i2b2 (99 patients, 18561 sequences) (Appendix A.2.2).
- Baselines: Model loss (using only the target model loss), with two threshold variants (A) w/ µ thresh. and (A) w/ Pop. thresh. (Table 1).
- Metrics: AUC (threshold-independent); precision and recall (threshold set at α = 10% FPR; Appendix A.3.1 additionally has α = 1%).
- Decision method: Threshold rule decision, no reviewer model; patient-level attacks decide by aggregating all notes of a patient.
- Reference model: PubMed-BERT mainly; the Table 5 ablation uses bert-base-uncased.
Main results
ClinicalBERT-Base, with PubMed-BERT as the reference model (per Table 2):
Swipe horizontally to read the table
Method Sample-level MIMIC AUC Sample-level i2b2 AUC Patient-level MIMIC AUC Patient-level i2b2 AUC (A) Model loss 0.662 0.812 0.915 1.000 (B) Ours 0.900 0.881 0.992 1.000 Method (10% FPR) Sample-level MIMIC Prec./Rec. Sample-level i2b2 Prec./Rec. (A) w/ µ thresh. 61.5 / 55.7 77.6 / 55.8 (A) w/ Pop. thresh. 61.2 / 15.6 79.6 / 39.0 (B) w/ Pop. thresh. 88.9 / 79.2 87.5 / 69.9 - The authors state that this paper's attack improves more under the MIMIC non-member setting, because members and non-members are more similar there and harder to distinguish using the target model loss alone, while the reference model can amplify the gap in the target model's behavior toward the two.
- The authors state that all patient-level attack metrics are higher than sample-level ones, because patient-level decisions aggregate multiple samples and have higher granularity.
- Figure 3 shows: with L(s), the histograms of members and non-members are clearly separated, whereas with the target model loss alone the two highly overlap; the authors accordingly state that the reference model helps measure the difficulty of each sample.
Sample length and model scale (Tables 3, 4)
- Sample length (ClinicalBERT-Base): Long samples (20–60 tokens) leak more than short samples (10–20 tokens)—this paper's attack AUC is 0.900 (MIMIC)/0.881 (i2b2) for long samples and 0.830/0.845 for short samples; the baseline is 0.662/0.812 for long samples and 0.516/0.756 for short samples. The authors suggest this may be because long samples are more unique and more likely to provide discriminative signal.
- Model scale and training amount (Table 4, MIMIC non-members): Leakage is similar across the four models; this paper's attack AUC is Base 0.900, Base++ 0.894, Large 0.904, Large++ 0.905; the authors state that Large++'s AUC is consistently higher than Base's, echoing Carlini et al. (2021b)'s observation that larger models have higher memorization capacity.
Reference model and name insertion (Tables 5, 6)
- Switching to a general reference model (Table 5): With bert-base-uncased as the reference, the attack remains effective but worse, e.g., on Base AUC 0.883 (vs 0.900 with the PubMed reference) and recall 71.5% (vs 79.2% with the PubMed reference); the authors state the reason is that PubMed has greater domain overlap with the target model's training data, whereas a reference model from a different distribution gives the same scores to easy and hard samples, lowering the true positive rate.
- Name-insertion model Base-b (Table 6, MIMIC non-members): This paper's attack is better on Base-b than on Base (sample-level AUC 0.960 vs 0.900, recall 91.3% vs 79.2%), whereas the baseline is worse at the sample level (AUC 0.561 vs 0.662). The authors hypothesize that inserting names increases sample entropy and makes samples harder to learn (average member loss 2.14 vs 1.61 for ordinary samples), so the baseline threshold classifies most members as non-members, while the reference model can identify such hard samples.
Other ablations and analyses
- 1% FPR (Table 10): This paper's attack recall is 43.0%–78.3% (long-sample Base 43.0%, Base-b 78.3%), versus only 0.1%–2.4% for baseline (A) w/ Pop. thresh.; the authors state the gap widens at low FPR. The abstract states that at 1% FPR the attack power is 51× that of prior work.
- Normalized energy (Table 11): Replacing the 15% masking energy with the normalized energy of Goyal et al. (2022) yields overall higher AUC (e.g., Base long samples 0.871 vs 0.830 in Table 9).
- Correlation of memorized samples (Table 7): Using logistic regression to predict whether a sample will be leaked (5505 training, 7461 test), the count of non-alphanumeric characters is the most indicative feature (test set precision 69.2, recall 47.5); with combined features, test set precision 72.1, recall 61.3; the authors suggest that samples containing multiple non-alphanumeric symbols (e.g., punctuation) are more likely to be memorized.
- Computational cost (Appendix A.2.4): No models were trained (0 hours of GPU training); inference ran for 18 hours on one RTX2080 (11GB).
What are some points that can be further explored?
In the Limitations section, the authors note that membership inference alone is insufficient and must be extended to reconstruction and property inference attacks; the experiments cover only the ClinicalBERT family in the medical domain.
Limitations and future directions noted by the authors
- Need to extend to other attack types (Limitations section): The authors state that although membership inference attacks are fundamental to privacy auditing and memorization analysis, membership inference alone is insufficient for a thorough data privacy analysis, and the analysis needs to be extended to reconstruction attacks and property inference attacks.
- Call to design privacy mitigation algorithms (Conclusions section): The authors state that the attacks in this paper show that MLMs are prone to memorization, and call for designing robust privacy mitigation algorithms for such language models.
- Protection directions mentioned in the Ethics Statement (Ethics Statement): The authors mention that differentially private training algorithms can be used to defend against membership inference, and also state that methods such as adversarial training and PII scrubbing can be used but do not provide the worst-case guarantees that differential privacy does; this is discussion in the statement rather than an experimental conclusion.
Scope of the experiments
- The models tested are 5 ClinicalBERT variants pretrained on MIMIC-III medical notes (Base, Base++, Large, Large++, Base-b); MLMs of other architectures or domains are not covered.
- Non-member data are of two kinds: the MIMIC-III holdout set (89 patients, 4072 sequences) and i2b2 (99 patients, 18561 sequences); member subsampling is repeated 10 times and averaged (Appendix A.2.2).
- Only two reference models were tested: the in-domain PubMed-BERT and the general-domain bert-base-uncased (Table 5).
- Threshold-related metrics are reported at two false positive rates: α = 10% (main text) and α = 1% (Appendix A.3.1).
- The paper does not report statistical significance tests or confidence intervals for the attacks; threshold setting depends on population distribution samples available to the attacker.
Summarize the main content of the paper
The authors propose a likelihood-ratio membership inference attack against MLMs, raising AUC from 0.662 to 0.900 on ClinicalBERT, and the authors state that MLMs in fact readily memorize training data.
A membership inference attack paper targeting privacy leakage in masked language models (MLMs). Prior attacks based on the target model loss had unclear conclusions for MLMs; the authors argue the reason is that the loss mixes in the sample's inherent complexity.
- Method: Treat the MLM as an energy-based sequence probability model, approximate the sequence likelihood with the energy formula for 15% masking, compute a likelihood ratio against a reference model trained on the population distribution (mainly PubMed-BERT), and determine membership by a threshold set according to the quantile on population samples.
- Main results: On ClinicalBERT-Base trained on MIMIC-III, sample-level attack AUC rises from the Model loss baseline's 0.662 to 0.900, and recall at 10% FPR rises from 15.6% to 79.2% (Table 2); patient-level attack AUC reaches up to 1.000 (i2b2 non-members).
- Low-error regime: At 1% FPR, this paper's attack recall is 43.0%–78.3%, versus only 0.1%–2.4% for the baseline (Table 10); the abstract states that at this point the attack power is 51× that of prior work.
- Influencing factors: Long samples (20–60 tokens) leak more than short samples (AUC 0.900 vs 0.830, Table 3); switching to the general reference model bert-base-uncased reduces effectiveness (AUC 0.883, Table 5); the attack is stronger on the name-insertion model Base-b (AUC 0.960, Table 6).
- Authors' conclusion: Contrary to prior conclusions, MLMs are vulnerable to attacks exploiting training data leakage; the authors call for designing robust privacy mitigation algorithms for such models and note that a complete privacy analysis also needs to be extended to reconstruction and property inference attacks.
Related papers
- Membership Inference Attack on Private EvolutionAttacksarXiv