Course contentsShow
← Machine Learning and Deep Learning
Lesson 1344 of 3,53830. Vision TransformersFree lesson

MLP Head and Classification

Projecting the CLS token representation through an MLP to produce class logits.

MLP Head and Classification

What You'll Learn: How the Vision Transformer produces final class predictions from the CLS token representation.

The Final Step in Vision Transformers

After all those transformer encoder layers process your image patches, you have a sequence of token representations—including the special CLS token that has gathered global image information through multi-head self-attention. But this is still just a vector of features, not class predictions. How do you turn it into "cat" or "dog"?

The MLP Head Explained

The MLP Head (Multi-Layer Perceptron Head) is a simple feed-forward network that projects the CLS token's representation into class logits. Think of it as a translator: the CLS token speaks "feature language," but you need "class probability language."

Here's what happens:

  1. Extract the CLS token representation from the encoder output (typically the first position in your sequence)
  2. Pass it through one or more fully-connected layers (often just one for classification)
  3. Project to the number of classes you have (e.g., 1000 for ImageNet)
  4. These raw scores are your logits, which can be converted to probabilities with softmax

Why "Head"?

The term "head" refers to the task-specific component attached to the general-purpose encoder. Different heads for different tasks: a classification head for image classification, a different head for object detection, etc. The encoder body stays the same; only the head changes.

Key Takeaway: The MLP Head takes the information-rich CLS token representation and projects it through a simple neural network to produce class logits, completing the classification pipeline.