NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Modern Hopfield Networks and Attention for Immune Repertoire Classification

Michael Widrich, Bernhard Schäfl, Milena Pavlovic, Hubert Ramsauer, Lukas Gruber, Markus Holzleitner, Johannes Brandstetter, Geir Kjetil Sandve, Victor Greiff, Sepp Hochreiter, Günter Klambauer

This paper bridges the gap between associative memory theory and deep learning to solve a massive "needle in a haystack" problem in computational biology. By demonstrating that transformer attention is mathematically equivalent to the update rule of modern Hopfield networks, the authors introduce DeepRC—a novel architecture capable of identifying disease-associated immune receptors within "bags" of millions of sequences, even when the relevant signal is as low as 0.01%.

The "Needle in a Haystack" Problem

The human immune system is a vast library of T-cell and B-cell receptors. An individual's "immune repertoire" consists of millions of these unique sequences. When a person is infected with a virus, only a tiny fraction of these receptors are specific to that disease.

Predicting an individual's immune status (e.g., "infected" vs. "healthy") based on these sequences is a Multiple Instance Learning (MIL) problem. In MIL, we label a "bag" (the whole repertoire) rather than individual "instances" (the sequences).

The challenge here is the unprecedented scale:

  1. Massive Bags: While typical MIL problems involve hundreds of instances, immune repertoires contain hundreds of thousands or millions.
  2. Extremely Low Witness Rate: The "witnesses" (sequences indicating the disease) might make up only 0.01% of the total bag.
  3. Complex Motifs: Only short subsequences (motifs) within the receptors usually determine binding to a pathogen.

DeepRC: A Hopfield-Powered Solution

To tackle this, the authors introduce DeepRC (Deep Repertoire Classification). The architecture consists of three main stages:

  1. Motif Recognition ($h$): A 1D-Convolutional Neural Network (CNN) processes each amino acid sequence to extract local features (motifs).
  2. Hopfield Pooling ($f$): This is the core innovation. The authors demonstrate that the attention mechanism used in Transformers is actually the update rule for modern Hopfield networks. These networks have an exponential storage capacity, making them theoretically ideal for retrieving a few specific patterns from a massive set of instances.
  3. Output Network ($o$): A fully connected layer takes the aggregated repertoire representation and predicts the class label.
Schematic of the DeepRC approach

To make this computationally feasible for millions of sequences, the authors implemented a specialized training regime where only the top 10% of sequences (by attention weight) are used for weight updates, alongside utilizing 16-bit precision for specific operations.

Key Insights

  • Attention as Associative Memory: The most profound insight is the mathematical proof that transformer-like attention is equivalent to the update rule of modern Hopfield networks. This provides a strong theoretical foundation for why attention is so effective at "finding" relevant instances in massive sets.
  • Exponential Storage: Unlike classical Hopfield networks, modern versions can store a number of patterns that is exponential in the dimension of the feature space. This allows DeepRC to handle bags with $10^5$ to $10^6$ instances.
  • Interpretability: Because the model uses an attention mechanism, the attention weights directly indicate which sequences the model found most important. This allows researchers to extract disease-associated motifs for further biological study.

Experimental Results

The authors evaluated DeepRC against a massive benchmark of ~30 billion sequences across simulated data, LSTM-generated synthetic sequences, and real-world datasets (including a large-scale Cytomegalovirus (CMV) dataset).

DeepRC consistently outperformed all competing methods, including Support Vector Machines (SVMs) with specialized kernels and other MIL-specific deep learning models.

AUC results across various datasets
  • CMV Dataset: DeepRC achieved a ROC-AUC of 0.831, outperforming the next best method (SVM with MinMax kernel) at 0.825 and significantly beating the standard "Burden test" (0.699).
  • Robustness to Low Witness Rates: In datasets with a 0.1% witness rate, DeepRC maintained high performance (e.g., 0.984 AUC) while most other methods' performance collapsed toward random guessing.
  • Motif Discovery: The sequences assigned high attention weights by DeepRC significantly overlapped with known disease-associated sequences identified in previous biological literature.

Limitations and Future Directions

While highly effective, processing millions of sequences per bag still requires significant GPU memory and computational time. Furthermore, while the model successfully identifies potential motifs, "wet lab" verification of these motifs as actual disease-fighting receptors remains a necessary subsequent step for clinical application.

Ultimately, the success of DeepRC on immune repertoires paves the way for applying modern Hopfield networks to other massive MIL problems in fields like medical imaging, remote sensing, and beyond.

Summary updated

BibTeX
@inproceedings{widrich2020modern,
  author = {Michael Widrich and Bernhard Schäfl and Milena Pavlovic and Hubert Ramsauer and Lukas Gruber and Markus Holzleitner and Johannes Brandstetter and Geir Kjetil Sandve and Victor Greiff and Sepp Hochreiter and Günter Klambauer},
  title = {{Modern Hopfield Networks and Attention for Immune Repertoire Classification}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2020},
  url = {https://openreview.net/forum?id=AA9MXvSPyMN},
}
Figure