MLP (Multilayer Perceptron)
A feedforward neural network made of stacked fully connected layers with nonlinear activations, used as a core building block inside transformers and many other models.
Roadmap step 2 of 4: Attention and the MLP. Try it: Transformer Explainer: the transformer block ↗, LLM Visualization: a small GPT in 3D, step by step ↗
What it is
A multilayer perceptron is a neural network where each layer multiplies its input by a learned weight matrix, adds a bias, and applies a nonlinear activation function. Data flows in one direction, with no recurrence or attention. In transformers, the MLP block (also called the feedforward block) sits after each self-attention layer and is applied to every token position independently.
Why it matters
MLP blocks usually hold a large share of a transformer's parameters, so their design affects model size, speed, and capacity. They are widely thought to store much of a model's learned knowledge, which makes them a focus of interpretability work. Variants such as gated MLPs and mixture-of-experts layers are common ways to scale models efficiently.
How it works
A typical transformer MLP expands the hidden vector to a larger dimension with one linear layer, applies an activation such as GELU or SwiGLU, then projects back down with a second linear layer. The nonlinearity is what lets stacked layers represent functions a single linear map cannot. In mixture-of-experts models, the single MLP is replaced by several smaller MLPs (experts), and a router sends each token to a few of them. The result is added back to the residual stream.