Concept · Chapter 7: Transformers
Feed-Forward Sublayer (MLP)
The feed-forward sublayer is a small two-layer neural network applied to each token separately, transforming the information that attention has gathered.
The problem
Attention only mixes existing vectors by weighted averaging; on its own it can't compute new nonlinear features of a token.
The solution
After attention, pass each token's vector through an MLP: expand to a wider hidden layer, apply a nonlinearity, project back.
The consequence
Attention moves information between tokens; the MLP processes it within each token. The MLPs hold most of a Transformer's parameters and are thought to store much of its learned knowledge.
You should understand first
- Vectors
- Feed-Forward Sublayer (MLP)
What it computes
expands from to a wider hidden size (4× in the original: 512 → 2048), is a nonlinearity (ReLU originally; GELU in GPT-2; gated variants like SwiGLU in many recent LLMs), and projects back.
"Position-wise" means the same weights are applied to every token, but each token separately — no information passes between tokens here. That's attention's job.
Where the parameters are
Per block, attention has four matrices (): parameters. The FFN has two matrices: . So roughly two-thirds of a standard block's parameters sit in the feed-forward sublayer Established. Interpretability work suggests these MLPs act partly like key–value memories that store factual associations Interpretation — the 3Blue1Brown video below explores this idea.
What to remember
- FFN(x) = W₂ · activation(W₁ x + b₁) + b₂, applied to each position independently.
- Hidden width is typically 4 × d_model.
- About two-thirds of a standard block's parameters are in the FFN.
Key papers
Attention Is All You Need
Ashish Vaswani, Noam Shazeer et al. · 2017 · NeurIPS 2017
Introduced the Transformer — the architecture behind BERT, GPT and nearly every modern large language model, and later adapted to vision, audio and more.
How to read it: Section 3 is the architecture — read it with Figure 1 open. Sections 3.2.1–3.2.2 contain the attention equation. You can skim the training details on a first pass.
Watch
3Blue1Brown
How might LLMs store facts | Deep Learning Chapter 7
The feed-forward half of a Transformer block gets less attention than attention; this fixes that.