logo
Kurashizu Blogwhere ideas flow
  • Home
  • News
  • Blog
  • About
  • Home
  • News
  • Blog
  • About

© 2026 Kurashizu. All rights reserved.

Admin·New Post·Service Status
Powered by Cloudflare·30.10.26
← Back to news

You could have invented transformers from memory

Original article
alexwang.ai|424 points|99 comments|by speckx|Oct 16, 2026

You Could Have Invented Transformers from Memory

By Alex Wang (Rewritten)

The Transformer architecture often feels like a piece of arcane magic—a sudden leap in AI capability that appeared out of nowhere. However, if you break it down, the Transformer is less of a "miracle" and more of a logical conclusion. If you understand basic linear algebra and the goal of sequence processing, you realize that you could have derived the Transformer yourself.


1. The Fundamental Goal: Contextualization

Imagine you have a sequence of tokens (words). Each token starts as a static embedding—a vector x\mathbf{x}x in high-dimensional space.

The problem is that a static embedding for the word "bank" is the same whether the sentence is "river bank" or "investment bank." To solve this, we need a way for tokens to communicate and update their meanings based on their neighbors.

We could use Recurrent Neural Networks (RNNs), but those are slow and forget things. We need something that can look at the whole sentence at once.

The Design Checklist

To build a modern sequence processor, we need:

  • A way to represent tokens (Embeddings)
  • A mechanism for tokens to interact (Attention)
  • A way to process the results (Feed-Forward Networks)
  • A method to keep the signal stable (LayerNorm & Residuals)
  • A sense of order (Positional Encoding)

2. The "Aha!" Moment: Attention

How do we let tokens "talk"? We want each token to look at every other token and decide: "How much of your information do I need to understand my own context?"

The QKV Framework

To do this, we assign three different roles to every token using learned weight matrices WQ,WK,WV\mathbf{W}_Q, \mathbf{W}_K, \mathbf{W}_VWQ​,WK​,WV​:

ComponentNamePurposeAnalogy
q\mathbf{q}qQueryWhat I am looking forA search query in Google
k\mathbf{k}kKeyWhat I containThe title/tags of a webpage
v\mathbf{v}vValueThe actual informationThe content of the webpage

Key Insight: The interaction between a Query and a Key determines how much of the Value gets passed along.

The Mathematical Flow

  1. Similarity: We calculate the dot product of the query qi\mathbf{q}_iqi​ and key kj\mathbf{k}_jkj​ to see how well they match.
  2. Scaling: We divide by dk\sqrt{d_k}dk​​ to prevent gradients from exploding.
  3. Normalization: We use softmax to turn these scores into probabilities (weights) that sum to 1.
  4. Aggregation: We multiply these weights by the values vj\mathbf{v}_jvj​.

The entire operation is captured in this elegant LaTeX expression:

Attention(Q,K,V)=softmax(QK⊤dk)V\text{Attention}(\mathbf{Q}, \mathbf{K}, \mathbf{V}) = \text{softmax}\left(\frac{\mathbf{QK}^\top}{\sqrt{d_k}}\right)\mathbf{V}Attention(Q,K,V)=softmax(dk​​QK⊤​)V


3. Scaling the Idea

A single attention mechanism is limited; it can only "attend" to one type of relationship at a time. To fix this, we use Multi-Head Attention (MHA).

Instead of one big attention operation, we run several smaller ones in parallel. One head might focus on grammar, another on entity relationships, and another on temporal order.


4. The Rest of the Machinery

Attention is great for moving information around, but it doesn't actually process that information. It's just a weighted average. To actually "think" about the data, we need a Feed-Forward Network (FFN).

The Processing Block

After the attention step, each token passes through the same MLP (Multi-Layer Perceptron): Linear →\rightarrow→ ReLU/GELU →\rightarrow→ Linear.

Stability and Order

To make the network deep without it crashing, we use:

  • Residual Connections: output=layer(x)+x\text{output} = \text{layer}(x) + xoutput=layer(x)+x. This allows gradients to flow easily.
  • Layer Normalization: Keeps the activations in a healthy range.
  • Positional Encodings: Since attention is permutation-invariant (it doesn't know the order of words), we add a sine/cosine wave to the embeddings: PE(pos,2i)=sin⁡(pos/100002i/dmodel)\text{PE}_{(pos, 2i)} = \sin(pos / 10000^{2i/d_{model}})PE(pos,2i)​=sin(pos/100002i/dmodel​)

5. Putting it All Together

If we were to write the logic of a single Transformer block in pseudo-code, it would look like this:

def transformer_block(x):
    # 1. Self-Attention with Residual and Norm
    attn_out = multi_head_attention(x)
    x = layer_norm(x + attn_out)
    
    # 2. Feed-Forward with Residual and Norm
    ffn_out = feed_forward_network(x)
    x = layer_norm(x + ffn_out)
    
    return x

Transformer Architecture Diagram

Final Thoughts

When you view the Transformer this way, it ceases to be a mystery. It is simply:

  1. Linear Algebra (Dot products for similarity).
  2. Probability (Softmax for weighting).
  3. Parallelism (Multi-head attention).
  4. Deep Learning Basics (MLPs and LayerNorm).

The "invention" wasn't a discovery of a new law of nature, but the clever assembly of existing tools to solve the problem of context. You could have done it too.