Introduction
In the field of Natural Language Processing, Transformer-based models like BERT and RoBERTa have become the standard for understanding and generating text. However, the internal mechanisms that drive their decision-making processes remain partially opaque. A critical question in model interpretability is how these architectures handle "outliers"—words that are grammatically or semantically out of place. This paper, "Attention-likelihood relationship in transformers," investigates this by analyzing the relationship between a token's likelihood and the self-attention it receives.
The Problem: Understanding Transformer Robustness
While we understand that Transformers use attention heads to identify linguistic patterns (such as punctuation or syntax), we know less about how they react to noisy or nonsensical input. If a model encounters a word that does not belong in a specific context, how does it process that information? Understanding this relationship is vital for developing AI that can maintain performance when faced with real-world, noisy data.
Methodology: Likelihood-Guided Perturbation
To probe the model's internal logic, the researchers developed a "likelihood-guided perturbation" strategy. The process involved four key steps:
- Baseline Establishment: The researchers recorded the likelihood of words and their corresponding attention maps in a set of standard, coherent sentences.
- Perturbation: They replaced a single target word in each sentence with a "perturbed" token—a word with a very low probability of appearing in that specific context.
- Comparison: They analyzed the shift in attention between the original sentence and the nonsensical version.
- Aggregation: To simplify the analysis across multiple attention heads, they used mean pooling to aggregate attention into a single value per layer.
This methodology was applied to several prominent encoder-only models, including BERT-base, RoBERTa (base and large), DistilBERT, and XLM-R.
Experimental Setup and Datasets
The study utilized a dataset of approximately 20,000 English sentences sourced from WordNet. To ensure the validity of the results, the researchers applied specific selection criteria:
- Sentences had to be longer than five tokens.
- Target words for perturbation were restricted to "meaningful" words, excluding common stopwords (e.g., "the," "and") to prevent statistical bias.
- Models were sourced from the HuggingFace library to ensure reproducibility.
Key Insights: The Self-Correction Mechanism
1. The "Ignore the Outlier" Strategy
The most striking discovery is that when a Transformer encounters a low-likelihood word, it effectively "nullifies" that word's contribution. The model stops attending to the word itself ($A_{ii}$) and redirects that attention elsewhere.
2. Uniform Redistribution
Rather than shifting attention to another specific "important" word, the model spreads the redirected attention uniformly across the surrounding context. This suggests that when the model cannot make sense of a token, it looks at the entire surrounding environment to infer what should have been there.
3. Layer Hierarchy
This behavior is not uniform across the model's architecture. In early layers, the model continues to rely on the token itself to establish its basic identity. However, in deeper layers—which are responsible for processing abstract semantics—the correlation between a token's likelihood and the attention it receives becomes significantly stronger.
Quantitative Results
The researchers used the Spearman correlation ($\rho$) to quantify the relationship between likelihood and attention. The results were statistically significant across all models tested:
- Correlation Jump: In RoBERTa-large (layer 23), the average correlation $\rho$ rose from 0.183 in standard text to 0.823 in perturbed text.
- Attention Drop: In RoBERTa-base, the mean "token attention" (the degree to which a word attends to itself) plummeted from 0.124 to 0.043 when the word was replaced with an unlikely alternative.
- Statistical Validation: Using the Mann-Whitney U test, the authors confirmed that these shifts in attention distribution were not random but represented a fundamental change in how the model processes information.
Limitations and Future Directions
While this study provides a clear look at encoder-only models, several questions remain:
- Architectural Scope: It is currently unknown if decoder-only models (like GPT-4) or encoder-decoder models (like T5) utilize the same "ignore and redistribute" strategy.
- Downstream Impact: The study focuses on internal attention shifts but does not measure how these shifts specifically impact final task performance, such as sentiment analysis accuracy.
- Cross-Modal Application: The authors suggest this methodology could be extended to Vision Transformers (ViTs) to determine if models ignore "out-of-place" pixels in images similarly to how they ignore out-of-place words in text.
Summary updated