How AI Learned to Read Pictures Like Sentences
For years, Convolutional Neural Networks (CNNs) ruled computer vision. They work by scanning an image with small filters, building up from simple edges to complex shapes layer by layer. Vision Transformers took a sledgehammer to that approach. Inspired
by models that mastered human language, ViTs treat an image like a sentence. The process is straightforward: the model chops an image into a grid of smaller, non-overlapping patches, like a jigsaw puzzle. Each patch is then flattened and treated as a "token," analogous to a word. This sequence of patch-tokens is fed into a transformer, which uses a mechanism called self-attention to weigh the importance of every patch against every other patch, giving it a global understanding of the image from the very first layer.
The Problem: How Do You Classify a Bag of Patches?
So the ViT has looked at all the patches and understands how they relate. A patch of a floppy ear is related to a patch of a wet nose. But how does the model consolidate all this information to make a single decision, like declaring the image is a "dog"? A common but inefficient approach would be to average the information from all the patch tokens at the end. This is known as global average pooling. However, the architects of the ViT borrowed a more elegant solution directly from the world of Natural Language Processing (NLP), specifically from models like BERT.
The Hidden Detail: The Class Token
The hidden detail most engineers gloss over is the existence and function of the Class Token, often written as `[CLS]`. Before the sequence of image patches is fed into the transformer, a special, extra token is added to the very beginning of the sequence. This `[CLS]` token is a learnable vector that starts with no information about the image. Think of it as an empty bucket or a dedicated class representative. As the sequence of patches and the `[CLS]` token pass through the transformer's layers, the self-attention mechanism allows the `[CLS]` token to interact with every single image patch. It effectively asks each patch what it contains and how it relates to others, gathering and aggregating this information. By the final layer, this single `[CLS]` token has become a rich, dense summary of the entire image.
Why This One Token Is Everything
Skipping over the `[CLS]` token is easy because it's an implementation detail, but its implications are huge. When it's time for the ViT to make a final classification, it completely ignores the output of all the image patch tokens. Instead, it looks exclusively at the final state of the `[CLS]` token. This single vector is fed into a small, simple classification head (usually a single linear layer) that makes the final prediction. This design is incredibly efficient. Instead of wrestling with dozens or hundreds of patch outputs, the model has forced all the necessary information into one specific, designated place. Understanding this reveals why ViTs are so powerful: the architecture isn't just looking at patches; it's actively learning how to build a holistic summary from those patches into a dedicated slot. For engineers, appreciating the `[CLS]` token's role is key to debugging and even designing more advanced multi-modal systems where different types of tokens need to interact.











