B-Cos Aligned Transformers Learn Human-Interpretable Features

Manuel Tran, Amal Lahiani, Yashin Dicente Cid, Melanie Boxberg, Peter Lienemann, Christian Matek, Sophia J. Wagner, Fabian J. Theis, Eldad Klaiman, Tingying Peng

TL;DR

Researchers have developed the B-cos Vision Transformer (BvT), a new architecture that replaces standard linear layers with "B-cos transforms" to force AI models to align their internal weights with actual image features. In the high-stakes field of digital pathology, this results in AI "explanations" that medical experts find significantly more trustworthy and biomedically relevant, often while improving classification performance.

What Problem Does This Paper Address?

Vision Transformers (ViTs) have become the gold standard for analyzing medical images, but they suffer from a "black box" problem. In computational pathology—where an AI might be tasked with identifying cancer—doctors are rightfully hesitant to trust a model if they can't see why it made a specific diagnosis.

While we can visualize "attention maps" to see where a model is looking, standard ViT attention is often fragmented, noisy, or focused on irrelevant artifacts like image edges. This lack of interpretability isn't just a technical hurdle; it’s a barrier to clinical adoption where transparency is a regulatory and ethical requirement.

Methods

The authors introduce the B-cos transform into the Transformer architecture.

  1. Weight-Input Alignment: In a standard neural network, a layer performs a linear transformation ($w^T x$). The B-cos transform modifies this to reward cosine similarity. Essentially, the model is incentivized during training to make its weights ($w$) look like the input patterns ($x$) it is trying to detect.
  2. The B-exponent: They introduce a hyperparameter $B$ that increases "alignment pressure." A higher $B$ forces the model to be even more selective, only activating when the weights and inputs are highly similar.
  3. Architecture Overhaul: They replaced every linear layer in the Vision Transformer (ViT) and the Swin Transformer (Swin) with these B-cos layers. They also removed standard ReLU activations, as the B-cos transform is inherently non-linear.
  4. Color Encoding: To help the model better understand the stains used in pathology (like H&E), they appended inverted color channels to the input, allowing the model to represent color directions more effectively.

Datasets

The models were evaluated on three key histopathology and cytology benchmarks:

  • NCT-CRC-HE-100K: 100,000 patches of colorectal cancer tissue.
  • TCGA-COAD-20X: A more challenging, non-normalized dataset of colorectal cancer slides used to test transfer learning.
  • Munich-AML-Morphology: A dataset of over 18,000 single white blood cell images used to classify different types of Leukemia.

Key Insights and Ideas

  • Alignment Equals Interpretability: By forcing the weights to align with the input, the "features" the model learns become visually recognizable to humans. If the model is looking for a nucleus, its weights actually look like a nucleus.
  • Uniform Representations: Using Centered Kernel Alignment (CKA), the authors showed that BvTs maintain a much more consistent internal representation across all layers compared to standard ViTs, which tend to have "messier" internal logic.
  • The "Expert" Seal of Approval: The most striking insight came from a blinded study. Pathologists were shown attention maps from both standard models and B-cos models without knowing which was which. They consistently ranked the B-cos models as more "plausible" and better at identifying biomedically relevant structures like dense chromatin and specific cytoplasmic granules.

Key Results

  • Performance Boost: While interpretability often comes at the cost of accuracy, the B-cos Swin (Bwin) actually outperformed the standard Swin Transformer, increasing the F1-score by 2.7% on the NCT dataset and 4.8% on the AML dataset.
  • Transfer Learning: When pre-trained on one dataset and moved to another (TCGA), the BvT outperformed the standard ViT by up to 5%, suggesting that the aligned features generalize better to new, "unseen" data.
  • Statistical Significance: In the expert ranking study, B-cos models achieved a significantly better rank (p < 0.05) than their standard counterparts across multiple datasets.

Limitations and Future Work

The authors note that when training from scratch on certain datasets, the B-cos models occasionally showed a slight performance dip (~2%) compared to standard models, likely due to the strict constraints the B-cos transform places on the weight space.

Future work could involve:

  • Scaling these models to even larger, more diverse medical datasets.
  • Exploring the use of B-cos transforms in other Transformer applications, such as Natural Language Processing (NLP), to see if "alignment" can help explain large language models.
  • Investigating the computational overhead of B-cos transforms in very large-scale deployments.

Summary updated

BibTeX
@inproceedings{tran2023b,
  author = {Manuel Tran and Amal Lahiani and Yashin Dicente Cid and Melanie Boxberg and Peter Lienemann and Christian Matek and Sophia J. Wagner and Fabian J. Theis and Eldad Klaiman and Tingying Peng},
  title = {{B-Cos Aligned Transformers Learn Human-Interpretable Features}},
  booktitle = {International Conference on Medical Image Computing and Computer-Assisted Intervention},
  year = {2023},
  doi = {10.1007/978-3-031-43993-3\_50},
}
Figure