Learning to Attribute with Attention

Benjamin Cohen-Wang, Yung-Sung Chuang, Aleksander Madry
4/18/2025
15 citations
cs.LGcs.CL
transformer-attention

Official code: MadryLab/AT2 (29 stars, Jupyter Notebook, MIT, last commit 2025-04-22).

Abstract

Given a sequence of tokens generated by a language model, we may want to identify the preceding tokens that influence the model to generate this sequence. Performing such token attribution is expensive; a common approach is to ablate preceding tokens and directly measure their effects.

Show full abstract

To reduce the cost of token attribution, we revisit attention weights as a heuristic for how a language model uses previous tokens. Naive approaches to attribute model behavior with attention (e.g., averaging attention weights across attention heads to estimate a token's influence) have been found to be unreliable. To attain faithful attributions, we propose treating the attention weights of different attention heads as features. This way, we can learn how to effectively leverage attention weights for attribution (using signal from ablations). Our resulting method, Attribution with Attention (AT2), reliably performs on par with approaches that involve many ablations, while being significantly more efficient. To showcase the utility of AT2, we use it to prune less important parts of a provided context in a question answering setting, improving answer quality. We provide code for AT2 at https://github.com/MadryLab/AT2 .

View on arXivView PDF

Code Implementations(1)

MadryLab/AT2Official100%
MIT

Attribute statements generated by LLMs to preceding tokens using attention weights.

291Jupyter Notebook, PythonApr 5, 20251 years agoMIT

Similar Papers

Cite this paper

@article{cohenwang2025learning,
  title  = {Learning to Attribute with Attention},
  author = {Benjamin Cohen-Wang and Yung-Sung Chuang and Aleksander Madry},
  year   = {2025},
  eprint = {2504.13752},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2504.13752v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2504.13752.svg)](https://codeofpaper.com/paper/2504.13752)

Discussion