You could have invented transformers from memory
TL;DR Highlight
Viewing linear, MLP and attention layers as memory stores: capacity goes ~64 to ~2,700 to over a million
Who Should Read
An LLM API developer who lacks intuition for why transformers are shaped this way and what MLP and attention layers do
Core Mechanics
- Every layer is a memory store
- A memory is one key-value pair: a key for lookup and a value to retrieve.
- A store that recalls by similarity is called an associative memory.
- Linear layers store by outer products
- To add a memory (k, v), add v·kᵀ to the weights.
- Recall compares the query with every key and returns the similarity-weighted sum of values.
- Interference drowns out memories
- A recall returns the target value (signal) plus values from other memories (interference).
- Capacity is the number of memories at which interference grows as large as the signal.
- Linear capacity equals key dimension
- With random unit keys, the interference-to-signal ratio is about √(M/d_k).
- So capacity is M≈d_k, and beyond that perfect recall is impossible since only d_k orthogonal directions exist.
- Capacity grows from linear to attention
- With 64-dim keys, it goes from about 64 to about 2,700 to over a million.
- The MLP is a nonlinear store and self-attention a non-parametric one.
- A gradient step also writes a memory
- For a linear layer, one step adds a memory with key x and value -η·ȳ to the weights.
- The post cites Irie, Csordás & Schmidhuber for this view.
Community Reactions
- Math notation is a barrier
- One reader said they know no linear algebra, and another felt excluded because the notation is unexplained.
- Another reader said that after reading, they still could not have invented transformers.
- Random keys give only a bound, some said
- The article assumes random keys, but real data has structure that allows more compression.
- So the conclusions are bounds rather than true estimates, and the real leverage comes from interaction with data structure.
- Question about what the values are in an LLM
- A reader got lost at the final link from memory to LLMs.
- They asked: if context tokens are the keys, what are the values?
- Author shared a summary thread
- The author posted a link to a short summary on X.
- Another comment liked that transformers find a suitable memory in one step, unlike multi-step vanilla Hopfield networks.
How to Apply
- Simulate interference yourself
- In 30 minutes, build an outer-product store with M random unit-vector keys.
- Vary M around d_k=64 and check whether recall error matches √(M/d_k).
- Check embedding dimension against index size in RAG
- If your index has far more chunks than embedding dimensions, check whether wrong documents leak into results.
- Use the interference idea as a hypothesis and compare against your retrieval logs.
- Explain layers as memory stores in a team study session
- Draw linear, MLP and attention as one key-value lookup framework.
- Open the post's interactive app and code and move M live.
Try It
# Run in Python: simple version (a simulation of the post's formulas, not the original code)
# pip install numpy
import numpy as np
d = 64
rng = np.random.default_rng(0)
for M in [8, 32, 64, 256, 1024]:
K = rng.normal(size=(M, d))
K /= np.linalg.norm(K, axis=1, keepdims=True)
V = rng.normal(size=(M, d))
V /= np.linalg.norm(V, axis=1, keepdims=True)
W = V.T @ K
out = W @ K[0]
interference = np.linalg.norm(out - V[0])
print(M, 'interference/signal =', round(interference, 2), 'vs sqrt(M/d) =', round((M / d) ** 0.5, 2))
# Next: make the keys mutually orthogonal (M<=d) and check that interference goes to about zero.Terminology
Related Papers
FutureBench: A Renewable Framework for Evaluating Knowledge-Context Conflict in LLMs
Adding 'verify and prioritize the passage' to RAG prompts raised false-passage adoption; a knowledge-priority warning fixed it.
Faster Retrieval for Better, More Efficient RAG
Small neural nets learned query routing, hitting the same recall up to 8x faster in IVF search
Memorilla: Latent Semantic Memory for LLMs
Compressing documents into 16 memory tokens beat full-context accuracy on FactKG.
What the Author Wrote, What the Agent Reads: Silent Cue Loss in Enterprise Document Ingestion
Preserving red text and highlights in docx ingestion lifted marked-requirement F1 from 0.150 to 0.690.
Multimodal Reranking Is a System One Decision
One multiple-choice question to a VLM over 16 candidates reranks them, beating a dedicated 2B reranker.
Pointing AI at archives found a forgotten meteorite, lost rhinos, and more
Embedding search plus a cheap filter model surfaced unrecorded events in 400 years of archives
EmbeddingGemma 2: An open, lightweight multimodal embedding model
One open 740M model embeds text, images, audio and video into a single shared vector space
RAG-NAROK: Retrieval-Aware Knowledge Corpus Poisoning in RAG with Source-specific Refutation
Refutation documents targeting retrieved sources took top rank and evaded anomaly detectors up to 88.37%.