Vision Transformers — When Attention Came for Images

For a decade, convolution was synonymous with computer vision. Then the transformer — the architecture that revolutionized language — was applied to images, and the vision transformer showed that attention could match or beat CNNs given enough data. It's a profound shift: the same architecture now underpins both language and vision, enabling the multimodal models that see and read at once. This post explains how transformers handle images and what their rise means.

Posts 3–5 built the CNN world. This post covers the architecture that challenged it — the vision transformer (ViT) — and why it matters beyond vision: it unified the architectures of AI’s two biggest domains. It connects directly to the blog’s transformer and Multimodal AI coverage, now from the vision side.

Treating an image as a sequence of patches

The transformer was built for sequences of tokens (words), using attention to let every token relate to every other (covered elsewhere on the blog). Images aren’t sequences — so how do you apply a transformer to one? The vision transformer (ViT) answer is elegantly simple: chop the image into a grid of fixed-size patches (say 16×16 pixels), treat each patch as a “token” (like a word), and feed that sequence of patches to a standard transformer.

That’s the core trick — an image becomes a sequence of patches, and from there it’s essentially the same transformer as in language: - Each patch is linearly projected into a vector (a patch “embedding”), with position information added so the model knows where each patch sat (since attention itself is order-agnostic). - The transformer’s self-attention then lets every patch attend to every other patch, directly modeling relationships across the whole image in a single layer.

This is the fundamental difference from a CNN (post 3). A CNN builds up global understanding gradually — early layers see only local neighborhoods, and it takes many stacked layers for information to travel across the image (post 3’s receptive field). A ViT’s attention gives global context immediately: in the very first layer, a patch in one corner can directly attend to a patch in the opposite corner. Where convolution’s inductive bias is locality, attention’s strength is long-range, all-to-all relationships — a genuinely different way of processing an image.

Convolution vs attention: inductive bias and data

The ViT-vs-CNN comparison is a clean lesson in a deep trade-off: built-in assumptions vs learning from data.

This produces the headline finding: ViTs underperform CNNs on small datasets but match or beat them when trained on very large datasets. With enough data, learning the right biases from scratch beats having good-but-fixed biases built in. This is a profound and recurring theme in deep learning (it echoes the “data beats hand-crafted structure at scale” lesson from classical-features-vs-CNNs, post 2) — and it’s why ViTs rose as massive datasets and compute became available. The practical consequence: ViTs shine when you can pretrain on huge data (then transfer, post 7); CNNs remain excellent and more data-efficient for smaller problems. In practice, hybrid architectures that combine convolution’s efficiency with attention’s global reach are also common, getting the best of both.

Why this matters beyond vision

The vision transformer’s deepest significance isn’t just competitive accuracy — it’s architectural unification, and this is the point to carry away:

The honest framing: ViTs didn’t make CNNs obsolete — CNNs remain excellent, efficient, and widely used, especially with limited data, and hybrids are common. But the vision transformer changed the landscape by proving attention works for images, by unifying the architectures of vision and language, and above all by enabling the multimodal models that are central to modern AI. It’s the bridge that let the two great branches of deep learning become one, which is why it matters far beyond any benchmark.

The throughline: the vision transformer (ViT) applies the language transformer to images by chopping an image into fixed-size patches, treating each patch as a token, and running a standard transformer whose self-attention gives every patch global context immediately — the opposite of a CNN’s gradual, local build-up (locality vs long-range all-to-all). This exposes a deep trade-off: CNNs have strong, correct inductive biases (locality/translation-invariance baked in → data-efficient on small data), while ViTs assume little and must learn structure from data (worse on small data, better at scale) — the headline finding that data beats built-in bias when there’s enough of it, echoing classical-features-vs-CNNs. Its deepest significance is architectural unification: one architecture (the transformer) now handles both vision and language, which enables multimodal models (images-as-tokens enter the same transformer as text — powering vision-language LLMs) and exemplifies a general idea escaping its origin domain. ViTs didn’t kill CNNs (still efficient, especially small-data; hybrids common) but bridged deep learning’s two branches into one.

Key takeaways

Further reading

Sources & References