Articles · 2026 · Reading: 15 min, plus 3 in closed details.
Article · explainer · alexwang.ai

You could have invented transformers from memory

Alex Wang (independent; Stanford PhD, formerly Cartesia) · published 15 October 2026

In one line: An explainer (about 19 minutes, derivations, a NumPy script and an in-page slider) that reads a linear layer, an MLP and softmax attention as stores of key-value memories and ranks them by how much the other memories leak into a recall. For random unit keys and values at key dimension 64, queried with a stored key, the leak equals the recalled value at about 64 memories for an outer-product matrix, 128 for a least-squares matrix or ReLU MLP, about 2,700 for a squared ReLU and about 1.2 million for softmax at the usual sharpness; our independent run and the author's 5-seed data agree with each.

64 to 2,700 memories
capacity at key dimension 64: an outer-product matrix holds about d = 64 random memories before interference equals the signal; a squared-ReLU MLP about 2d²/3 = 2,731
derived in the article; ours: 67 and 2,853 measured (3 seeds) · in the article: introduction
1.2 million memories
softmax attention at the usual sharpness β = √64 = 8: capacity e^{2β(1 − β/d)} = e^14; the author's run crosses 1 at about 1.23 million
derived, then simulated to 2 million keys · in the article: Self-attention
0.004 at 2M
interference over signal with 2 million stored memories when the sharpness grows with log M (Su's and Qwen's rules, reference 1,024); without it the ratio passes 1 near 1.2 million
the author's simulation, 5 seeds; released data · in the article: Long context

How far to trust it: Believe the derivations and every number: we recomputed them from scratch and they agree with the author's released data. Read "capacity" as how many rows one readout can hold before crosstalk equals the signal, for random vectors queried exactly, not as how much a layer stores per parameter: the matrix holds its 64 memories in 4,096 numbers, while the MLP's 2,700 and attention's 1.2 million each take their own 128-number row. The evidence, judged.

The idea in one sentence: a linear layer, an MLP and softmax attention all recall a stored value by weighting every stored value by its key's similarity to the query, so the leftover weight on all the wrong memories (interference) grows like √M; each step from the matrix to the MLP to attention shrinks the weight on keys that are only slightly similar, which lets one readout hold about d, then about d², then about e2√d random memories before the interference is as large as the value it recalls.

What this page is for. The layers themselves are owned elsewhere (The transformer from zero; the outer-product state on Beyond attention). No page of ours has the article's single yardstick applied to all three layers, so this page follows that argument, recomputes every capacity live (section 10), and says how far "capacity" carries.

You need: what attention and the FFN compute (The transformer from zero); outer products and least squares (Linear algebra for ML, sections 3 and 7). The rest is built here.

New terms: memory store (a function holding M key-value pairs that, queried with x, returns a mix of values weighted by how similar their keys are to x); signal and interference (the target value's share of a recall, and everything the other M − 1 memories add to it); interference-to-signal ratio (the length of the second over the length of the first); capacity (the M at which that ratio reaches 1, for random unit keys and values queried with a stored key); sharpness β (the factor on similarities inside the exponential; standard attention's 1/√dk scaling is β = √dk for unit-length keys).

Every store weights a key by its similarity; the steeper the curve, the less the crowd of unrelated keys leaks into a recall
Redrawn from the article's argument (our drawing, exact formulas). The target key has similarity 1 to the query (red); the other keys, random unit vectors at d = 64, sit in the grey bump around 0 with spread 1/√64 = 0.125. The dashed line marks that typical similarity, and the dots the weight each store gives it relative to the target: outer product and ReLU 0.125, squared ReLU 0.0156, cubed ReLU 0.0020, softmax at β = 8 about 0.0009 (e−7). Interference is about √M times the root-mean-square weight over the whole bump, so a store's capacity is about 1 over that mean square: 64, 128, about 2,700, about 35,000 and about 1.2 million memories, the article's ladder (the formulas are in section 6).

1. One yardstick: interference over signal

Introduction

The article judges every layer by the interference-to-signal ratio: the length of what the wrong memories add to a recall, over the length of the right value. A store holds M pairs (key ki, value vi) and, queried with kj, should return vj; its capacity is the M at which the ratio reaches 1. Everything is run at key dimension dk = 64 with random unit keys and values, and the promised ladder is a jump from about 64 memories to about 2,700 to over a million.

2. The outer-product store fills at d

An outer product memory store

The simplest store is one matrix, W = Σi viki⊤, read as Wx = Σi vi(ki·x). So recall is a lookup by similarity. A gradient step on a linear layer, W ← W − η ȳx⊤, is such a write, and the same matrix is linear attention's state, which Beyond attention animates (its Fig. 2). Queried with a stored unit key, the answer is vj (signal) plus Σi≠j vi(ki·kj) (interference). Random keys have similarities of about ±1/√dk, and M − 1 such terms add like a random walk, so the ratio is about √(M/dk) and capacity is dk = 64: past that we cannot get perfect recall once we store more. The article's bar figure shows one recall's weights piling up as M passes 64.

3. Two ways to reduce interference

How do we reduce interference?

Short of a bigger key dimension, store more carefully (cancel the keys' overlap: section 4) or recall more selectively (damp keys that barely match: sections 5 to 7).

4. The optimal linear store doubles capacity, and no more

The optimal linear memory store

Fit every memory at once, minW Σ‖Wki − vi‖², and W = VᵀK(KᵀK)−1: the same store with the query first multiplied by the inverse key covariance. This whitens the keys, so the store stops over-weighting shared directions (least squares and the pseudo-inverse: Linear algebra for ML, section 7). It is exact up to M = dk; past that the article derives, from the projection P = K(KᵀK)−1Kᵀ (trace dk, P² = P), a ratio of √(M/dk − 1), so its capacity is twice as large as before: 128. The online form of this fit is the delta rule, owned by Beyond attention (section 3, Fig. 3).

5. A nonlinearity on each similarity is a two-layer MLP

MLP as a nonlinear memory store

Weight by σ(ki·x) instead, f(x) = Vᵀσ(Kx), and We just rediscovered a two-layer MLP from first principles: one hidden unit per key, the output matrix's columns as values. ReLU zeroes negative similarities (capacity 128); squared ReLU also crushes small positive ones (A similarity of 0.1 becomes 0.01). Squared ReLU is ReLU(Kx) ⊙ Kx, a GLU whose gate shares the input weights; SwiGLU, as in our transformer from zero, gives the gate its own weights and a Swish. Trained FFNs behaving this way is Geva et al.'s measurement, which the architecture root cites; the article adds that real MLPs store facts in superposition, which the one-memory-per-unit picture does not cover. Its aside that the Transformer paper said this first, then cut it (the passage is gone from every later version), is correct (closed block).

Checked: the Transformer paper's lost appendix (depth)

arXiv v2 (19 June 2017) and v3 (20 June) of Attention Is All You Need end with "Two Feed-Forward Layers = Attention over Parameters": the FFN is "a kind of attention" with ReLU for softmax and the rows of W1 and W2 as keys and values. Replacing every FFN with attention over 1,536 or 512 learned key-value pairs per head, at matched parameters (65M), gave in Table 5: base perplexity 4.92 and BLEU 25.8 (newstest2013, development), AOP1 4.92 and 25.5, AOP2 4.86 and 25.9, both trained 16 hours against 12. v4 (30 June 2017), v5 and v7 have no such appendix; our paper page reads v7. One slip in it: the text gives the second model 8 heads, Table 5 gives 16.

6. Higher powers: capacity grows like dp

Reducing interference with higher powers

With σ = ReLUp the target keeps weight 1 while a typical other key falls to about dk−p/2, so capacity is about dkp. With the half-normal moments the constants are 2dk (ReLU), 2dk2/3 ≈ 2,731 (squared) and 2dk3/15 ≈ 34,953 (cubed). The shared-gate SwiGLU, s²/(1 + e−s), lands at about 2,900: its capacity nearly matches the squared ReLU, for a reason the article does not give (closed block).

Why the shared-gate SwiGLU matches the squared ReLU (depth)

Near s = 0 the sigmoid is about ½ on both sides, so the curve acts like s²/2 for negative similarities too instead of zeroing them. The crowd's mean-square weight is then 3/(4dk2), half the squared ReLU's 3/(2dk2), while the target's weight is 1/(1 + e−1) = 0.73, a factor 0.73² = 0.53; the two nearly cancel. Gaussian estimate 2,864, measured 2,961 here, 2,901 in the author's data.

7. All powers at once: the exponential is softmax attention

Self-attention as a non-parametric memory store

Use the exponential, a weighted sum of every power, eβs = Σp(βs)p/p!, and capacity becomes e2β(1 − β/dk), exponential in β. The derivation uses E[ets] = et²/(2dk) for a normal similarity, giving the ratio √M · eβ²/dk − β. At attention's β = √dk = 8 that is e14 ≈ 1.2 million, nearly 20,000 times the linear store (the author's run crosses 1 at about 1.23 million). Truncated series show the ladder from inside: with 2 terms, the capacity is about 40, with 3 about 450, with 4 about 3,100. Normalising the weights changes no ratio, and the result is Vᵀ softmax(βKx). Unlike an MLP, its keys and values come from the context, one per token, so M is the context length (what makes self-attention non-parametric); the price is the KV cache that Long context sizes. Standard attention's division by √dk, with q and k of length about √dk, is β = √dk for unit vectors (footnotes 6 and 7).

8. Long context: raise β with log M

Handling many key-value pairs in long context

Since capacity is exponential in β, a longer context needs only a slowly growing β. A huge β would make softmax a hard argmax that picks only the most similar key, with no gradient to the rest, so the rules scale the attention logits with log M against a reference length L: Su (2021) by log M / log L everywhere (Scalable-Softmax learns the factor), the original Qwen's LogN only past L, Qwen2.5-1M by YaRN's (0.1 ln(M/L) + 1)² (YaRN's temperature: Positional Encodings). In the author's simulation (β = 8 at L = 1,024) plain softmax passes 1 near 1.2 million memories; Su's and Qwen's rules hold the ratio at about 0.004 at 2 million, YaRN's at 5.9 × 10−5 (rounded in the article to "about 10−4").

9. The closing table and the author's own limits

Closing thoughts

The article ends on the ladder as a table (64, 128, 128, about 2,700, 2,900, 35,000, 1.2 million, and more than 2 million with log M scaling) and on two caveats: Our capacity estimate only counts how many random vectors one layer recalls, and we haven't actually considered the training data at all. For trained models it points to bits per parameter (Morris et al. about 3.6, Allen-Zhu and Li about 2 for facts; quoted, not checked here), then a reading list that seeds our Further reading.

10. Run it: every capacity, recomputed in your browser

The figure repeats the article's experiment from scratch: M random unit keys and values in d dimensions, 48 stored-key queries, the median ratio (as the author's code takes it), three seeds, M = 4 to 16,384; solid lines measured, dashed lines the article's Gaussian estimate continued to 2 million, open circles where a measured line crosses 1. It opens on curves recorded by this page's src/recompute.py (the same code and random numbers); the button or another d computes live.

At d = 64 the defaults reproduce the article independently (our code, our seeds): 67 against 64, 128, 124 against 128, 2,853 against about 2,700 and 2,961 against about 2,900; cubed ReLU and softmax stay below 1 in range (0.65 and 0.11 at 16,384). The medians sit a little above the estimates for the sharp stores because a few large terms dominate their sums.

Predict, then switch d from 64 to 32. Which capacity falls furthest: the matrix's, the squared ReLU's or softmax's? Then try 16.

The answer

The matrix halves (64 to 32), the squared ReLU quarters (2,731 to 683 by the estimate; 768 measured), and softmax falls about a hundredfold, from e14 ≈ 1.2 million to e2√32 − 2 ≈ 11,000 (11,553 measured), because its capacity is exponential in √d. At d = 16 softmax holds about 400 (563 measured), fewer than the cubed ReLU's 546 to 838: the ladder's order is not fixed, it depends on the head size. Small heads lose most where attention is strongest.

Interference grows like √M for every store; the stores differ only in height, so capacity is where each line meets 1
Measured here in the browser (exact arithmetic on seeded random vectors; nothing trained). Theory column: d, 2d, 2d (ReLU), 2d²/3, the shared-gate SwiGLU's Gaussian estimate, 2d³/15 and e2√d − 2. "Beyond 16,384" means the measured line stays below 1 in range; the article's d = 64 column is quoted from its closing table.

How much of this to believe

The mathematics and the numbers hold. Every capacity comes out of our independent run, out of the Gaussian estimates and out of the author's released five-seed data (closed block below). The derivations are standard (random-walk sums, projection identities, the Gaussian moment generating function), the code is public and runs in under a minute, the post is unchanged since its first archived copy (16 October 2026), and the one historical claim, the Transformer appendix, is right in every detail.

What "capacity" measures is narrower than the ladder suggests. It is the number of memories one readout can sum over before the crosstalk from random wrong memories is as long as the right one, and the stores spend very different amounts of storage to get there:

store at dk = dv = 64memories at capacitynumbers it keepsnumbers per memory
outer product, one 64 × 64 matrix644,09664
optimal linear, one 64 × 64 matrix1284,09632
squared-ReLU MLP, one hidden unit per memoryabout 2,731about 349,600128
softmax attention, one cached key and value per tokenabout 1.2 millionabout 154 million128

Derived: an MLP or cache row holds one key and one value, 64 + 64 numbers; 2,731 × 128 and 1,202,604 × 128 (inputs/recompute.json).

  • Per number kept, the matrix is the most compact store, not the worst. What the nonlinear stores buy is that adding rows does not ruin recall (why attention can find one token among a million); "an MLP improves capacity" means more rows read cleanly, not more facts per parameter. A real FFN has about 4d hidden units, not 2,700 per 64 dimensions, so it relies on the superposition the article mentions but does not analyse; footnote 3 notes that with argmax decoding a d × d matrix holds about d² facts.
  • Every number assumes random keys and values and a query equal to a stored key. Real keys are correlated and real queries only near their key. With a query 0.9 similar to its key, softmax's capacity falls to e2β(0.9 − β/d) ≈ 242,802 (derived), and at M = 1,024 its measured ratio more than doubles (0.027 to 0.061) while the matrix's moves from 3.97 to 4.43: the sharpest stores are the most sensitive to a noisy query. The author's code has this option; the post plots only exact queries.
  • Nothing is trained, and "ratio = 1" is a convention: the capacities describe the readout's arithmetic, not what gradient descent writes, as the author says himself (closing section and his reply below).
  • Small slips: the shared-gate SwiGLU is not the SwiGLU models use (separate gate weights), which the article says; the YaRN rule's 5.9 × 10−5 at 2 million is rounded to "about 10−4"; the title's "you could have invented" is a teaching device, not history (softmax attention entered from alignment in machine translation, Bahdanau et al. 2014).

Verdict. Believe the derivations and every number, and use the article as the clearest single argument for why softmax attention can recall one item among a million and why sharper activations help MLPs. Read its capacities as rows read cleanly from random vectors with exact queries, not as storage per parameter, and not as a description of trained layers.

What the responses said

No rebuttal, replication or blog response was found (web search, 27 November 2026); a Chinese translation appeared on 机器之心, linked from the post. The Hacker News thread had 670 points and 152 comments on 27 November 2026 (submitted 16 October 19:01 UTC; a dated reading); most of it is praise or an argument about mathematical notation. The substantive points:

  • objectionThe memory analogy is weak once training is in the picture
    a Hacker News commenter, with the author's reply, 17 October 2026

    Layers act on deep representations shaped by a loss, so treating Q, K and V as a lookup table says little about what trained layers do; attention is better seen as a kernel method. The author agreed the post is an intuition that ignores what gets written into the weights and the learning dynamics, and pointed to the papers in his closing list.

  • objectionRandom keys are white noise; real data has structure
    two Hacker News commenters, 17 October 2026

    The capacities hold for random keys and values; real keys are correlated and real values are structured, which both helps (compression) and hurts (correlated keys interfere more). A second commenter adds that truly random key-value pairs would be served better by an exact associative array. The post states the first limit itself in its closing section.

  • questionWhy not take the hard maximum?
    a Hacker News commenter, answered in the thread, 17 October 2026

    If higher powers suppress interference better, the limit is argmax over keys. The answer, already in the post: argmax is not differentiable, and a very large β saturates the softmax so the gradients to other keys vanish; hence β grows only as fast as M requires.

  • reader commentUndefined terms and notation
    several Hacker News commenters, 17 October 2026

    The largest sub-thread: readers without linear algebra found d_k, ℝ^{d_k}, M and "similarity" not defined at first use and asked for a worked example with real data structures; others answered that the terms paragraph defines them. A reading-level complaint, not an error.

Where it moves the knowledge base

It contradicts nothing on our pages; it gives three of them a quantitative reason they lack.

  • Beyond attention: its section 2 says, with Schlag et al., that the state overfills once the sequence exceeds the key dimension; it gains the number (interference over signal √(M/dk), capacity about dk), the least-squares store as the offline limit the delta rule approaches (capacity 2dk, exact up to dk), and this article in Further reading.
  • The transformer from zero: its FFN and attention sections gain the memory reading in two sentences (the FFN as Vᵀσ(Kx), softmax as the all-powers limit with capacity e2β(1 − β/d)), and its √d section the article's reading of the scale as the sharpness β = √dk.
  • Topic: llm-architecture: its sentence that the FFN "behaves like a key-value memory" (Geva et al.) gains the Transformer v2 and v3 appendix as the first statement of it, and the article.
  • Attention Is All You Need: a note that v2 and v3 carried the attention-over-parameters appendix and Table 5 (above), absent from v7, which the page reads.
  • Activation functions: squared ReLU gains its reason in this frame (crowd weight d−1 instead of d−1/2).
  • Positional Encodings and Long context: the log M logit scalings (Su, LogN, SSMax) as a family beside YaRN's temperature, with the article's simulation as the reason they work.
The article's numbers, recomputed (depth)
  • Gaussian estimates at d = 64 (capacity = σ(1)² / E[σ(s)²], s ~ N(0, 1/64)): linear 64; ReLU 128; squared ReLU 2,730.7; shared-gate SwiGLU 2,863.9; cubed ReLU 34,952.5; exponential e14 = 1,202,604; truncated exponentials with 2, 3 and 4 terms 40.5, 448.3 and 3,089.1 (article: about 40, 450 and 3,100).
  • Measured here (3 seeds, 48 queries, median): d = 64: 67.1, 128.0, 123.7, 2,852.8, 2,960.9; cubed ReLU and softmax below 1 at 16,384 (0.649 and 0.111). d = 32: 35.7, 64.3, 66.7, 767.6, 794.7, 5,218.5, 11,553.3. d = 16: 16.1, 32.6, 36.6, 208.5, 199.2, 837.7, 562.7 (order: outer product, optimal, ReLU, squared ReLU, SwiGLU, cubed ReLU, softmax).
  • The author's released data (crosstalk.json, 5 seeds), crossings by the same log-log interpolation: 67.8, 128.7, 136.0, 2,813, 2,901; softmax 1.225 million (ratio 0.936 at 1,048,576 and 1.254 at 2,097,152); with log M scaling 0.0037 (Su and LogN) and 5.9 × 10−5 (YaRN) at 2,097,152.
  • Softmax closed form at β = 8, d = 64: 2β(1 − β/d) = 16 × 0.875 = 14; e14 / 64 = 18,791 ("nearly 20,000 times"). With query similarity ρ = 0.9: e2β(ρ − β/d) = e12.4 = 242,802.
Provenance: what was read, fetched and compared

Read on 27 November 2026: the post (fetched that day; dated 15 October 2026 in its page data; 4,276 words with formulas and figure labels, 19 minutes at 230 words a minute), its footnotes and three collapsed asides; the code repository (README, crosstalk.py and data/crosstalk.json at commit 5defb8d, 15 October 2026; no licence file, so its data is cited, not copied); all 152 Hacker News comments through the item API; arXiv 1706.03762 v1 to v5 (the appendix is in v2 and v3) and its submission history; the Qwen2.5-1M report (arXiv 2501.15383, section 5.1) for the YaRN rule's definition; the arXiv titles of the papers in Further reading. The two earliest Wayback copies (16 October 2026, 18:16 and 19:06 UTC) carry the same text as the current post.

Not checked: the 1% hidden-unit activation figure (Li et al.), and the bits-per-parameter estimates of Morris et al. and Allen-Zhu and Li, all quoted from the article. Hacker News commenters are not named here; they are readers, not authors of published responses.