v9.1.1
Menu

Token Mixing Layer

mediumFREEMLP-MixerNeural Networks, Matrix MathAdvanced Architectures

MLP-Mixer replaces self-attention with simple MLPs that mix information in two stages:

  1. Token Mixing: Mix information across spatial tokens (patches)
  2. Channel Mixing: Mix information across feature channels

Token Mixing operates on the transposed representation: Y=Wtoken⋅XY = W_{\text{token}} \cdot X

Where:

  • X∈RN×DX \in \mathbb{R}^{N \times D}: N tokens with D channels each
  • Wtoken∈RN×NW_{\text{token}} \in \mathbb{R}^{N \times N}: Learnable token mixing weights

This mixes information across the N spatial locations while keeping channels independent.

Task: Implement the token mixing forward pass.

Example

Input
X (3×2), W_token = identity (3×3)
Output
X unchanged (identity mixing)
Reasoning

With identity weights, each token keeps only its own information. Non-identity weights blend information across tokens.

Constraints

  • NN (Number of tokens): 1≤N≤2561 \leq N \leq 256
  • DD (Channels per token): 1≤D≤5121 \leq D \leq 512

More from Advanced Architectures

solution.py

Test results

Sign in to run your code against the test cases.