ContextCite: Attributing Model Generation to Context

Benjamin Cohen-Wang, Harshay Shah, Kristian Georgiev, Aleksander Madry

ContextCite is a simple, scalable method for context attribution—identifying exactly which parts of an input context caused a language model to generate a specific statement. By training a sparse linear surrogate model on a small number of context "ablations," ContextCite can verify model claims, improve response quality by filtering out noise, and detect adversarial poisoning attacks with high accuracy.

The Challenge of Context Attribution

When using Retrieval-Augmented Generation (RAG), language models are provided with external articles to ground their answers. However, it is often unclear whether a model’s response is genuinely based on that context, hallucinated from pre-training data, or a flat-out misinterpretation of the provided text.

Existing "citation" methods typically focus on corroborative attribution: finding text that supports a claim. But what if the model misreads the text? A corroborative method might find no support, failing to explain why the model made the mistake. To address this, the authors introduce contributive attribution: pinpointing the specific parts of the context that actually led the model to its conclusion, regardless of factual correctness.

ContextCite traces a generated statement back to the specific context responsible for it.

How ContextCite Works

ContextCite treats context attribution as a data modeling problem. Rather than inspecting internal model weights (like attention mechanisms), it observes how the model's output changes when parts of the context are removed.

  1. Ablation Sampling: The method creates multiple versions of the context, removing random subsets of "sources" (typically sentences).
  2. Probability Measurement: For each ablated version, it measures the probability of the model generating the original statement.
  3. Surrogate Modeling: It trains a sparse linear surrogate model (using LASSO) to predict the logit-scaled probability of the statement based on the presence or absence of specific sources.
  4. Attribution Scores: The learned weights of this linear model serve as the attribution scores. A high weight indicates that a source was critical to generating the statement.
The linear surrogate model faithfully captures how removing specific sources affects the model's output probability.

The efficiency of ContextCite relies heavily on LASSO. Because most generated statements depend on only a tiny fraction of the total context (context sparsity), LASSO can accurately model these dependencies with as few as 32 additional inference passes.

Key Insights and Results

The researchers evaluated ContextCite across diverse benchmarks, including TyDi QA, Natural Questions, Hotpot QA, CNN DailyMail, MS MARCO, and DROP.

  • Superior Attribution: ContextCite consistently outperformed baselines like attention weights, gradient norms, and semantic similarity across various models (Llama-3, Phi-3, Mistral). The paper demonstrates that raw attention weights are often unreliable for attribution, making ContextCite's black-box ablation approach much more robust.
  • Self-Verification: By using ContextCite to show a model its own "causal" sources, the model's ability to judge the correctness of its own answers significantly improved.
  • Context Pruning: Identifying the most relevant sources allows for "pruning" the rest. Regenerating responses with this filtered context reduces the distraction of irrelevant information, leading to higher accuracy.
  • Poisoning Detection: In scenarios involving "indirect prompt injection" (where malicious text is hidden in the context), ContextCite successfully identified the poisonous source as the top contributor over 95% of the time.

Limitations and Future Work

While highly effective, ContextCite has a few limitations:

  • Redundancy: If multiple parts of the context contain identical information, removing just one might not significantly change the output probability, potentially leading to artificially low attribution scores for both.
  • Indirect Attribution: If statement B depends on statement A, which in turn depends on the context, ContextCite may struggle to link statement B directly back to the original context.
  • Computational Cost: Although 32 inference passes is sample-efficient for research, it remains 32x more expensive than a single generation, which could be a bottleneck for real-time production.
  • Sentence Dependencies: Arbitrarily removing sentences can disrupt grammatical flow or coreference (e.g., removing a pronoun's definition), potentially confusing the model for reasons unrelated to the actual information content.

Summary updated

BibTeX
@inproceedings{cohenwang2024contextcite,
  author = {Benjamin Cohen-Wang and Harshay Shah and Kristian Georgiev and Aleksander Madry},
  title = {{ContextCite: Attributing Model Generation to Context}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=7CMNSqsZJt},
}
Figure