You could have invented transformers from memory
- Source
- alexwang.ai
- Publisher
- Alex Wang
- Author
- speckx
- Date

Context
An associative memory stores key-value pairs and returns a value when queried with something similar to its key. In this October 2026 post, Alex Wang reads the standard layers of a as different kinds of associative memory and asks how many memories each can hold before recall fails (alexwang.ai). His answer, for random keys and values with 64 dimensions per key, is about 64 memories for a plain linear layer, about 2,700 for an MLP with a squared activation, and over a million for .
The starting point is a linear layer that stores each memory by adding the product of its value and key into a weight matrix. Querying multiplies the input by that matrix, which returns every stored value weighted by how similar its key is to the query. The wanted value comes back, but so does a little of every other value, and Wang calls that leftover interference. He defines a store's capacity as the number of memories at which interference grows as large as the signal; for the linear store that is roughly the key dimension. Fitting all memories at once by least squares instead of adding them one by one doubles it.
The bigger gains come from recalling selectively. Passing each similarity through a nonlinear before weighting the values turns the store into exactly a two-layer MLP, with the first weight matrix holding keys and the second holding values. A ReLU zeroes out negative similarities; squaring the result shrinks weak matches far more than strong ones, so a similarity of 0.1 becomes 0.01 while 1 stays 1, which lifts capacity to about 2,700. The exponential function contains every power at once, and dividing by the sum for numerical stability gives the softmax used in self-attention. With the sharpness self-attention normally uses, capacity reaches about 1.2 million. Its keys and values come from the tokens in rather than from trained weights, so the store grows with the context, and raising the sharpness with the logarithm of context length, as some long-context methods do, kept recall working past 2 million memories in his experiments.
Wang is explicit about the limits. The estimate only counts how many random vectors one layer can recall before interference dominates, and it ignores the training data that determines what the keys and values actually represent. He points to other work that measures what trained models store in bits per parameter as a complementary view.
- transformer — The neural network architecture behind modern AI models, built on attention — letting every word directly consider every other word in parallel.
- attention — The mechanism that lets a model weigh which earlier words matter for the word it's currently processing — the core operation of a transformer.
- Function — A named block of instructions that takes inputs, called arguments, and hands back a result, called its return value.
- Context and context window — Context is the information available for a generation; the context window is the capacity available to hold it.



