4.1.12 · D1Transformer Architecture

Foundations — The original - Attention is All You Need - architecture

3,444 words16 min readBack to topic

This page assumes you have seen none of the notation. We build each symbol from a picture before the parent note is allowed to use it.


1. A vector — an arrow of numbers

Picture it. In the figure below the arrow has two numbers, so it lives on a flat board. Real Transformers use arrows with numbers — impossible to draw, but the idea is identical: an arrow pointing somewhere in a high-dimensional space.

Figure — The original  - Attention is All You Need -  architecture

Why the topic needs it. A word like "cat" cannot be added, scaled, or compared as a raw symbol. Turn it into an arrow of numbers and suddenly all of arithmetic is available. Every box in the parent note is moving arrows around.


2. Symbols you will keep seeing

Before any formula, here is the full glossary the parent note leans on. Read top to bottom — each builds on the one above. Every symbol here is pictured or drawn in the sections that follow; the map at the end shows exactly which figure defines which.

Do not memorise these — each is drawn below.

2a. The token grid — where , , , , , live

Every symbol about shape lives in one picture: the grid . Each row is one token's arrow (there are of them, indexed by or ); each column is one of the entries (indexed by ).

Figure — The original  - Attention is All You Need -  architecture

2b. Where the arrows come from — embedding and positional encoding

A raw token is just a symbol ("cat"). Two steps turn it into a starting arrow of length .

Figure — The original  - Attention is All You Need -  architecture

3. Multiplying an arrow by a matrix — a reshaping machine

We use the row-vector convention throughout, matching the parent note (, with written as a row and the matrix on its right).

Figure — The original  - Attention is All You Need -  architecture

Why the topic needs it. The projections , the feed-forward , the output mix all of them are "reshape this arrow through a learned machine, then nudge". Training tunes the numbers inside and .

3a. Transpose — flipping a grid

Figure — The original  - Attention is All You Need -  architecture

4. The dot product — how aligned are two arrows?

This is the heart of attention, so we slow down.

Why this tool and not another? We need a single number saying "how relevant is token A to token B?". Distance would work but grows with vector length and ignores direction. The dot product answers exactly "do these two arrows agree in direction?" — which is precisely what "these two words are related" should mean once meaning lives in direction. That is why the parent's score matrix is (every query dotted with every key).

Figure — The original  - Attention is All You Need -  architecture

5. Softmax — turning scores into a fair vote

Why the exponential and not just "divide by the total"? Two reasons. First, raw scores can be negative; is always positive, so every weight is a valid share. Second, exaggerates the winner — a slightly higher score grabs a much larger slice, which lets attention focus sharply on the most relevant token instead of spreading itself thin.

Figure — The original  - Attention is All You Need -  architecture

6. Q, K, V — three costumes for the same tokens

Analogy. A library search: your typed query meets each book's index card (key); the match strength decides how much of each book's contents (value) you carry away.

Why the topic needs it. Splitting one arrow into these three roles lets the same token behave differently as a seeker versus as a target. Without it, attention could only measure raw similarity, never learned, task-specific relevance. This is the core of Scaled Dot-Product Attention and Multi-Head Self-Attention.

6a. heads and the final mix

Figure — The original  - Attention is All You Need -  architecture

7. Mean, variance, and layer normalization — keeping numbers tame

Figure — The original  - Attention is All You Need -  architecture

Why the topic needs it. Deep stacks make numbers drift huge or tiny, and softmax + dot products misbehave at extremes. Layer Normalization uses exactly this to keep every arrow at a sane scale before the next layer; and give it a way to undo the squashing when helpful.


8. Why and appear


9. How it all connects

Tokens as numbers

Token grid X

Embedding E plus PE

Matrix reshape xW plus b

Transpose

Q K V roles

Dot product

Scores QKT

Scale by sqrt dk

Softmax to weights

Split into h heads

Blend values V

Mix heads with WO

Attention output

Mean and variance

Layer Normalization gamma beta

Transformer layer

Read it top-down: tokens become embedding-plus-position arrows in a grid, arrows get reshaped into Q/K/V, transpose lets dot products score them, scaling + softmax turn scores into a vote, heads split the width, the vote blends the values, mixes the heads, and normalization (with ) keeps everything stable enough to stack six times.


Equipment checklist

Cover the right side and answer aloud — if you can, you are ready for the parent note.

What is a vector, in one picture?
An arrow of numbers pointing to a spot in -dimensional space.
What does the symbol mean?
The set of all real numbers — any ordinary number on the number line.
In the token grid , what is a row, and what is a column?
A row is one token at position ; a column is one feature slot shared across all tokens.
What does describe?
A grid with rows and columns — one arrow per row.
Where does a token's starting arrow come from?
Add the meaning arrow to the position arrow .
In the row-vector convention, what shapes must and have for to work?
and ; shifts the reshaped arrow.
What do and stand for?
The lengths of the arrows going into and out of a reshape.
What does the transpose do and why is it in ?
Swaps rows and columns so key arrows become columns, letting one multiply compute all query–key dot products.
What single number does a dot product give, and when is it large?
A relevance/alignment score; large and positive when the two arrows point the same direction.
Why is attention built on dot products rather than distances?
We need one number for "how related?"; the dot product measures directional agreement, which is exactly relatedness once meaning lives in direction.
What does softmax output, why the exponential, and what stability trick is used?
Positive weights summing to 1; the exponential keeps them positive and sharpens focus; subtract before exponentiating to avoid overflow (same result).
What are the shapes of , , ?
and .
What does do to the width , and what does do afterwards?
Splits it into blocks of size ; mixes the concatenated heads back into one output.
What does mean and why divide scores by ?
is the number whose square is ; dot products grow like , so dividing cancels that and keeps softmax in its high-gradient range.
What do , , , do in layer norm?
recenter and rescale to mean 0 / spread 1; are learned scale and shift applied afterward.