Attention Analysis Limitations › Visualizing Attribution Method Agreement
Language AI HandbookAll chapters Attention Analysis Limitations › Visualizing Attribution Method AgreementOne section · Sections in this chapter12 / 16 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The disagreement between attention and gradient-based methods has direct practical consequences beyond theory. We can directly measure it on a synthetic but representative example, showing how different methods rank the same tokens.
The following visualization simulates a scenario common in practice: running multiple attribution methods on the same sentence and comparing their token rankings. Methods that produce similar rankings agree on what the model finds important; methods that produce different rankings give different explanations for the same prediction. This comparison is something every practitioner should run when using interpretability tools for consequential decisions.

The structural and semantic tokens receive dramatically different scores across the four methods. Raw attention assigns 22% of its weight to [CLS] while gradient saliency assigns only 5%. Conversely, "awful" receives 22% from gradient saliency versus only 8% from raw attention. Integrated Gradients and gradient-weighted attention fall between the extremes, with both converging on the importance of "not" and "awful" as the semantically decisive tokens. This convergence between the gradient-based methods, alongside their divergence from raw attention, supports the conclusion that attention is measuring something different from importance.
Now let's quantify the agreement between methods using pairwise rank correlations. This gives a numerical picture of how similar the different attribution methods are in their rankings of token importance.
from scipy.stats import spearmanr
method_data = {
"Raw Attention": raw_attn,
"Gradient Saliency": grad_sal,
"Integrated Gradients": ig_scores,
"Gradient-Weighted Attn": gw_attn,
}
method_names = list(method_data.keys())
method_arrays = list(method_data.values())
n_methods = len(method_names)
# Pairwise Spearman rank correlations
corr_matrix = np.ones((n_methods, n_methods))
for i in range(n_methods):
for j in range(i + 1, n_methods):
rho, _ = spearmanr(method_arrays[i], method_arrays[j])
corr_matrix[i, j] = rho
corr_matrix[j, i] = rhoPairwise Spearman Rank Correlations between Attribution Methods
-----------------------------------------------------------------
Raw Attention Gradient SaliencyIntegrated GradientsGradient-Weighted Attn
Raw Attention 1.000 0.039 -0.091 0.184
Gradient Saliency 0.039 1.000 0.943 0.929
Integrated Gradients -0.091 0.943 1.000 0.890
Gradient-Weighted Attn 0.184 0.929 0.890 1.000
The correlation matrix reveals the structure of the disagreement. The three gradient-based methods (Gradient Saliency, Integrated Gradients, and Gradient-Weighted Attention) show high mutual correlations, indicating that they largely agree on which tokens are important. Raw attention shows systematically lower correlations with all three gradient-based methods, confirming that it is measuring something qualitatively different. This is not a failure of any particular method; it is evidence that attention and gradients are answering different questions about the model's computation.