AttnLRP: Attention-Aware Layer-Wise Relevance Propagation for Transformers
Reduan Achtibat, Sayed Mohammad Vakilzadeh Hatefi, Maximilian Dreyer, Aakriti Jain, Thomas Wiegand, Sebastian Lapuschkin, Wojciech Samek
TL;DR
AttnLRP introduces an attention-aware Layer-Wise Relevance Propagation framework for transformers, deriving faithful rules to propagate relevance through nonlinear attention, MLPs, and normalization with a single backward pass. By leveraging Taylor-based decomposition and specialized rules (ε- and γ-LRP, along with a uniform rule for bilinear matmul and an identity rule for element-wise nonlinearities), it achieves high faithfulness and enables interaction with latent neurons. Experimental results across LLMs (e.g., LLaMa 2, Mixtral 8x7b, Flan-T5) and Vision Transformers demonstrate superior attribution quality compared to baselines, with detailed analyses on latent-feature interpretation and neuron manipulation. The work provides open-source tooling and opens pathways for concept-based explanations and safer, more transparent transformer-based systems in practical settings.
Abstract
Large Language Models are prone to biased predictions and hallucinations, underlining the paramount importance of understanding their model-internal reasoning process. However, achieving faithful attributions for the entirety of a black-box transformer model and maintaining computational efficiency is an unsolved challenge. By extending the Layer-wise Relevance Propagation attribution method to handle attention layers, we address these challenges effectively. While partial solutions exist, our method is the first to faithfully and holistically attribute not only input but also latent representations of transformer models with the computational efficiency similar to a single backward pass. Through extensive evaluations against existing methods on LLaMa 2, Mixtral 8x7b, Flan-T5 and vision transformer architectures, we demonstrate that our proposed approach surpasses alternative methods in terms of faithfulness and enables the understanding of latent representations, opening up the door for concept-based explanations. We provide an LRP library at https://github.com/rachtibat/LRP-eXplains-Transformers.
