The small circuit a transformer runs again and again: mix context, preserve a route, stabilize the numbers, then enrich the signal.
In one lineAttend → add what you had → normalize → think wider.
TRANSFORMER_BLOCK / 06 repeatable
signal insignal out
self-attention
feed-forward
mix → preserve → enrich8 stages / toy trace
one circuit / many passes
Short version: a transformer block changes a representation without throwing the old one away.Step through the circuit.
00 Overview / start here
One small circuit. Repeated.
A language model needs to keep a useful thread of meaning while it adds context and new features. The transformer block is the repeatable unit that does this work.
familiar problem
How can “it” keep its identity and use new context?
In “The robot carried the battery because it was heavy,” the token “it” starts with a rough representation. It needs the surrounding words, but the next calculation should not erase what “it” already carried.
plain-language definition
A block is a reusable context mixer.
It lets tokens exchange information with self-attention, adds the previous signal back through a residual path, stabilizes the scale with normalization, and then applies a small feed-forward network.
the complete storybefore → inside the block → after
BEFORE / embeddingsEach token has a numeric signal.
For this lesson, “it” is a four-number vector. The vector is a calculated state; the embedding table that produced it is learned.
INSIDE / two jobsAttention gathers context; FFN reshapes features.
Attention mixes information across positions. The feed-forward network works on each position separately to create richer features.
AFTER / representationA better signal leaves the block.
Residual additions keep a direct route from earlier values. The output can enter the next identical block, many times.
one concrete mini-story
“it” → context → a steadier clue
Attention pulls in a little “battery” and “heavy” information. The first residual adds the original “it” signal back. The FFN notices a feature combination, the second residual keeps both, and normalization keeps the values workable.
The names are less important than the sequence. Move stage by stage and watch the same four-number signal change. Use Previous, Next or the arrow keys when the stepper has focus.
Eight stops, one repeatable unit.
This is a toy trace for the token “it.” Values are rounded to two decimals. The attention mix and FFN weights are illustrative learned parameters; residual addition and normalization are calculated from the current state.
EXPERIMENT / 01embeddings → attention → output
current stageEmbeddings
A token begins as a row of learned numbers. Nothing has mixed yet.
01/ 08
keyboard← / → move · Home / End jump
start with the token’s learned vector8 stages / one toy position
A block does not replace the signal in one leap. It edits the signal in careful passes.
02 Run the skip-path experiment
Keep a route back to before.
A residual connection is an element-wise addition: line up two vectors and add their matching coordinates. Toggle it to see what the block loses when the direct route disappears.
Original signal + new signal.
The gauge below is deliberately simple: it shows how much of each original component is present in the first sum. It is not a probability and does not claim that a real model has a literal percentage of “old meaning.”
original component in the sumresidual on / 74% average share
Each coordinate receives the old value and the new value. The block can add context without forcing the old route to vanish.
element-wise addition / four matching coordinatesskip path active
The shortcut is not laziness. It is a memory lane.
03 Repeat the unit
Same circuit, more passes.
One block can make a small update. A stack of identical-shaped blocks can make a representation progressively richer. Change the depth and compare the toy states.
How depth changes the trace.
This control repeats the same illustrative block. It is not a trained language model: the weights stay fixed, the dimensions stay tiny, and the changing vectors only demonstrate repeated transformation.
EXPERIMENT / 03block × depth → representation
one local editdeeper stack
toy representation after each pass
pass
vector state
what can change
same block shape / repeated state update1–4 passes / illustrative
Depth is not a new kind of block. It is another chance to transform the same kind of state.
04 Do the small math
From vector shape to calculated state.
Now pin the moving picture to one explicit calculation. This makes the boundary clear: learned weights are parameters; the vectors that pass through the block are calculated states.
One block, written in the order it runs.
The left side is static so you can read it slowly. The right side mirrors the same numbers and labels the shapes, operation order and value origin.
static equivalent / hand calculationthe signal moves down
No run yet. The output will match the calculation above.
What this omits: batching, positional details, multiple attention heads, dropout, masking and training. Those are important production details, but hiding them here keeps the block’s causal order inspectable.
06 Consolidate / try this
Can you narrate the route?
Close the loop without memorizing the labels. Use the experiments above as evidence, then make one prediction.
TRY / 01
Predict one toggle.
Turn the residual connection off. Before you look at the output, predict what happens to the original vector’s component share and why the later normalization still runs.
TRY / 02
Change one value by hand.
Replace the attention weight for “robot” with 0.80 and lower the “The” weight. Which part of the attention mix gets louder? Which residual coordinates change?
TRY / 03
Say the mental checklist.
Embeddings start the state. Attention mixes positions. Residuals preserve a direct route. Normalization keeps scale manageable. FFN enriches each position. The same shape can enter another block.
limits / deferred production details
This field guide uses one token position, four features, fixed toy parameters and a simplified post-attention order. Real LLMs add positional information, multiple heads, causal masks, layer-norm variants, efficient kernels, batching, training updates and many more blocks. Those details refine the implementation; they do not change the core story traced here.
source note The original Attention Is All You Need paper introduced the Transformer architecture. This page’s vectors, weights and outputs are deliberately tiny teaching values. For normalization background, see the original Layer Normalization paper.
FAQ Transformer blocks / quick answers
Repeat the circuit.
Keep the reusable unit clear before the full transformer story gets larger.
· illustrative lesson
01 / definitionWhat is a transformer block?
A transformer block is a repeatable unit that lets positions exchange context through attention, updates features with a feed-forward network, and uses residual paths and normalization to keep the signal workable.
02 / residualsWhat is a residual connection?
A residual connection adds an earlier vector back to a transformed vector element by element. It gives the block a direct route for preserving useful information while adding a new update.
03 / depthWhy stack transformer blocks?
Each block can refine the representation it receives. Repeating the same overall shape lets later blocks work with a state that already contains more context and feature transformations.