The Surprising Effectiveness of Membership Inference with Simple N-Gram Coverage

Skyler Hallinan, Jaehun Jung, Melanie Sclar, Ximing Lu, Abhilasha Ravichander, Sahana Ramnath, Yejin Choi, Sai Praneeth Karimireddy, Niloofar Mireshghallah, Xiang Ren

TL;DR

The N-GRAM COVERAGE ATTACK is a highly effective, fully black-box membership inference attack that determines whether a text document was used to train a language model using only the model's text outputs. Despite lacking access to internal token probabilities or logits, this simple approach matches or even outperforms state-of-the-art white-box attacks while being significantly more compute-efficient than existing black-box alternatives.

What Problem Does This Paper Address?

Auditing large language models (LLMs) for data leakage, privacy violations, or copyright infringement typically relies on Membership Inference Attacks (MIAs)—techniques that guess whether a specific document was part of a model's training data.

Most top-performing MIAs are "white-box," meaning they require access to the model's internal state, such as token logits or loss values. However, the most widely used commercial models (like GPT-4) are strictly "black-box," accessible only via text-generation APIs. Existing black-box MIAs either perform poorly, require expensive external paraphrasing models, or assume the target model is an exceptionally compliant question-answering system. The authors bridge this gap by designing a powerful, low-cost MIA that operates entirely on surface-form text outputs.

Methods

The core intuition behind the N-GRAM COVERAGE ATTACK is simple: language models are far more likely to generate verbatim or highly similar text patterns if they memorized them during training.

Figure 1: A high-level overview of N-GRAM COVERAGE ATTACK, a cost-effective, white-box membership inference attack effective for both open and closed models: (1) attain a short prefix of the candidate document (2) sample continuations given the prefix from the target model (3) compare to the original suffix (4) aggregate similarities to infer membership.

As illustrated in Figure 1, the attack operates in four straightforward steps:

  1. Prefix Extraction: Take a candidate document and split it, using the first half (e.g., 50%) as a prompt prefix.
  2. Diverse Generation: Prompt the target model multiple times ($d$ generations) to complete the text based on the prefix.
  3. N-Gram Similarity Evaluation: Compare the model's generated completions against the hidden ground-truth suffix using simple n-gram overlap metrics (such as standard Coverage, a length-normalized Creativity Index, or Longest Common Substring).
  4. Aggregation: Aggregate these similarity scores across all generations (typically using the max function). If the maximum similarity exceeds a predefined threshold, the document is flagged as a training set "member."

Datasets

The authors evaluated their method across several benchmarks, including two newly introduced datasets designed to address limitations in existing evaluations:

  • BookMIA & WikiMIA: Standard benchmarks consisting of book snippets and Wikipedia articles split by temporal boundaries (pre- vs. post-training cutoffs).
  • WikiMIA2024 Hard (New): A challenging new dataset pairing older versions of Wikipedia articles (likely training members) with post-2024 edited versions of the exact same articles (non-members). This eliminates topical confounding factors present in the original WikiMIA.
  • TÜLU Mix (New): A dataset constructed to specifically evaluate membership inference against fine-tuning data rather than pre-training data.

Key Insights and Ideas

  • Surface Text as a Logit Proxy: Simple n-gram overlaps of raw text outputs serve as a surprisingly robust proxy for internal model likelihoods. You don't need access to complex probability distributions to see what a model has memorized.
  • Performance Scales with Compute: The attack's accuracy scales predictably with the number of sampled sequences. Generating more completions provides a more accurate empirical representation of the model's true output distribution.
  • The "Max" Metric Wins: Using the maximum similarity score across generations works best because false positives (non-members perfectly reconstructing a specific suffix) are rare. The max operator successfully surfaces sparse but strong memorization signals.
  • An Evolving Trend in Privacy: Testing across OpenAI's model timeline revealed that newer models like GPT-4o show a marked drop in MIA vulnerability compared to older models like GPT-4, indicating that model providers are successfully implementing stronger post-training privacy or alignment safeguards.

Key Results

The N-GRAM COVERAGE ATTACK consistently outperformed the leading black-box baseline, DE-COP, across all tested datasets.

MIA performance (AUROC) on WikiMIA benchmarks

As shown in Table 1 (Figure 2), on the standard WikiMIA benchmark, the N-gram attack achieved an average of 95% of the performance of white-box attacks on open-weight LLaMA models. Crucially, on the more rigorous WikiMIA2024 Hard dataset, the N-gram attack actually outperformed white-box methods on several LLaMA variants.

MIA performance (AUROC) on the TÜLU fine-tuning dataset

Furthermore, Table 3 (Figure 3) demonstrates its high accuracy in detecting fine-tuning data on the TÜLU models, where the previous black-box baseline (DE-COP) degraded to near-random performance (around 0.50 AUROC). Beyond accuracy, the N-gram attack proved highly practical, running 2.6× faster on average than DE-COP because it bypasses the need for external paraphrasing models.

Limitations and Future Work

While highly effective, the attack's reliance on generating multiple completions ($d=50$ to $100$ in experiments) means it can incur notable API token costs when auditing commercial models at scale. Additionally, because the attack relies on a prefix-suffix evaluation framework, its current formulation is optimized for sequential text documents and may require adaptation to audit non-sequential data formats or highly structured conversational data.

Summary updated

BibTeX
@inproceedings{hallinan2025surprising,
  author = {Skyler Hallinan and Jaehun Jung and Melanie Sclar and Ximing Lu and Abhilasha Ravichander and Sahana Ramnath and Yejin Choi and Sai Praneeth Karimireddy and Niloofar Mireshghallah and Xiang Ren},
  title = {{The Surprising Effectiveness of Membership Inference with Simple N-Gram Coverage}},
  booktitle = {COLM},
  year = {2025},
  url = {https://openreview.net/forum?id=CNWlNF8VOm},
}
Figure