Lune

ICLR2021Top-tier venue

Hopfield Networks is All You Need

Hubert Ramsauer, Bernhard Schäfl, Johannes Lehner, Philipp Seidl, Michael Widrich, Lukas Gruber, Markus Holzleitner, Thomas Adler, David P. Kreil, Michael K. Kopp, Günter Klambauer, Johannes Brandstetter, Sepp Hochreiter

Abstract

We show that the transformer attention mechanism is the update rule of a modern Hopfield network with continuous states. This new Hopfield network can store exponentially (with the dimension) many patterns, converges with one update, and has exponentially small retrieval errors. The number of stored patterns is traded off against convergence speed and retrieval error. The new Hopfield network has three types of energy minima (fixed points of the update): (1) global fixed point averaging over all patterns, (2) metastable states averaging over a subset of patterns, and (3) fixed points which store a single pattern. Transformer and BERT models operate in their first layers preferably in the global averaging regime, while they operate in higher layers in metastable states. The gradient in transformers is maximal for metastable states, is uniformly distributed for global averaging, and vanishes for a fixed point near a stored pattern. Using the Hopfield network interpretation, we analyzed learning of transformer and BERT models. Learning starts with attention heads that average and then most of them switch to metastable states. However, the majority of heads in the first layers still averages and can be replaced by averaging, e.g. our proposed Gaussian weighting. In contrast, heads in the last layers steadily learn and seem to use metastable states to collect information created in lower layers. These heads seem to be a promising target for improving transformers. Neural networks with Hopfield networks outperform other methods on immune repertoire classification, where the Hopfield net stores several hundreds of thousands of patterns. We provide a new PyTorch layer called "Hopfield", which allows to equip deep learning architectures with modern Hopfield networks as a new powerful concept comprising pooling, memory, and attention. GitHub: this https URL

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

140 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • xLSTM: Extended Long Short-Term Memory cites Linear Transformers Are Secretly Fast Weight Programmers
  • Parallelizing Linear Transformers with the Delta Rule over Sequence Length cites Large Associative Memory Problem in Neurobiology and Machine Learning
  • Parallelizing Linear Transformers with the Delta Rule over Sequence Length cites Linear Transformers Are Secretly Fast Weight Programmers
  • Large Associative Memory Problem in Neurobiology and Machine Learning cites Modern Hopfield Networks and Attention for Immune Repertoire Classification
  • Transformers Learn In-Context by Gradient Descent cites Linear Transformers Are Secretly Fast Weight Programmers
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers140

  1. Transformers Learn In-Context by Gradient DescentJohannes von Oswald, Eyvind Niklasson, Ettore Randazzo, João Sacramento et al.ICML 2023 · 729 citations
  2. xLSTM: Extended Long Short-Term MemoryMaximilian Beck, Korbinian Pöppel, Markus Spanring, Andreas Auer et al.NeurIPS 2024 · 703 citations
  3. Transformer Memory as a Differentiable Search IndexYi Tay, Vinh Tran, Mostafa Dehghani, Jianmo Ni et al.NeurIPS 2022 · 506 citations
  4. Parallelizing Linear Transformers with the Delta Rule over Sequence LengthSonglin Yang, Bailin Wang, Yu Zhang, Yikang Shen et al.NeurIPS 2024 · 412 citations
  5. Linear Transformers Are Secretly Fast Weight ProgrammersImanol Schlag, Kazuki Irie, Jürgen SchmidhuberICML 2021 · 394 citations

Builds on4

  1. ELECTRA: Pre-training Text Encoders as Discriminators Rather Than GeneratorsKevin Clark, Minh-Thang Luong, Quoc V. Le, Christopher D. ManningICLR 2020 · 541 citations
  2. Large Associative Memory Problem in Neurobiology and Machine LearningDmitry Krotov, John J. HopfieldICLR 2021 · 202 citations
  3. Modern Hopfield Networks and Attention for Immune Repertoire ClassificationMichael Widrich, Bernhard Schäfl, Milena Pavlovic, Hubert Ramsauer et al.NeurIPS 2020 · 152 citations
  4. MEMO: A Deep Network for Flexible Combination of Episodic MemoriesAndrea Banino, Adrià Puigdomènech Badia, Raphael Köster, Martin J. Chadwick et al.ICLR 2020 · 41 citations

Related papers

  1. On the Role of Hidden States of Modern Hopfield Network in TransformerTsubasa Masumura, Masato TakiNeurIPS 2025 · 2 citations
  2. Simplicial Hopfield networksThomas F. Burns, Tomoki FukaiICLR 2023 · 1 citation
  3. Outlier-Efficient Hopfield Layers for Large Transformer-Based ModelsJerry Yao-Chieh Hu, Pei-Hsuan Chang, Haozheng Luo, Hong-Yu Chen et al.ICML 2024 · 46 citations
  4. Nonparametric Modern Hopfield ModelsJerry Yao-Chieh Hu, Bo-Yu Chen, Dennis Wu, Feng Ruan et al.ICML 2025
  5. Energy Landscape-Aware Vision Transformers: Layerwise Dynamics and Adaptive Task-Specific Training via Hopfield StatesRunze Xia, Richard JiangNeurIPS 2025 · 1 citation
Dusk over the sea between two cliffs drawn in fine vertical lines