↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Block 1 of 12 recorded: 14 × 14 = 0 tokens, a 7 × 7 window drawn (rows 4–10, columns 4–10) · no queries, keys or softmax · one MLP for all 768 channels
Loading recorded token mixing…

What MLP-Mixer is

MLP-Mixer (Tolstikhin et al., 2021) is a vision model built only from multi-layer perceptrons. Like ViT it cuts the image into patches; then it alternates two kinds of MLP, one applied to each patch separately, mixing its channels, and one applied to each channel separately, mixing the patches. The second, the token-mixing MLP, takes attention's place. The paper's point is that neither convolution nor attention is necessary for competitive image classification, given large training sets or modern regularisation.

The page records MLP-Mixer B/16, pre-trained on ImageNet-21k and fine-tuned on ImageNet-1k. Patches of 16 pixels cut a 224-pixel image into a 14 × 14 grid of 196 tokens with 768 channels each, processed by 12 blocks, of which blocks 1, 6 and 12 are recorded. Its top-1 guesses are Egyptian cat (99 %), beagle (93 %), space shuttle (100 %, for the astronaut) and envelope (97 %, for the coloured shapes).

The Mixer block

Treat the input as a table of 196 tokens by 768 channels. A block first mixes along the tokens, column by column, then along the channels, row by row:

The token-mixing MLP, 196 → 384 → 196, runs on each channel's column of 196 values with the same and for all 768 channels. The channel-mixing MLP, 768 → 3,072 → 768, runs on each token's row. Only the token-mixing MLP moves information between patches, so it is what this tab shows: the Mixer input column holds its input after the LayerNorm and the Token-MLP output column its output, before the residual add.

The MLP as an input-dependent matrix

The model uses the exact GELU, , where is the standard normal distribution function. So for channel , with input column and hidden pre-activations ,

exactly. On a given input the token-mixing MLP acts as a 196 × 196 matrix plus a bias. and are fixed after training, but the gates , one per hidden unit, come from the channel's own tokens, so each image and each channel gets its own matrix. The Effective mixing card draws a 7 × 7 window of for the first three channels, and the selected token's whole row is drawn on the image; the popup sums the row against the input and matches the recorded output.

Against the cat image's matrices, the other images change by about 1 % in block 1 and by about 7–11 % in blocks 6 and 12; the note under the image gives the figure for each one.

What the weights look like

The First layer W₁ panel shows 16 of the 384 hidden units' first-layer weights as 14 × 14 maps, one weight per token, with each unit's gate for the selected channel as a bar. Because every token has its own weight, a token-mixing unit can learn any spatial pattern; the paper's visualisations show some units acting on small regions and others on the whole image. Unlike a convolution, nothing forces the weights to repeat across positions; unlike attention, nothing makes them depend on what the patches contain, except through the gates.

A token's weight on itself can dwarf the rest of its row, near −4.5 for a few tokens in block 1, so the card sets the diagonal aside from the colour scale by default; the toolbar button puts it back.

Order, size and convolution

Mixer uses no position embeddings: the token-mixing MLP gives every position its own weights, so it already knows where each patch is. The cost is a fixed input size, since has exactly 196 inputs. The paper also reads Mixer as an unusual convolutional network: channel mixing is a 1 × 1 convolution, and token mixing is a single-channel depthwise convolution with a kernel as large as the image, whose weights are shared across channels. The ConvNeXt tab shows the opposite trade: a small 7 × 7 kernel, separate for each channel.

Where it came from

MLP-Mixer appeared in May 2021, within weeks of ResMLP (Touvron et al.), which mixes tokens with a single linear layer, and gMLP (Liu et al.), which gates a token-mixing projection by the input. All three followed ViT (2020) in treating an image as a sequence of patches. The MetaFormer view (the PoolFormer tab) later argued that the block structure they share matters more than the mixer inside, and FNet (the FNet tab) replaced the learned token mixer with a fixed Fourier transform.

Papers

  1. MLP-Mixer: An all-MLP Architecture for Vision Ilya Tolstikhin et al. · NeurIPS 2021 The Mixer architecture: token-mixing and channel-mixing MLPs, and the B/16 model recorded here.
  2. An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale Alexey Dosovitskiy et al. · ICLR 2021 The Vision Transformer, whose 16-pixel patches and attention Mixer keeps and replaces.
  3. Gaussian Error Linear Units (GELUs) Dan Hendrycks, Kevin Gimpel · arXiv 2016 GELU(h) = h Φ(h), the identity that turns the token MLP into an input-dependent matrix.
  4. ResMLP: Feedforward networks for image classification with data-efficient training Hugo Touvron et al. · arXiv 2021 A concurrent all-MLP vision model whose token mixer is a single linear layer.
  5. Pay Attention to MLPs Hanxiao Liu, Zihang Dai, David R. So, Quoc V. Le · NeurIPS 2021 gMLP: a token-mixing projection gated by the input, for vision and language.
  6. MetaFormer Is Actually What You Need for Vision Weihao Yu et al. · CVPR 2022 Argues the block around the token mixer matters most, with pooling as the mixer (the PoolFormer tab).

See also