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

Modern Hopfield Networks and Attention for Immune Repertoire Classification

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

Abstract

This paper establishes a mathematical equivalence between the attention mechanism used in modern Transformer architectures and the update rule of Modern Hopfield Networks (MHNs). Leveraging this connection, the authors introduce DeepRC (Deep Repertoire Classification), a model specifically designed to handle the massive Multiple Instance Learning (MIL) challenge of immune repertoire classification. DeepRC utilizes the exponential storage capacity of MHNs to identify rare disease-associated sequences within millions of immune receptors, achieving state-of-the-art results on real-world benchmarks like CMV status prediction.

Introduction: The Massive MIL Problem

The human immune system consists of a vast array of T-cell and B-cell receptors. An individual's "immune repertoire" can contain millions of unique sequences. When an infection occurs, only a tiny fraction of these sequences—often fewer than 0.01%—react to the pathogen. These rare sequences are the "witnesses" of the disease.

From a machine learning perspective, this is a Multiple Instance Learning (MIL) problem where:

  1. The Bag: Represents an individual person, labeled as "infected" or "healthy."
  2. The Instances: Are the millions of amino acid sequences within that person's repertoire.
  3. The Challenge: The "witness rate" is extremely low, and the number of instances per bag is several orders of magnitude larger than in standard MIL tasks. Traditional MIL methods often fail to scale or lose the signal in the noise.

Methodology: DeepRC and Modern Hopfield Networks

DeepRC addresses these challenges by combining deep learning for feature extraction with the high-capacity retrieval capabilities of Modern Hopfield Networks.

A key contribution of this work is the proof that the standard attention mechanism, $att(Q, K, V)$, is identical to the update rule of a continuous-state Hopfield network. Unlike classical Hopfield networks with limited storage, MHNs can store an exponential number of patterns relative to their feature dimension, making them ideal for searching through millions of sequences.

Model Architecture

The DeepRC pipeline consists of three primary stages:

  1. Motif Recognition: A 1D-CNN scans amino acid sequences to identify local patterns (motifs) that are likely to bind to pathogens.
  2. Attention Pooling: Instead of simple averaging, DeepRC employs the MHN update rule as an attention mechanism. A learned "query" is used to find and weight the most relevant sequences across the entire repertoire.
  3. Output Generation: The weighted representations are aggregated to produce a final classification for the individual.
DeepRC Architecture Overview

To manage the computational load of processing millions of sequences, the authors implemented 16-bit precision and an "attention-based subsampling" strategy, focusing training on the top 10% of sequences with the highest attention weights.

Results and Performance

The model was evaluated on a massive scale, including simulated datasets with witness rates as low as 0.01% and a real-world Cytomegalovirus (CMV) dataset comprising 686 human repertoires.

State-of-the-Art Benchmarks

On the real-world CMV dataset, DeepRC achieved an AUC of 0.831, outperforming the previous state-of-the-art (SVM with MinMax kernel at 0.825). In simulated environments, DeepRC demonstrated remarkable robustness, maintaining high accuracy even when the signal was extremely sparse, whereas baseline methods failed as the witness rate dropped below 1%.

Performance Comparison on Real and Simulated Data

Biological Validation and Interpretability

DeepRC is "interpretable by design." By analyzing sequences with the highest attention weights, the researchers successfully re-discovered T-cell receptor (TCR) sequences known in the literature to be associated with CMV. This confirms that the model's attention mechanism focuses on biologically meaningful signals rather than spurious correlations.

Discussion and Future Outlook

While DeepRC sets a new standard for immune repertoire classification, it remains computationally intensive. Future work aims to incorporate multi-head attention and additional metadata, such as age or HLA type, to further refine predictions. The "massive MIL" approach pioneered here has broad implications beyond immunology, potentially benefiting fields like high-resolution pathology and long-form video analysis where rare signals must be detected within vast datasets.

Summary updated

BibTeX
@inproceedings{widrich2020modern,
  author = {Michael Widrich and Bernhard Schäfl and Hubert Ramsauer and Milena Pavlovic 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