Hopfield Networks is All You Need

By Hubert Ramsauer, Bernhard Schafl, Johannes Lehner, Philipp Seidl, Michael Widrich, Lukas Gruber, Markus Holzleitner, Milena Pavlovi'c, Geir Kjetil Ferkingstad Sandve, Victor Greiff and 5 more. 2020

701 citations recorded by the source corpus.

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

Subfields: Artificial Intelligence, Cognitive Neuroscience, Model Architectures

How researchers see this paper

The researchers whose trusted networks rank it highest, strongest advocate first. Every researcher gets a different order.

In Artificial Intelligence

  1. Quoc V. Le
  2. Sergey Levine
  3. Yoshua Bengio
  4. Mohit Bansal
  5. Christopher R'e
  6. Dacheng Tao
  7. Jianfeng Gao
  8. J. Urgen Schmidhuber

In Cognitive Neuroscience

  1. Andrew Kyle Lampinen
  2. Felix Hill
  3. Imanol Schlag
  4. Kazuki Irie
  5. Johannes von Oswald
  6. J. Urgen Schmidhuber
  7. Ngoc-Son Vu
  8. James L. McClelland

In Model Architectures

  1. Christopher R'e
  2. J. Urgen Schmidhuber
  3. Tri Dao
  4. Quoc V. Le
  5. Yoshua Bengio
  6. Imanol Schlag
  7. Sepp Hochreiter
  8. Atri Rudra

Citations in the corpus