JoPA: Explaining Large Language Model's Generation via Joint Prompt Attribution

Yurui Chang, Bochuan Cao, Yujia Wang, Jinghui Chen, Lu Lin · Submission to ICLR 2025 · Withdrawn

TL;DR

Large Language Models (LLMs) are incredibly powerful text generators, but understanding which specific parts of an input prompt caused a particular output remains a major challenge. This paper introduces JoPA (Joint Prompt Attribution), a framework that identifies the most influential combinations of input tokens by treating prompt attribution as a discrete optimization problem. JoPA is not only more faithful to the model's true behavior than existing methods, but it is also over 70x faster when analyzing long-context prompts.

What Problem Does This Paper Address?

As LLMs are deployed in high-stakes environments, we need to know why they generate what they do. If a model outputs a harmful or biased response, which exact words in the prompt triggered it?

Historically, feature attribution methods were designed for classification tasks or simple next-word prediction. When applied to full-sequence generation, existing methods (like Captum) typically evaluate tokens independently. They delete one token at a time and measure how much the output changes.

The authors point out a glaring flaw in this approach: semantic interaction. If a prompt says, "Write a story about a doctor and his patient," the words "doctor" and "patient" are highly correlated. If you delete just "doctor," the LLM can still infer the medical context from "patient" and generate a nearly identical story. Consequently, independent attribution methods will incorrectly assign a low importance score to "doctor."

Comparison of attribution methods showing JoPA capturing semantic clusters while Captum highlights isolated tokens.

To truly understand the prompt's influence, we must evaluate the joint combinatorial effect of tokens. However, exhaustively searching all possible token combinations in a long prompt is computationally impossible.

Methods

To solve this, the authors frame prompt attribution as a discrete combinatorial optimization problem. The goal is to find a binary mask (removing $k$ tokens from the input) that maximizes the drop in the probability of the LLM generating its original output.

Because the search space is massive, they introduce the JoPA (Joint Prompt Attribution) algorithm, which uses a clever probabilistic search strategy:

  1. Gradient-Guided Masking: Instead of starting blind, JoPA calculates the gradient of the generation loss with respect to the input tokens. It uses the magnitude of these gradients to make an educated initial guess of the top-$k$ most important tokens.
  2. Probabilistic Search Update: Pure gradient methods struggle with discrete text (you can't have "half" a token). JoPA uses the gradient magnitudes to weight the probabilities of swapping masked and unmasked tokens. It iteratively samples new masks, tests them, and keeps the swap if it successfully lowers the model's ability to generate the original output.
The JoPA framework, illustrating the gradient-guided probabilistic search for optimal token masking.

This hybrid approach avoids the massive computational cost of exhaustive search while escaping the rounding errors of purely continuous gradient-descent methods.

Datasets

The authors evaluated JoPA using long-context prompts (15+ words) across three diverse text generation datasets:

  • Alpaca: A general instruction-following dataset.
  • tldr_news: A dataset for abstractive text summarization.
  • MHC (Mental Health Counseling): A dataset featuring long-context questions and advice from online therapy platforms.

Key Insights and Results

The authors tested JoPA on LLaMA-2 (7B-Chat) and Vicuna (7B), revealing several major advantages over existing methods:

  • Combinatorial Effects are Crucial: LLMs are highly robust to minor deletions. You have to mask out entire semantic clusters (e.g., both "publishing" and "book") to actually disrupt the model's generation path. JoPA successfully captures these joint interactions where prior methods fail.
  • Superior Faithfulness: Compared to baselines (Random, Attention, Integrated Gradients, Captum), removing the tokens identified by JoPA caused the most drastic changes to the output. For example, on the MHC dataset, JoPA achieved a much lower BLEU score (0.575 vs Captum's 0.640) and a higher KL-divergence, proving it successfully found the true load-bearing tokens.
  • Massive Speedup: Because Captum evaluates tokens sequentially, its compute time scales terribly with prompt length. On the Alpaca dataset, Captum took an average of 1,169 seconds per prompt. JoPA took just 15.2 seconds—a ~76x speedup. On longer datasets (MHC), the speedup exceeded 120x.
  • Security and Debugging Utility: JoPA isn't just for academic curiosity. In a practical security test, JoPA successfully detected 91% of malicious adversarial prompts by identifying the unnatural trigger tokens driving the unsafe generation. It can also help developers debug prompts by showing exactly which instructions an LLM is paying attention to.

Limitations and Future Work

The authors acknowledge that while JoPA provides highly accurate counterfactual explanations (i.e., "if we remove these tokens, the output changes"), the underlying generation mechanism of the LLM remains a black box. JoPA highlights the inputs that matter, but it does not explain the internal circuitry or how the model processes those tokens. Future work will aim to extend this framework to explore the internal mechanistic aspects of LLM generation.

Summary updated

BibTeX
@misc{chang2024jopa,
  author = {Yurui Chang and Bochuan Cao and Yujia Wang and Jinghui Chen and Lu Lin},
  title = {{JoPA: Explaining Large Language Model's Generation via Joint Prompt Attribution}},
  year = {2024},
  eprint = {2405.20404},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2405.20404},
}
Figure