TL;DR
Standard Vision Transformers (ViTs) are often explained using attention maps, but attention alone ignores non-linear MLPs, layer norms, and tokenizers while failing to distinguish positive from negative evidence. The authors introduce B-cos ViTs, redesigning each transformer component to be dynamic linear ($y(x) = W(x)x$). This makes the entire network mathematically summarizable into a single, input-dependent linear transformation, providing faithful, fine-grained, class-specific explanations out of the box without sacrificing classification accuracy.
What Problem Does This Paper Address?
While attention maps are widely used to explain Vision Transformers, they only show where attention heads look—completely ignoring tokenization, layer normalizations, and multi-layer perceptrons (MLPs). Furthermore, attention matrices contain only non-negative weights, meaning they cannot identify negative evidence (features arguing against a class) and are inherently class-agnostic.
Post-hoc explanation methods (like Grad-CAM, Integrated Gradients, or Layer-wise Relevance Propagation) attempt to compensate, but they can be noisy, computationally heavy, or fail to accurately mirror internal network operations. The authors set out to build a transformer architecture that is inherently explainable by design, producing faithful, pixel-level, class-specific explanations as a natural byproduct of its forward pass.
Methods
The paper builds on the B-cos framework, which forces network layers to dynamically scale outputs based on how well weight vectors align with inputs. To make an entire ViT dynamic linear ($y(x) = W(x)x$), the authors overhaul every standard component:
- Tokenization via B-cos CNN: Instead of standard patch projection, features are extracted via a B-cos DenseNet-121 backbone followed by a B-cos convolution.
- B-cos Attention: Standard attention computes $A(P)VP$, which is already dynamic linear. However, to prevent unconstrained scaling and preserve alignment properties:
- Value ($V$) and projection ($U$) linear heads are replaced with B-cos linear transformations with MaxOut units.
- Standard LayerNorm is removed from the residual path and applied strictly inside the attention matrix calculation: $A(P) = \text{softmax}(\tilde{P}^T Q^T K \tilde{P})$ where $\tilde{P} = \text{LayerNorm}(P)$.
- B-cos MLPs & Classifier: GELU non-linearities and normalization layers are removed; linear transformations are swapped for B-cos layers coupled with MaxOut units.
- Multiplicative Attention Priors: Standard additive position embeddings force models to tie feature content directly to spatial positions, harming generalization. Instead, the authors inject positional bias directly into attention heads via a learnable prior: $$\text{Attention}_{\text{mul}}(P) = \text{softmax}(R(P)) \times \text{softmax}(B)$$
Datasets
- ImageNet-1k (ILSVRC 2012): Used for training and evaluating classification accuracy ($224 \times 224$ resolution).
- Grid Pointing Game Benchmark: 250 synthetic $2 \times 2$ grid images ($448 \times 448$ resized to $224 \times 224$) composed of distinct ImageNet classes, measuring how much positive attribution an explanation assigns to the correct quadrant.
- Pixel Perturbation Benchmark: Evaluated on the 250 most confident, correctly classified ImageNet validation samples.
Key Insights and Ideas
- Computation is Explanation: Because the entire architecture satisfies dynamic linearity, the model output for class $k$ is literally an inner product: $y_k(x) = [W(x)]_k^T x$. The row $[W(x)]_k$ serves as an exact, unapproximated, model-faithful explanation.
- Attention Rollout "Fills the Blanks": Attention rollout effectively treats MLPs and tokenizers as identity matrices. B-cos ViTs preserve the same cascading linear structure across all layers, capturing the contributions of MLPs and tokenizers at full image resolution.
- Class-Specific and Signed Attributions: Unlike attention maps that highlight every salient object in an image regardless of the queried class, the B-cos formulation highlights class-specific features and distinguishes between positive and negative evidence.
- Direct Color Visualizations: Because input pixels are encoded in a bounded 6-channel angular representation, rows of $W(x)$ can be directly decoded and visualized in RGB color space.
Key Results
- Competitive Classification Performance: Across Tiny, Small, and Base ViT configurations on ImageNet, B-cos ViTs perform on par with or exceed conventional ViTs. For example, B-cos ViT-Base-87 reached 76.7% top-1 accuracy compared to 74.5% for conventional ViT-Base-87.
- Superior Spatial Localization: On the 4-quadrant grid pointing game, the model-inherent explanations outperformed the strongest post-hoc method on B-cos ViTs (Attention Rollout) by a factor of $2.47\times$, and beat the best post-hoc method on standard ViTs (Integrated Gradients) by $2.32\times$.
- Pixel Perturbation Fidelity: Measuring the area between curves (ABC) when removing most- vs. least-important pixels, B-cos inherent contribution maps outperformed the second-best baseline by $1.99\times$.
Limitations and Future Work
- Local vs. Global Interpretability: Explanations are strictly sample-level (local). They reveal why the network classified a specific image, but do not directly explain global dataset-level representations.
- Frozen Backbones: To keep computational overhead manageable across ablation configurations, models were evaluated on frozen DenseNet backbones rather than being trained purely patch-based from scratch.
- Modality Scope: The study is restricted to image classification on ImageNet-1k. Extending B-cos transformers to NLP, multimodal tasks, or dense visual prediction (detection/segmentation) remains open for future research.
Summary updated