Is transformer attention really a Hopfield network?
Is Transformer Attention Really a Hopfield Network?
The Core Claim
One update step of a modern continuous Hopfield network equals scaled dot-product attention under a specific identification of queries, keys and values. This is an identity of operation, not a history of how transformers were built, and it does not turn a context window into memory that outlives the conversation.
The result originates from Ramsauer and colleagues in their 2020 paper Hopfield Networks is All You Need presented at ICLR 2021. Its abstract states in one sentence: "The new update rule is equivalent to the attention mechanism used in transformers." The update rule of their modern Hopfield network is written as:
ΞΎ_new = X Β· softmax(Ξ² Xα΅ΞΎ)
Reading this literally: compare the current state with every stored pattern, turn the similarities into softmax weights, and return the weighted sum of patterns. Identify the stored patterns with keys, the state with a query, apply the value projection, and set Ξ² = 1/βdβ. The update becomes softmax(QKα΅/βd_k)V, which is scaled dot-product attention. Under those substitutions, the equality is exact - at the level of that single operation. A query attends over keys and returns a weighted blend of values. A Hopfield state updates by attending over stored patterns and returning their weighted blend.
What the Identity Does Not Say
This equivalence applies to one update step. The paper's own text specifies that "retrieval with one update is compatible with activating the layers of deep networks," and its theorems bound how close a single update gets to the stored pattern when patterns are well separated. It is a statement about a step, not about a network iterating to convergence. It is not a lineage.
Attention was introduced in Attention Is All You Need in 2017, three years before the equivalence was demonstrated. The paper's first figure uses an equality sign and explains it in the caption: the sign means "keeps the properties." The two were found to be the same operation after the fact. The identity covers only the operation itself - residual connections, layer normalization, feed-forward blocks, causal masking, and training dynamics fall outside it. Later work narrows the conditions under which the identity holds rather than overturning it.
Three Capacity Numbers That Get Merged Into One
Asking how many patterns a Hopfield network can store yields three different answers, each answering a distinct question:
| Source | Capacity | What It Tolerates |
|---|---|---|
| Hopfield, 1982, simulations at N = 30 and 100 | about 0.15N | until recall errors become severe |
| Amit, Gutfreund and Sompolinsky, 1985 and 1987 | Ξ±_c β 0.138, often rounded to 0.14, so about 0.138N | a small fraction of bit errors, under 1.5 % at zero temperature |
| McEliece, Posner, Rodemich and Venkatesh, 1987 | n/(2 ln n) | none: exact recall of most memories |
There is no contradiction between these. The first is an empirical rule of thumb from small simulations. The second is a statistical mechanics result that permits some noise in what comes back. The third demands exact recovery, making it smaller and growing more slowly. Modern variants changed the question entirely: dense associative memories raised capacity to polynomial and then exponential scaling, and Ramsauer and colleagues proved exponential capacity in the dimension of the space for continuous states. If a post quotes 0.14N as the capacity of the network inside a transformer, it has mistakenly taken the number from the wrong row of a table that stopped at 1987.
A Vocabulary for What Retrieval Returns
The most practical contribution of the paper is not the equivalence itself but the taxonomy of fixed points it provides for the update. A query can settle on a single stored pattern - the clean case - when one pattern is close and well separated. It can settle on a metastable state that averages a subset of similar patterns. Or, when nothing is well separated, it can settle on a global average of everything stored. The authors applied this lens to trained models, reporting that attention heads "perform in the first layers preferably global averaging and in higher layers partial averaging via metastable states." A blend is thus an operating regime of the retrieval step, not automatically a malfunction: when stored patterns are not sufficiently separated, the step returns an average of a subset rather than a single pattern. This is a statement about one retrieval step, not about every wrong answer a model produces.
What This Means for an Agent's Memory
The identity tells us what the retrieval step does with whatever gets there - it does not explain how items get there. Attention retrieves associatively over what is present in the context window right now. It performs this very well, and the Hopfield reading clarifies why. However, it does not persist anything beyond the context window. As Google Research's Titans paper abstracts: "From a memory perspective, we argue that attention due to its limited context but accurate dependency modeling performs as a short-term memory, while neural memory due to its ability to memorize the data, acts as a long-term, more persistent, memory." Thus, the reply in the opening thread has the direction backwards. Attention being a Hopfield update describes retrieval within a window, not long-term storage across sessions or tools.
Disclosures
I work on Mnemoverse, a memory service for AI agents - the kind of system the final section addresses. The extended version, including every paper and the full capacity table, is available in our library, and the MCP server is open source (MIT):
github.com/mnemoverse/mcp-memory-server
Source material adapted from the original article text.
Comments
No comments yet. Start the discussion.