Skip to content

Spurious attention heads in vision transformers: mechanistic identification of annotation-driven bias in medical chest X-ray analysisSpurious Attention Heads in Vision Transformers: Mechanistic Identification of Annotation-Driven Bias in Medical Chest X-Ray Analysis

arXiv: Interpretability· arXiv:2610.21638· Joshua Muhumuza, Cornelius KalenziMakerere UniversityIndexed by this site · 2026-10-16· Originally publishedAlignment

Quick read

Interpretability

Based on the paper PDF (generated by Gemini); refer to the original

The author analyzed ViT and found that in 62% of COVID-19 chest X-rays, L8H10 attends to corner text, and ablation does not produce specific changes in output.

Questions
Medical vision Transformers readily exploit spurious correlations such as text labels in chest X-ray classification, but the internal mechanism has not been localized, and conventional behavioral evaluations cannot detect it.
Methods
By systematically scanning attention heads for entropy, distance, and max patch weight to localize abnormal heads, using mean masking and inpainting for causal validation, and evaluating ablation effects on fine-tuned models.
Experiments and results
Across 200 COVID-19 chest X-rays, L8H10 attends to corner text on 62% of images; however, ablating this circuit with either single-head or multi-head ablation produced no specific change in downstream predictions.
Limitations and future work
The corner region setting is based on current data annotation conventions; fine-tuning experiments use only 200 images; not tested on other medical modalities such as CT or retinal images, nor on architectures like Swin.
Experimental setupViT-Base/16 (google/vit-base-patch16-224)、DeiT-Base et al. · COVID-19 Chest X-ray Dataset、NIH ChestX-ray14 et al. · Entropy、Mean attention distance et al.
Evaluated models
ViT-Base/16 (google/vit-base-patch16-224)DeiT-BaseViT-Large/16codewithdark/vit-chest-xraylxyuan/vit-xray-pneumonia-classification
Benchmarks
COVID-19 Chest X-ray DatasetNIH ChestX-ray14CheXpertPneumonia dataset
Metrics
EntropyMean attention distanceMax single-patch attentionCorner/lung ratioSpurious ratePrediction change rateConfidence shift
AI summaryUsing mechanistic interpretability, the paper localizes an attention head L8H10 in ViT-Base/16 that specifically reads annotations. In 62% (123) of 200 COVID-19 chest X-rays, it attends to corner text rather than lung pathology; the corner-to-lung attention ratio is 57.5× for affected images and 0.77× for normal images. Using two types of causal interventions—mean masking and OpenCV inpainting—the authors confirm that annotation content, not brightness or edge density, drives this behavior; removing annotations increases lung attention by 1.52× (p<0.0001) in affected images. The phenomenon reproduces on NIH ChestX-ray14 (79%), DeiT-Base (88%), and ViT-Large/16 (80%), and is described as a consistent property of the ViT architecture family.

Using mechanistic interpretability, the paper localizes an attention head L8H10 in ViT-Base/16 that specifically reads annotations. In 62% (123) of 200 COVID-19 chest X-rays, it attends to corner text rather than lung pathology; the corner-to-lung attention ratio is 57.5× for affected images and 0.77× for normal images. Using two types of causal interventions—mean masking and OpenCV inpainting—the authors confirm that annotation content, not brightness or edge density, drives this behavior; removing annotations increases lung attention by 1.52× (p<0.0001) in affected images. The phenomenon reproduces on NIH ChestX-ray14 (79%), DeiT-Base (88%), and ViT-Large/16 (80%), and is described as a consistent property of the ViT architecture family.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    The authors state that medical ViTs have shortcut attention heads that read corner text, and that this spurious circuit cannot be detected by conventional behavioral evaluations at the output level.

    Core problem: chest X-ray vision transformer models rely on non-pathological corner text labels during classification, forming shortcut learning, and this internal circuit is difficult to detect by conventional evaluation at the model output level.

    • Clinical deployment scenario and importance: the authors state that medical ViT models are often pretrained in high-resource referral centers and then directly transferred to primary hospitals or mobile screening vehicles with different equipment and scan annotation formats; if the model reads corner device codes rather than lung pathological features, it may silently fail during cross-institutional transfer.
    • Limitations of existing interpretability tools: the authors state that post-hoc interpretation tools such as Grad-CAM, attention rollout, and LIME only show where the model attends, cannot identify which specific internal component causes the shortcut, and cannot establish causality to support intervention.
    • Mechanistic interpretability analysis approach: the authors apply mechanistic interpretability to medical ViTs, hypothesizing that shortcuts are implemented by specific internal attention circuits; through layer-wise attention scanning, they localize specific attention heads and find that this circuit is hidden from output-level ablation.
    • Proposed analysis framework: the paper proposes a three-stage analysis pipeline (Figure 1), sequentially performing abnormal attention head identification, statistical feature characterization, and causal validation based on activation patching.
  2. What related research exists?

    The paper reviews work on medical AI shortcuts, mechanistic interpretability, and medical ViT interpretation, pointing out that relevance-based explanations cannot localize internal causal components and mechanisms.

    The paper reviews and discusses related work along the following three dimensions:

    Spurious correlations and shortcut learning in medical AI

    • Geirhos et al. (2020): established that deep neural networks generally prefer texture over shape.
    • DeGrave et al. (2021): pointed out that COVID-19 classifiers learned hospital acquisition artifacts rather than pathological features.
    • Zech et al. (2018): pointed out that pneumonia classifiers exhibit shortcut learning based on token-level markers. The authors note that these works established the existence of shortcut phenomena but did not clarify the internal mechanisms.

    Mechanistic interpretability

    • Olah et al. (2020): identified interpretable computational units such as curve detectors and frequency filters in convolutional neural networks.
    • Elhage et al. (2021, 2022): extended mechanistic analysis to Transformers and identified induction head circuits; proposed the superposition theory, explaining how models encode more features than their dimensions.
    • Dosovitskiy et al. (2021), Raghu et al. (2021), and Joseph et al. (2024): Dosovitskiy et al. proposed the ViT architecture; Raghu et al. compared representation differences between ViT and CNN; Joseph et al. developed the ViT-Prisma toolkit. The authors state that no prior report has mechanistically localized circuits implementing spurious correlations in medical ViTs.

    Interpretability of medical vision transformers

    • Chefer et al. (2021): improved attention rollout by incorporating relevance propagation.
    • Barekatain et al. (2025): pointed out that various interpretability methods produce substantially inconsistent explanations on medical ViTs. The authors note that relevance-based interpretability is insufficient to support intervention and cannot specify which component causes the shortcut.

    Baselines and benchmarks

    • The paper uses the remaining 143 attention heads in the network as control baselines when screening abnormal heads; uses a uniform random distribution (0.0051/patch) as the baseline for attention distribution; uses the non-ablated baseline (0.0% prediction change rate) as a control in single-head and multi-head ablation experiments; evaluation is based on the COVID-19 and NIH ChestX-ray14 datasets.

    The authors note that this work differs from existing work by directly localizing the internal components implementing the shortcut and completing causal validation, while also pointing out the structural blind spot of output-level evaluation for representation-level shortcuts.

  3. How does the paper address this problem?

    The authors localize abnormal heads using attention entropy, spatial distance, and maximum weight, validate causality with masking and inpainting, and perform single-head and multi-head ablation experiments.

    The paper proposes a Three-Stage Analysis Pipeline for medical vision transformers, covering abnormal attention head identification, statistical feature characterization, and causal ablation validation.

    Problem Setting and Network Architecture

    • The model uses ViT-Base/16 pretrained on ImageNet-21k, with 12 layers, 12 attention heads per layer, totaling 144 heads. Input images are resized to 224×224, divided into 196 16×16 patches plus 1 CLS token.
    • The base dataset is the COVID-19 Chest X-ray Dataset containing 200 chest X-rays, with images containing real patient identifiers, hospital labels, and other acquisition metadata.

    Abnormal Attention Head Screening Metrics

    • Extract attention tensors from all 12 layers, computing attention weights over 196 patches for each attention head on the CLS token.
    • Define an entropy metric to measure focus: H = −∑i ai log(ai + ε), where ai is the attention weight for patch i, and ε is a constant to prevent logarithm divergence; lower values indicate more focused attention.
    • Define mean attention distance, using the weighted average spatial distance between attended patches to distinguish local from global attention.
    • Define max single-patch attention, the peak softmax weight on a single patch, as the primary anomaly signal.
    • Define the corner/lung ratio, dividing the average attention in the top-left 3×3 patch region by the average attention in the central 6×6 region; a ratio greater than 2 defines a spurious sample.

    Causal Validation and Intervention Design

    • Mean-value masking: replace the top-left 56×56 pixel region with the average pixel intensity, re-infer and compare attention changes.
    • Inpainting: use the Telea fast marching algorithm to inpaint the top-left 56×56 region, filling with real surrounding tissue texture, to eliminate interference from the high-contrast gray block.

    Ablation Experiment Design and Statistical Tests

    • Zero out specific heads in fine-tuned classifiers, including single-head ablation (L8H10) and three-head joint ablation (L8H10, L7H2, L9H3).
    • Between-group comparisons use two-tailed Mann-Whitney U test; paired before-after comparisons use two-tailed Wilcoxon signed-rank test; significance level set at α=0.05.
  4. What experiments did the paper conduct?

    Experiments localized spurious heads across three architectures and two datasets, inpainting validated causality, but neither single-head nor multi-head ablation produced specific prediction changes.

    Experimental Setup

    • Models under test: pretrained ViT-Base/16 (google/vit-base-patch16-224), cross-architecture replication models DeiT-Base and ViT-Large/16; downstream classification fine-tuned models codewithdark/vit-chest-xray (a five-class model trained on CheXpert: cardiomegaly, edema, consolidation, pneumonia, no findings) and lxyuan/vit-xray-pneumonia-classification (a pneumonia binary classification model).
    • Datasets: COVID-19 Chest X-ray Dataset (200 images); cross-dataset validation uses NIH ChestX-ray14 (200 images, original dataset has 112,120 chest X-rays); fine-tuning data includes CheXpert and pneumonia datasets.
    • Baselines and controls: the remaining 143 attention heads in the network; uniform random attention baseline (0.0051 per patch); non-ablated baseline state (prediction change rate 0.0%).
    • Evaluation metrics: attention entropy (nats), mean attention distance, max single-patch attention weight, corner/lung ratio, spurious rate, prediction change rate, confidence shift.
    • Review and judgment methods: corner/lung ratio greater than 2 is judged as a spurious sample; statistical tests use two-tailed Mann-Whitney U test and two-tailed Wilcoxon signed-rank test, with significance threshold set at α=0.05.
    • Sample size and fine-tuning parameters: main analysis and ablation sample sizes are n=200 each; partial fine-tuning updates the last two layers and classification head for 5 epochs (AdamW, learning rate 2e-5); full fine-tuning updates all 12 layers for 15 epochs (base learning rate 2e-5, decay rate 0.85 toward input layers, cosine annealing, gradient clipping 1.0).

    Main Results

    Swipe horizontally to read the table

    ModelAbnormal attention headSpurious rateBetween-group separation multipleSpurious group meanNormal group mean
    ViT-Base/16L8H1062%74.8×57.5×0.77×
    DeiT-BaseL9H288%10.6×11.8×1.11×
    ViT-Large/16L8H880%30.5×16.2×0.53×

    (Data from Table 5, n=200 per group, Mann-Whitney U test p<0.0001)

    • Network-wide anomaly concentration: the authors state that L8H10 in ViT-Base/16 has the largest single-patch attention weight of 0.346, 2.8 times higher than the next highest head in the network (L6H12 at 0.124), and a mean attention distance of 6.18 (Figure 3).
    • Bimodal distribution and cross-architecture universality: on the COVID-19 dataset, L8H10 focuses on corner text in 62% of images, with a mean corner/lung ratio of 57.5× in the spurious group, and no interquartile overlap between the two groups (Figure 5); on DeiT-Base and ViT-Large/16, spurious rates reach 88% and 80%, respectively (Table 5).
    • Contrast-driven features: the authors' analysis indicates that mean corner brightness cannot predict spurious behavior, while local pixel standard deviation is higher in the spurious group (Mann-Whitney p<0.0001), and corner edge density is not statistically significant (p=0.622).

    Causal Validation and Image Inpainting

    • Test content: compare the causal impact of mean masking (replacing a 56×56 pixel region with the mean) and OpenCV Telea inpainting on L8H10 attention across 200 images.
    • Experimental results: mean masking increases lung attention by 7.8× (from 0.0026 to 0.0202), but the gray block causes corner attention to rise simultaneously; after inpainting, 158 cases (79%) show decreased corner attention (Wilcoxon p<0.0001), 140 cases (70%) show increased lung attention, with an average increase of 1.34× (Wilcoxon p=0.021). In 123 spurious images, lung attention increases by an average of 1.52×, while in 77 normal images it is 0.99× (Mann-Whitney p<0.0001, Figure 6).
    • Authors' interpretation: the authors state that this result confirms that the annotated text content, not mere brightness or edges, drives L8H10's behavior, and that removing the text redirects attention back to lung pathology regions.

    Output-level Ablation and Distributed Encoding Test

    • Test content: perform single-head ablation of L8H10 on the CheXpert fine-tuned model and the pneumonia fine-tuned model, and multi-head ablation on the CheXpert model by zeroing three heads simultaneously: L8H10, L7H2, L9H3 (Table 2, Table 3).
    • Experimental results: under single-head ablation, the CheXpert model has an overall prediction change rate of 5.0% (spurious group 4.9%, normal group 5.2%, Mann-Whitney p=0.340), with an average confidence change of -0.0098; the pneumonia model has a prediction change rate of 0.5% (spurious group 0.8%, normal group 0.0%, p=0.435). Under multi-head ablation, the prediction change rate rises to 10.0%, but the difference between the spurious group (9.8%) and the normal group (11.7%) is not statistically significant (Mann-Whitney p=0.532, Figure 7).
    • Authors' interpretation: the authors state that neither single-head nor multi-head ablation produces specific effects on spurious samples, indicating that the shortcut signal is encoded in a distributed, overlapping manner in the network and cannot be detected by conventional output-level metrics.

    Effect of Fine-tuning on Shortcut Behavior

    • Test content: evaluate the impact of partial fine-tuning (updating the last two layers and classification head for 5 epochs) and full fine-tuning (updating all 12 layers for 15 epochs) on L8H10's spurious behavior (Table 6).
    • Experimental results: after partial fine-tuning, the spurious rate changes from 61.5% to 61.0%, with 122 of 123 samples (99.2%) remaining spurious; after full fine-tuning, the spurious rate is 62.5%, with 121 of 123 samples (98.4%) still spurious, and the mean corner/lung ratio decreases from 35.6× to 29.2× (Wilcoxon p=0.009).
    • Authors' interpretation: the authors state that fine-tuning does not eliminate the shortcut behavior; the fine-tuning objective does not provide corrective gradients because text correlates with institutional prevalence, and standard fine-tuning procedures may preserve or even reinforce the shortcut.

    Other Ablations and Analyses

    • Cross-dataset validation: on 200 images from NIH ChestX-ray14, L8H10 has a spurious rate of 79% (158/200), with corner/lung ratios of 34.9× in the spurious group and 0.92× in the normal group, a separation of 37.9× (p<0.0001, Table 4).
    • Layer-wise entropy distribution: attention specialization is absent in layers 1-6 (average entropy 5.0–5.2 nats), spikes in layers 7-9, and only L7H2 (2.97 nats), L9H3 (2.91 nats), and L8H10 (2.88 nats) fall below 3.0 nats (Figure 2).
    • Spatial distance of abnormal heads: L8H10 has an average attention spatial distance of 6.18, while focused heads L7H2 and L9H3 have 2.00 and 2.28, respectively (Appendix B).
    • Single-patch weight extremes: L7H2 and L9H3 have maximum weights around 0.09, while L8H10 reaches 0.346, with the highest observed ratio at 311.4× (Table 1, Appendix B).
  5. What are some points that can be further explored?

    The authors list limitations such as regional priors, fine-tuning sample size, and single modality; experiments cover three ViT architectures, two chest X-ray datasets, and two types of fine-tuned models.

    Limitations and future directions noted by the authors

    • Region definition and threshold priors (Section 5.3): The authors note that the top-left 3×3 patch region and the threshold of corner-to-lung ratio greater than 2 were chosen to match the annotation conventions of the dataset used in this study; applying them to datasets with annotations in other locations would require adjusting the region definition.
    • Small fine-tuning sample size (Section 5.3): The authors note that the fine-tuning experiments used only 200 images, which is small relative to clinical training set sizes.
    • Dataset comparison experiment direction (Section 5.3): The authors note that the most important future work is comparing fine-tuning performance on matched-scale datasets with consistent annotations versus removed annotations.
    • Fine-tuning validation with removed annotations (Section 5.4): The authors suggest directly testing in the future whether fine-tuning on images with annotations removed prevents the model from encoding spurious correlations.
    • Automated abnormal-head detection tool (Section 5.4): The authors suggest developing an automated screening step based on abnormal maximum attention concentration to avoid manual per-model inspection.
    • Extension to other medical modalities and architectures (Sections 5.2, 5.4): The authors note that whether this phenomenon applies to Swin, BEiT, other medical modalities (retinal imaging, dermoscopy, CT), or other pretraining mechanisms remains an open question.

    Experimental coverage

    • Architecture analysis covers 3 vision Transformer architectures: ViT-Base/16, DeiT-Base, and ViT-Large/16.
    • Image evaluation covers 2 public chest X-ray datasets: COVID-19 Chest X-ray Dataset and NIH ChestX-ray14, with 200 samples drawn from each.
    • Causal intervention covers 2 image processing approaches: mean masking and OpenCV Telea inpainting.
    • Downstream ablation covers 2 fine-tuned models: codewithdark (based on CheXpert) and lxyuan (pneumonia classification), including single-head and three-head ablation settings.
    • Fine-tuning validation covers 2 approaches: partial-layer (2 layers) and full-parameter (12 layers) fine-tuning on 200 images.
  6. Summarize the main content of the paper

    The paper uses mechanistic interpretability to locate and validate an attention head that reads corner text in a medical ViT, pointing out that the shortcut has distributed hidden characteristics.
    • Paper positioning: This study is a mechanistic interpretability analysis of the internal mechanisms of shortcut learning in medical vision transformers (ViTs).
    • Problem addressed: Chest X-ray classifiers tend to exploit annotation information such as hospital codes in image corners as diagnostic shortcuts, which may silently fail when transferred across institutions, but traditional post-hoc interpretability methods cannot localize the specific implementing components.
    • Core method design: systematically scan attention heads for entropy, spatial distance, and max patch concentration to identify abnormal heads; use mean masking and OpenCV inpainting for causal intervention validation; and perform single-head and multi-head ablation tests on downstream fine-tuned models.
    • Main experimental findings:
      1. On ViT-Base/16, L8H10 exhibits a single-patch concentration of 0.346, focusing on corner text in 62% of 200 COVID-19 images, with a mean corner/lung ratio of 57.5×, significantly higher than the normal group's 0.77× (Table 1).
      2. The phenomenon is consistently reproduced across architectures (DeiT-Base 88%, ViT-Large/16 80%) and across datasets (NIH ChestX-ray14 79%) (Table 4, Table 5).
      3. Inpainting increases lung attention by 1.52× in spurious images, causally validating the driving role of text content (Figure 6).
      4. Neither single-head ablation (p=0.340) nor three-head joint ablation (p=0.532) produces specific prediction changes for spurious images at the output level (Table 2, Table 3).
      5. After 15 epochs of full fine-tuning, 98.4% of images retain spurious features, and the shortcut cannot be eliminated by fine-tuning (Table 6).
    • Authors' conclusions and implications: the authors believe that neural networks encode shortcuts in a distributed, overlapping manner, leading to a structural blind spot in output-level behavior evaluation for representation-level shortcuts; conventional accuracy benchmarks cannot detect potential failure risks, and medical AI urgently needs mechanistic audits before cross-institutional deployment.
Read originalarxiv.org