Alpaca against Vicuna: Using LLMs to Uncover Memorization of LLMs

Aly M. Kassem, Omar Mahmoud, Niloofar Mireshghallah, Hyunwoo Kim, Yulia Tsvetkov, Yejin Choi, Sherif Saad, Santu Rana

TL;DR

Large Language Models (LLMs) often memorize their training data, posing significant privacy and copyright risks. This paper demonstrates that instruction-tuning—the process that makes models helpful and conversational—doesn't actually reduce memorization; it just makes it harder to detect using standard methods. By using an "attacker" LLM to iteratively optimize prompts, the authors uncovered 23.7% more memorized data than previous state-of-the-art techniques.

What Problem Does This Paper Address?

The standard way researchers measure LLM memorization is the "prefix-suffix" attack: you give the model the first few words of a training sequence and see if it can complete the rest. While this works well for "base" models, instruction-tuned models (like Vicuna or Alpaca) often appear to have "forgotten" this data because they are trained to follow instructions rather than just complete text.

The authors argue that this gives a false sense of security. The memorized data is still there in the model's weights; we just aren't asking for it correctly. The challenge is to find instruction-based prompts that trigger this latent memory without simply "cheating" by putting the answer in the prompt itself.

Methods

The authors propose a black-box prompt optimization method where one LLM (the attacker) tries to extract data from another (the victim).

Figure 1: Overview of our method: we first create an initial prompt that turns the target training sequence into an instruction. The attacker LLM uses this prompt to generate multiple candidate prompts designed to make the victim LLM produce responses that closely match the training data. We score each candidate based on two criteria: (1) the overlap between the victim’s response and the training data (higher is better) and (2) the overlap between the candidate prompt and the training data (lower is better to avoid revealing the solution). This score guides the attacker in optimizing and generating new prompts for further rounds of optimization.

As shown in Figure 1, the process involves an iterative feedback loop:

  1. Initialization: A "meta-prompt" (often generated by GPT-4) turns a training sequence into a basic instruction.
  2. Interactive Sampling: An attacker model (Zephyr 7B) generates multiple candidate paraphrases of the prompt.
  3. Scoring: Each candidate is scored by a reward function that balances two goals:
  4. Maximize Output Overlap: The victim's response should match the ground-truth training data as closely as possible.
  5. Minimize Prompt Overlap: The prompt itself should not look like the training data, ensuring the model is actually "remembering" and not just repeating the input.
  6. Refinement: The best-performing prompt is used as the starting point for the next round of optimization.

The authors also developed a practical classifier-based attack that doesn't require access to the ground-truth data during the attack phase, making it more representative of a real-world threat.

Datasets

The study evaluated memorization across a wide range of domains and models:

  • Pre-training Data: Samples from Llama (C4, CC, Arxiv, Books, Github), Falcon’s RefinedWeb, and OLMo’s Dolma (including Reddit and Stack Overflow).
  • Copyrighted Material: Excerpts from the Harry Potter series, the Books3 dataset, and New York Times articles.
  • Models: They tested various sizes (7B to 30B) of Llama-based models (Alpaca, Vicuna, Tulu), OLMo, and Falcon, as well as closed models like GPT-4o.

Key Insights and Ideas

  • Instruction-Tuning is a Mask, Not a Cure: The study proves that instruction-tuning doesn't erase training data; it merely changes the "trigger" required to access it.
  • Adversarial Contexts are More Effective: Standard prefixes are poor triggers for aligned models. Instead, prompts that describe the context or intent of the data (e.g., "Illustrate the scene where Harry gets his letter") are far more successful at inducing regurgitation.
  • Cross-Model Attacks: Using a different model as an attacker (e.g., Zephyr attacking Vicuna) is more effective than having a model attack itself.
  • Unlearning is Fragile: The authors successfully extracted Harry Potter text from a model specifically fine-tuned to "unlearn" that content, suggesting that current unlearning techniques are vulnerable to adversarial prompting.

Key Results

  • Higher Extraction Rates: The method achieved 23.7% more overlap with training data compared to standard prefix-suffix baselines.
  • Efficiency: Their black-box approach is significantly faster than white-box alternatives like Greedy Coordinate Gradient (GCG), taking roughly 1.3 minutes per sample compared to 12 minutes for GCG.
  • Bypassing Refusals: While GPT-4o often refuses to complete a text sequence (refusal rates of ~26%), it almost never refuses the optimized instruction-based prompts (0% refusal), as seen in the Harry Potter case study.
  • Copyright Leakage: The method achieved 39% more extraction on copyrighted datasets like Books3 and NYT compared to simple prompting.
Figure 2: Comparison of our method to the GCG, P-S baseline, and P-S-instruction on the Llama and its instruction- tuned versions. We evaluate different subsets of the pre-training data and observe that our method consistently outperforms the GCG and prefix-suffix baseline.

As illustrated in Figure 2, the "Ours" method (dark grey) consistently outperforms standard baselines across all tested domains (Github, Arxiv, C4, etc.) and sequence lengths.

Limitations and Future Work

The primary limitation is that the "upper bound" version of the attack requires access to the training data to calculate the reward. While the authors introduced a classifier to mitigate this, the classifier's performance (70% F1 score) leaves room for improvement.

Future work includes developing fully automated strategies that don't require any prior knowledge of the training set and exploring more robust defense mechanisms beyond simple instruction-tuning or fragile unlearning techniques.

Summary updated

Abstract

In this paper, we introduce a black-box prompt optimization method that uses an attacker LLM agent to uncover higher levels of memorization in a victim agent, compared to what is revealed by prompting the target model with the training data directly, which is the dominant approach of quantifying memorization in LLMs. We use an iterative rejection-sampling optimization process to find instruction-based prompts with two main characteristics: (1) minimal overlap with the training data to avoid presenting the solution directly to the model, and (2) maximal overlap between the victim model's output and the training data, aiming to induce the victim to spit out training data. We observe that our instruction-based prompts generate outputs with 23.7% higher overlap with training data compared to the baseline prefix-suffix measurements. Our findings show that (1) instruction-tuned models can expose pre-training data as much as their base-models, if not more so, (2) contexts other than the original training data can lead to leakage, and (3) using instructions proposed by other LLMs can open a new avenue of automated attacks that we should further study and explore. The code can be found at https://github.com/Alymostafa/Instruction_based_attack .
BibTeX
@inproceedings{kassem2025alpaca,
  author = {Aly M. Kassem and Omar Mahmoud and Niloofar Mireshghallah and Hyunwoo Kim and Yulia Tsvetkov and Yejin Choi and Sherif Saad and Santu Rana},
  title = {{Alpaca against Vicuna: Using LLMs to Uncover Memorization of LLMs}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.naacl-long.421},
}
Figure