xavier-ramirez.com
STAGE 0 · 2·B · 3 NODES

The feed-forward network

Every transformer block is two halves: attention, then a small 2-layer network run on each token. That second half expands the vector, fires a gate, and compresses it back — and it's where most of a model's facts are stored. Play with the width and the gate to see how.

THE 3 STEPS
01Widen the vector02Fire the gate03Compress + add back
NODE 01 / 03

Widen the vector

Attention just mixed information between tokens. Now each token goes solo — and the first thing this little network does is make it much bigger.

  • A token is a vector — a list of numbers (about 4,096 of them) holding its meaning so far.
  • The up-projection widens it — multiply by a big matrix and 4,096 numbers become ~16,000. More dimensions = more room to compute.
  • This is where the weights are. Roughly two-thirds of an LLM's parameters live in these feed-forward layers, not in attention.
  • Each token is processed on its own — attention already shared context, so this stage just expands one position at a time.
THE UP-PROJECTION

Drag the expansion factor — watch the hidden layer and the parameter count grow.

The expansion factor is how much wider the hidden layer is than the token vector. Around 4× is standard; more capacity, more weights.

NODE 02 / 03

Fire the gate

A wide layer of numbers does nothing until you decide which parts matter. An activation acts as a gate — it opens some units and shuts the rest.

  • The gate is a switch per unit — for each of the thousands of hidden units it decides pass, block, or somewhere in between.
  • Modern LLMs use a SwiGLU gate: one copy of the vector carries values, a second copy becomes a gate value that scales it up or down.
  • This is what makes the layer nonlinear — without a gate, two matrix multiplies collapse into one and the model could only draw straight lines.
  • Different inputs open different units — that is the layer choosing which stored patterns to fire.
GOOD TO KNOW · KEY-VALUE MEMORY
Feed-forward layers store facts
Research found these layers act like a key-value memory: rows of the up-projection are keys that detect an input pattern, and columns of the down-projection are the values written back. It's why editing a single fact in a model (methods like ROME/MEMIT) targets these exact weights — the facts really do live here.
WHICH UNITS FIRE

Switch the input token — a different cluster of units lights up (green = firing).

“Paris” opens a cluster that seems to store geography and place facts. (Illustrative — real units aren't this tidy.)

NODE 03 / 03

Compress, then add it back

The wide, gated vector gets squeezed back to normal width — then added onto the vector that came in. The block edits the token; it never rewrites it.

  • The down-projection shrinks it back — ~16,000 numbers collapse to 4,096, the original width.
  • What fired writes the answer. The units that opened contribute their stored values — this is why feed-forward layers behave like memory: keys detect, values write.
  • A residual adds it back — output = input + edit. Turn it off and the token's meaning-so-far is lost.
  • Then the next block repeats — dozens of expand → gate → compress edits stack into the final prediction.
DOWN-PROJECTION + RESIDUAL

Toggle the residual — off, the edit replaces the token; on, it adds to it.

Residual ON — output = input + edit. The token keeps its meaning-so-far and the layer just adds its contribution.

EXPLAIN IT BACK
Attention and the feed-forward network sit in every block. If attention moves information between tokens, what is the feed-forward network for — and why is that where most of the weights are?
NEXT: SAMPLING STRATEGIES

After the last block, the token vector becomes a list of scores over the whole vocabulary. Next, sampling — how the model turns those scores into one actual next word, and why temperature makes it bold or careful.

Back: attentionContinue: Sampling strategies
Language: English