Quantifying Context Mixing in Transformers

Hosein Mohebbi, Willem Zuidema, Grzegorz Chrupala, Afra Alishahi · DOI

TL;DR

This paper introduces "Value Zeroing," a novel method to quantify how much information from surrounding tokens is mixed into a target token's representation within Transformer encoder blocks. By analyzing the entire encoder block, not just attention weights, Value Zeroing offers a more faithful and interpretable measure of context mixing, outperforming existing methods in various evaluations.

What Problem Does This Paper Address?

Transformers have revolutionized NLP and other fields due to their ability to capture complex relationships between input tokens. A key mechanism for this is self-attention, where attention weights are often used to understand how information flows. However, these raw attention weights are known to be unreliable indicators of a model's actual decision-making process. They can focus on irrelevant tokens and don't account for other crucial components within an encoder layer, like feed-forward networks, which significantly contribute to information mixing. Existing interpretability methods often focus solely on attention or specific parts of the encoder, failing to capture the full picture of how context is integrated into token representations.

Methods

The core contribution is Value Zeroing, a new metric for quantifying context mixing. The approach works by:

  • Targeting the Value Vector: For a specific token j, its value vector (a component in the self-attention mechanism) is zeroed out when computing the context vector for a target token i.
  • Measuring the Impact: The difference between the original context vector and the one computed with token j's value zeroed out is measured using a distance metric (cosine distance was chosen). This difference quantifies how much token i's representation is affected by token j.
  • Holistic Analysis: Unlike previous methods that might only look at attention weights or specific sublayers, Value Zeroing analyzes the output of an entire encoder block, thus incorporating the effects of multi-head attention, residual connections, layer normalization, and feed-forward networks.

Datasets

The primary dataset used is the BLiMP benchmark (Warstadt et al., 2020). This benchmark consists of pairs of minimally different sentences that contrast in grammatical acceptability, isolating specific linguistic phenomena. The authors selected five datasets from BLiMP focusing on grammatical agreement, creating a unified dataset of 4,276 data points for training and testing.

Key Insights and Ideas

  • Beyond Raw Attention: The paper strongly reinforces that raw attention weights are insufficient for understanding information flow and context mixing in Transformers.
  • Holistic Encoder Block Analysis is Crucial: Focusing on the entire encoder block, rather than just attention mechanisms, is key to a more accurate understanding of how context is integrated.
  • Value Vectors Matter: The "value" component in self-attention plays a significant role in how information is mixed, and manipulating it (as Value Zeroing does) provides a powerful interpretability signal.
  • Faithfulness to Model Decisions: Value Zeroing demonstrates higher faithfulness to the model's actual decisions compared to many other methods, meaning its explanations are more aligned with what the model is truly doing.

Key Results

  • Superior Cue Alignment: Value Zeroing consistently shows higher alignment with "cue words" (the critical words determining grammatical correctness in the BLiMP tasks) across all layers and models tested (BERT, RoBERTa, ELECTRA), outperforming baselines like raw attention, attention-rollout, and gradient-based methods.
  • Strong Correlation with Probing: Layer-wise compression scores from probing classifiers (measuring how well representations encode number agreement) are highly positively correlated with Value Zeroing alignment scores. This suggests that when Value Zeroing indicates a token is important for context mixing, its representation is indeed more useful for downstream tasks.
  • Faithfulness: Value Zeroing exhibits the highest correlation with blank-out scores (a measure of a token's influence on the model's final prediction), indicating it is more faithful in explaining model behavior.
  • Qualitative Analysis: In a specific example, Value Zeroing correctly identified the main subject ("pictures") as the most influential cue word for determining agreement, a finding supported by blank-out scores, while other methods highlighted less relevant tokens.

Limitations and Future Work

  • Model Specificity: The proposed method is currently customized for Transformer-based architectures and may not be easily generalized to other modeling architectures.
  • Modality Focus: The evaluations were primarily conducted on text modality. The authors suggest extending experiments to other modalities like speech and vision in the future.
  • No Gold Standard: As with most interpretability methods, the authors acknowledge the inherent difficulty in definitively evaluating their approach due to the lack of a "gold standard" for understanding internal model workings. They rely on complementary evaluation schemes to mitigate this.

Summary updated

BibTeX
@inproceedings{mohebbi2023quantifying,
  author = {Hosein Mohebbi and Willem Zuidema and Grzegorz Chrupala and Afra Alishahi},
  title = {{Quantifying Context Mixing in Transformers}},
  booktitle = {EACL},
  year = {2023},
  doi = {10.18653/v1/2023.eacl-main.245},
}
Figure