Context-Aware Membership Inference Attacks against Pre-trained Large Language Models

Hongyan Chang, Ali Shahin Shamsabadi, Kleomenis Katevas, Hamed Haddadi, Reza Shokri

TL;DR

This paper introduces CAMIA (Context-Aware Membership Inference Attack), a highly efficient method to determine if a specific text snippet was used to train a pre-trained Large Language Model (LLM). By shifting the focus from overall sequence loss to token-level uncertainty and context dynamics, CAMIA significantly outperforms existing attacks without requiring expensive reference models.

What Problem Does This Paper Address?

Membership Inference Attacks (MIAs) help researchers evaluate privacy risks and data leakage by identifying whether a piece of data was part of a model's training set. However, traditional MIAs—originally designed for classification models—perform poorly on LLMs.

Standard approaches typically look at the average loss across an entire text sequence. This ignores the generative, token-by-token nature of LLMs, where the predictability of a token depends heavily on the preceding text (the prefix). Furthermore, state-of-the-art MIAs often require training independent "reference models" on similar datasets to calibrate their scores. For massive pre-trained LLMs, training these reference models is computationally prohibitive and often practically impossible.

Methods

The authors propose CAMIA, a framework built on the insight that memorization in LLMs is context-dependent. Instead of treating all tokens equally, CAMIA extracts fine-grained, token-level signals from the target model's perplexity dynamics:

  1. Token Diversity Calibration: Repetitive text naturally yields low loss regardless of whether the model has seen it during training. CAMIA normalizes the loss based on the ratio of unique tokens to total tokens to eliminate this bias. Effect of token diversity calibration on separating members and non-members
Figure 1: Effect of token diversity calibration on mem- bership inference (Pythia-160M, GitHub domain). Cal- ibration clearly improves separation of members and non-members, significantly enhancing true positive rates (TPR) at low false positive rates (FPR).
  1. Filtering Less Informative Tokens (Cut-off Loss): As a text sequence grows, the context becomes highly informative, causing the loss gap between training data (members) and unseen data (non-members) to close. CAMIA truncates the evaluation sequence to only the first $T'$ tokens where the membership signal is strongest. Average token losses at the beginning vs. the end of sequences
Figure 2: Average token losses at the beginning (left) and end (right) of sequences (Pythia-160M, Arxiv do- main). Early tokens exhibit clearer differences between members and non-members, justifying our cut-off ap- proach.
  1. Loss Decreasing Rate (Slope): When faced with an ambiguous prefix, an LLM evaluating a memorized sequence will quickly resolve its uncertainty, causing token losses to drop sharply. CAMIA captures this by calculating the downward slope of the early token losses. Linear fits showing steeper loss decline for member sequences
Figure 3: Linear fits to token-loss sequences (Pythia- 160M, Pile-CC domain). Member losses decrease signif- icantly faster (slope = 0.014) than non-members (slope = 0.000), reflecting stronger memorization.
  1. Robust Low-Loss Counting: Average losses are easily skewed by sudden, massive spikes (e.g., when a text switches languages). CAMIA avoids this by counting how many tokens fall below adaptive, context-dependent thresholds rather than averaging them. Example of a token-loss spike dominating average loss during a language switch
Figure 4: Example token-loss spike when the language switches from English to Bulgarian (Pythia-160M). The sudden spike (loss = 484.2) dominates the sequence, inflating the average loss to 9.33 and obscuring mem- bership signals. This motivates using robust counts of low-loss tokens rather than relying on average loss.
  1. Complexity & Fluctuation Metrics: Unseen text yields highly unstable, fluctuating token-level losses, whereas memorized text produces smoother patterns. CAMIA uses Approximate Entropy and Lempel-Ziv complexity to quantify these variations.

Finally, these individual signals are combined into a single, unified membership score using statistical composition methods (like Edgington's or George's tests) or via a lightweight logistic regression classifier if a small amount of labeled member data is available.

Datasets

The authors evaluated CAMIA using the MIMIR benchmark, a dataset specifically designed for evaluating MIAs on LLMs. MIMIR draws from seven distinct domains of The Pile:

  • Pile-CC (web text)
  • Wikipedia
  • PubMed Central
  • Arxiv
  • HackerNews
  • DM Mathematics
  • GitHub

The benchmark includes multiple data splits based on varying levels of $n$-gram overlap to rigorously test the attack's ability to distinguish true members from highly similar non-members.

Key Insights and Ideas

  • Memorization is triggered by ambiguity: If a prefix clearly dictates the next token through logic or repetition, the model generalizes. However, when the prefix is complex or ambiguous, the model relies heavily on specific memorized sequences from its training phase to resolve uncertainty.
  • Early tokens matter most: The beginning of a text sequence contains the highest concentration of membership information. Once the context window fills up, the model's next-token predictions generalize so well that the distinction between member and non-member data disappears.
  • Averages lie: Relying on sequence-level average loss makes an attack fragile. A single formatting anomaly or language shift can mask strong token-level memorization signals.

Key Results

CAMIA consistently outperformed all baseline attacks across multiple model families (Pythia, GPT-Neo) and sizes (ranging from 70M to 12B parameters):

  • Arxiv Domain: When attacking a 2.8B Pythia model, CAMIA achieved a 32.00% True Positive Rate (TPR) at a strict 1% False Positive Rate (FPR), nearly doubling the performance of the best baseline (LOSS at 14.94%).
  • GitHub Domain: CAMIA achieved a TPR of 63.30% compared to the best baseline baseline (Zlib at 46.12%).
  • Efficiency: CAMIA is highly practical. Evaluating 1,000 samples took approximately 38 minutes on a single A100 GPU, compared to 500 minutes for Neighborhood-based attacks, while delivering superior accuracy.

Limitations and Future Work

  • Language Bias: The evaluations were restricted to the English-heavy Pile dataset; how well these context-dependent dynamics translate to multilingual settings remains an open question.
  • API Constraints: The attack requires access to token-level loss/log-probability information. While common in many developer APIs, platforms that completely hide token-level probabilities would mitigate this specific attack vector.
  • Proprietary Models: The authors excluded closed-source models (like GPT-4 or LLaMA variants) because their exact training sets are undisclosed, and existing public benchmarks for them (like WikiMIA) suffer from severe distribution shifts that artificially inflate attack metrics.

Summary updated

BibTeX
@misc{chang2024context,
  author = {Hongyan Chang and Ali Shahin Shamsabadi and Kleomenis Katevas and Hamed Haddadi and Reza Shokri},
  title = {{Context-Aware Membership Inference Attacks against Pre-trained Large Language Models}},
  year = {2024},
  eprint = {2409.13745},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2409.13745},
}
Figure