Better Explain Transformers by Illuminating Important Information

Linxin Song, Yan Cui, Ao Luo, Freddy Lécué, Irene Li

Abstract

Transformer-based models excel in various natural language processing (NLP) tasks, attracting countless efforts to explain their inner workings. Prior methods explain Transformers by focusing on the raw gradient and attention as token attribution scores, where non-relevant information is often considered during explanation computation, resulting in confusing results. In this work, we propose highlighting the important information and eliminating irrelevant information by a refined information flow on top of the layer-wise relevance propagation (LRP) method. Specifically, we consider identifying syntactic and positional heads as important attention heads and focus on the relevance obtained from these important heads. Experimental results demonstrate that irrelevant information does distort output attribution scores and then should be masked during explanation computation. Compared to eight baselines on both classification and question-answering datasets, our method consistently outperforms with over 3% to 33% improvement on explanation metrics, providing superior explanation performance. Our anonymous code repository is available at: https://anonymous.4open.science/r/MLRP-E676/

Introduction

While Transformers have become the backbone of modern NLP, they remain largely "black boxes." To build trust and ensure safety, researchers use token attribution to identify which input words most influenced a specific prediction. However, existing methods often rely on raw attention weights or gradients across all attention heads. Because Transformers contain many heads that focus on noise or irrelevant patterns, these standard explanations often become diluted, highlighting unimportant tokens and confusing human interpreters. This paper introduces Mask-LRP, a method designed to "illuminate" core information flows while "eliminating" the noise.

Methodology: Mask-LRP

The researchers propose a refined version of Layer-wise Relevance Propagation (LRP). LRP typically redistributes a model's output relevance backward through its layers to the input tokens. Mask-LRP improves this by introducing a Head Mask ($M$) that filters the backward flow.

Identifying Important Heads

The method identifies two primary types of "important" heads based on dataset-wide statistics:

  1. Syntactic Heads: These heads consistently track core grammatical relations, such as subjects (nsubj), direct objects (dobj), and modifiers (amod, advmod).
  2. Positional Heads: These heads focus on fixed relative positions, such as the immediate previous or next token.

Refined Information Flow

During the backward pass, the mask $M$ is applied to zero out relevance flowing through heads deemed unimportant. A normalization step ensures that total relevance is conserved, maintaining the mathematical integrity of the attribution scores while focusing them on the most semantically and syntactically meaningful pathways.

The Mask-LRP framework redistributes relevance through a refined information flow, masking irrelevant attention heads to produce cleaner attribution scores.

Experimental Setup

The method was evaluated on seven benchmarks, including sentiment classification (SST-2, IMDB, Yelp), sentence pair tasks (QQP, MNLI), and question answering (SQuAD v1/v2). The authors tested Mask-LRP against eight strong baselines, including Rollout, GAE, and AttCAT, using models like BERT-base, GPT-2, and RoBERTa.

Key Results and Insights

Quantitative Performance

Mask-LRP consistently outperformed all baselines across metrics like AOPC (Area Over the Perturbation Curve) and LOdds:

  • Classification: Achieved a 3.56% improvement in identifying influential tokens.
  • Question Answering: Demonstrated a massive 33.02% improvement in Precision@20, indicating that the highlighted tokens were significantly more relevant to the ground-truth answers.

The Impact of Noise

A key finding was that even a random mask (keeping the same number of heads but choosing them arbitrarily) often outperformed standard baselines. This confirms that "irrelevant" information in Transformers is not just neutral but actively destructive to explanation quality.

Qualitative Clarity

Visualizations demonstrate that Mask-LRP produces much sharper attributions. For example, in sentiment analysis, it correctly highlights descriptive adjectives and their modifiers while ignoring filler words or punctuation that often trip up other methods.

Qualitative comparison showing how Mask-LRP (Ours) highlights meaningful tokens like "charming" more effectively than baselines, which often assign relevance to irrelevant tokens or punctuation.

Conclusion

By filtering out the noise from irrelevant attention heads, Mask-LRP provides a more accurate and human-interpretable window into Transformer decision-making. The discovery that positional heads dominate early layers while syntactic heads cluster in later layers further illuminates the internal logic of these models. Future work will extend these findings to Large Language Models (LLMs) to see if these patterns hold at greater scales.

Summary updated

BibTeX
@inproceedings{song2024better,
  author = {Linxin Song and Yan Cui and Ao Luo and Freddy Lécué and Irene Li},
  title = {{Better Explain Transformers by Illuminating Important Information}},
  booktitle = {EACL (Findings)},
  year = {2024},
  url = {https://openreview.net/forum?id=NO04TflFrY},
}
Figure