Explore the research collection
1 entry · Follow this search
- Post
You could have invented transformers from memory
A pedagogical explainer (not a research result) deriving linear maps, MLPs, and self-attention as associative key-value memory stores from first principles. The unifying quantity is the interference-to-signal ratio — interference from other stored memories vs the target's signal — and capacity is the number of memories before interference matches signal (random unit keys, query with a stored key). At d_k=64: outer-product linear store ≈64; optimal linear (least-squares/whitened keys) ≈128; ReLU MLP ≈128; squared ReLU / SwiGLU ≈2d_k²/3 ≈2,700–2,900; cubed ReLU ≈2d_k³/15 ≈35,000; self-attention with β=√d_k ≈e^{2√d_k−2} ≈1.2 million; β ∝ log M allows an essentially unbounded store (>2M in experiments). Derivations: interference terms add like a random walk (√M); σ(s)=ReLU(s)^p gives capacity M≈d_k^p; the exponential is a weighted sum of all powers, so capacity grows exponentially in the sharpness β: M≈e^{2β(1−β/d_k)} for β≪d_k; normalizing weights for numerical stability yields exactly f(x)=Vᵀsoftmax(βKx). Unlike MLPs, self-attention is non-parametric: keys/values come from context tokens, so the store grows with context length. Notes that the original transformer's v2/v3 described the feedforward layer as "a kind of attention" (passage removed from later versions) and tried replacing FFNs with learned-key-value attention at similar quality. The long-context section compares β∝log M tricks (Su 2021 entropy scaling, Scalable-Softmax, Qwen LogN-Scaling, Qwen2.5-1M YaRN scaling), driving the interference ratio to ~10⁻⁴ at 2M memories. Author-stated caveat: the count is random-vector recall of a single layer, ignoring training data; companion pointers to bits-per-parameter memorization work (Morris et al. ~3.6 bits/param; Allen-Zhu & Li ~2 bits factual knowledge/param). Includes interactive demos (sliders for M and β with live interference/signal visualization). Asides: a gradient-descent step is a memory write (Irie, Csordás & Schmidhuber); transformers' MLPs store facts in superposition.