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

Abstract

Membership inference attacks serves as useful tool for fair use of language models, such as detecting potential copyright infringement and auditing data leakage. However, many current state-of-the-art attacks require access to models' hidden states or probability distribution, which prevents investigation into more widely-used, API-access only models like GPT-4. In this work, we introduce N-Gram Coverage Attack, a membership inference attack that relies solely on text outputs from the target model, enabling attacks on completely black-box models. We leverage the observation that models are more likely to memorize and subsequently generate text patterns that were commonly observed in their training data. Specifically, to make a prediction on a candidate member, N-Gram Coverage Attack first obtains multiple model generations conditioned on a prefix of the candidate. It then uses n-gram overlap metrics to compute and aggregate the similarities of these outputs with the ground truth suffix; high similarities indicate likely membership. We first demonstrate on a diverse set of existing benchmarks that N-Gram Coverage Attack outperforms other black-box methods while also impressively achieving comparable or even better performance to state-of-the-art white-box attacks - despite having access to only text outputs. Interestingly, we find that the success rate of our method scales with the attack compute budget - as we increase the number of sequences generated from the target model conditioned on the prefix, attack performance tends to improve. Having verified the accuracy of our method, we use it to investigate previously unstudied closed OpenAI models on multiple domains. We find that more recent models, such as GPT-4o, exhibit increased robustness to membership inference, suggesting an evolving trend toward improved privacy protections.

Introduction

Membership Inference Attacks (MIAs) are the primary tool for auditing data privacy and copyright infringement in Large Language Models (LLMs). They answer a simple but critical question: Was this specific document used to train this model?

Historically, the most effective MIAs have been "white-box," meaning they require access to the model's internal log-probabilities (logits). However, the most widely used models today (like GPT-4o or Claude) are "black-box"—they only provide text outputs via an API. Existing black-box attacks often struggle with accuracy or require complex setups, like training "shadow models" or using expensive auxiliary LLMs to paraphrase text. This paper addresses the need for a simple, cost-effective, and highly accurate membership inference method that works using only standard text generation.

Methodology: The N-Gram Coverage Attack

The authors introduce the N-GRAM COVERAGE ATTACK, a remarkably straightforward four-step pipeline designed to work with both open and closed models:

  1. Prefixing: Take a candidate document and remove the last $K$ words (the suffix).
  2. Generation: Use the remaining prefix to prompt the target model to generate multiple ($M$) diverse completions.
  3. N-Gram Scoring: Compare these generations to the original ground-truth suffix using simple overlap metrics: Coverage (Cov), Creativity Index (Cre), and Longest Common Substring (LCS).
  4. Aggregation: Combine the scores from all $M$ generations (using the maximum score) to make a final "Member" or "Non-member" prediction.
A high-level overview of the N-GRAM COVERAGE ATTACK pipeline.

Datasets and Experimental Setup

The study evaluates the attack across five diverse datasets:

  • WikiMIA & BookMIA: Standard benchmarks consisting of Wikipedia snippets and book excerpts.
  • WikiMIA-24: An updated version of WikiMIA with more recent data.
  • WikiMIA2024 Hard: A benchmark introduced in this paper that uses different versions of the same Wikipedia articles (pre- and post-edit) to minimize "topical" clues and force the attack to rely purely on memorization.
  • TULU Mix: A dataset designed to test membership inference for fine-tuning data rather than just pre-training data.

Key Results and Insights

The N-GRAM COVERAGE ATTACK consistently outperformed previous black-box methods like DE-COP across all tested models.

Performance vs. White-Box Attacks

As shown in the results for WikiMIA, the attack achieved AUROC scores that were highly competitive with white-box baselines. On LLaMA models, the attack reached roughly 95% of the performance of the best white-box attacks despite having much less information. On the "Hard" version of the Wikipedia benchmark, this text-only attack actually outperformed traditional logit-based attacks, suggesting that for very challenging cases, the act of generation might be a noisier but more robust signal of membership than raw token probabilities.

Results on WikiMIA benchmarks comparing N-GRAM COVERAGE to white-box baselines.

Scaling and Model Robustness

  • Scaling with Compute: Unlike many other attacks, this method gets better the more you use it. Increasing the number of generated samples ($M$) consistently improves the attack's success rate, as it provides a more accurate picture of the model's underlying probability distribution.
  • The GPT-4o Trend: The authors found that newer models like GPT-4o show increased robustness to these attacks compared to GPT-3.5. This suggests that model providers may be successfully implementing unlearning or privacy-preserving techniques during post-training.

Conclusion and Future Work

While the N-GRAM COVERAGE ATTACK is simple and effective, it requires generating dozens of completions per document, which could become expensive for high-volume auditing via paid APIs. Furthermore, the attack relies on the model's tendency to regurgitate text; if a model is trained with extremely high levels of deduplication, the signal might weaken. Future research will investigate how this method performs on non-textual data like code and whether "temperature tuning" during generation could further amplify the membership signal.

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