BERTology Meets Biology: Interpreting Attention in Protein Language Models

Jesse Vig, Ali Madani, Lav R. Varshney, Caiming Xiong, richard socher, Nazneen Rajani

Transformer architectures, originally designed for natural language processing, have revolutionized computational biology. By treating amino acid sequences as "words" in a biological language, protein language models (pLMs) like BERT can predict complex protein properties with remarkable accuracy. However, these models are often treated as "black boxes." In biology, simply getting the right answer isn't enough; researchers need to understand why a model makes a prediction to aid in scientific discovery.

This paper applies "BERTology"—the study of the inner workings of Transformer models—to the biological domain. The researchers demonstrate that pLMs trained exclusively on raw sequences naturally "discover" fundamental biological concepts, such as 3D folding structures and functional binding sites, entirely within their attention mechanisms.

Unpacking the Black Box

To understand how these models process biological data, the authors analyzed five pre-trained Transformer models, including TapeBert, ProtBert, ProtAlbert, and ProtXLNet. They employed several interpretability lenses:

  1. Attention Analysis: The team measured how much "high-confidence" attention (weights above a specific threshold) aligns with known biological features. For instance, they investigated whether an attention head connecting amino acids $i$ and $j$ corresponds to those two residues being physically close in 3D space.
  2. Probing Tasks: Using "diagnostic classifiers," they tested what information is stored in the model's hidden states (Embedding Probes) versus what information is actively used in the attention weights (Attention Probes).
  3. 3D Visualization: To bridge the gap between sequence and structure, the researchers developed Provis, a 3D visualization tool that maps attention arcs directly onto 3D protein structures.
3D visualization of attention arcs mapped onto a protein structure, illustrating how models learn spatial proximity.

Key Biological Insights

The analysis revealed several profound ways in which Transformer models internalize biological rules:

Emergent 3D Intuition: Even though the models are only fed 1D strings of amino acids, their deepest layers develop a strong "sense" of 3D geometry. Attention heads in these layers frequently connect amino acids that are far apart in the linear sequence but physically touching in the folded 3D protein. In the best-performing model (ProtBert-BFD), up to 63.2% of high-confidence attention aligned with physical contacts, compared to a random background frequency of just 1.3%.

Functional Targeting: The models do not just look at structural geometry; they also identify functional regions. Specific attention heads "specialize" in targeting binding sites—the critical areas where proteins interact with drugs or other molecules. In the ProtAlbert model, 22 different attention heads directed over 50% of their attention to binding sites, far exceeding the 4.8% background frequency. Furthermore, some heads showed incredible specificity for rare features; one TapeBert head focused 64% of its attention on post-translational modification (PTM) sites, which represent only 0.8% of the dataset.

Hierarchical Learning: Much like how computer vision models learn simple edges in early layers and complex faces in deeper layers, protein models exhibit hierarchical learning. They capture simple, local structures (like alpha-helices) in early layers and complex, global properties (like binding sites and 3D contacts) in deeper layers.

Attention heatmaps for ProtBert and ProtBert-BFD showing how specific heads in deeper layers specialize in biological properties.

Chemical Logic: The models also learn the underlying chemistry of evolution. The way the model relates different amino acids to one another correlates strongly (Pearson $r=0.73$) with the BLOSUM62 substitution matrix, a classic biological tool that measures the evolutionary likelihood of one amino acid replacing another.

Limitations and Future Directions

While these findings are compelling, the authors note that their analysis is primarily associative. Just because an attention head "looks" at a binding site does not definitively prove that this specific head is the sole reason the model succeeds at a downstream task. Additionally, due to memory constraints, sequences were truncated to 512 amino acids, potentially excluding insights from very large, complex proteins.

Ultimately, this research opens the door for significant discovery potential. By leveraging these "structurally-aware" attention heads, future work could uncover entirely new biological relationships or more nuanced definitions of amino acid interactions that classical biology has yet to formalize.

Summary updated

BibTeX
@inproceedings{vig2021bertology,
  author = {Jesse Vig and Ali Madani and Lav R. Varshney and Caiming Xiong and richard socher and Nazneen Rajani},
  title = {{BERTology Meets Biology: Interpreting Attention in Protein Language Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2021},
  url = {https://openreview.net/forum?id=YWtLZvLmud7},
}
Figure