MLGuerrillaStart M1 →
Architectures·16 min read·Updated 24 September 2026

Vision Transformer (ViT)

A Vision Transformer cuts an image into squares, treats each square as a token, and runs the same transformer a language model runs. It is the backbone inside CLIP, SigLIP, DINOv2 and every vision-language model on this index.

A Vision Transformer takes an image as input and returns a vector for every square it cut the image into, plus one extra vector standing for the whole thing. The architecture doing the work is the transformer, unchanged from the one built for translation.

Getting there took one idea. Cut the image into a grid of fixed squares, flatten each square, multiply it by one learned matrix to get a vector, and hand the resulting sequence to a transformer as though the squares were words. Dosovitskiy et al. (2020) put it in their title as an image being worth 16 by 16 words, and showed in the abstract that "a pure transformer applied directly to sequences of image patches can perform very well on image classification tasks".

What it is

The picture becomes a sequence, and each patch's position is a learned vector

Running one photo through the original checkpoint shows every step of that, with the numbers each one produces.

A four-step figure titled "An image becomes 196 tokens, and a transformer reads them", from one photo through google/vit-base-patch16-224 at 86.6M parameters. Step one shows a 224 by 224 street photo overlaid with a 14 by 14 grid, giving 196 patches of 16 pixels, with one square outlined in terracotta. It explains that each patch is 768 pixel values flattened and multiplied by one learned matrix to give 768 numbers, that nothing convolutional happens and no patch sees any other yet. Three real rows are printed: patch 1 begins -0.17, -0.08, +0.06, +0.07, -0.01; patch 106, the terracotta square, begins -0.32, -0.03, -0.19, -0.08, +0.14; and patch 196 begins -0.19, -0.03, -0.09, +0.09, -0.01, each with 768 numbers. Step two, headed a learned position vector is added and it says where each patch sits, shows a 14 by 14 heatmap of how similar patch 106's position embedding is to every other patch's, with a bright centre and a visible cross along its row and column. Four measurements are given on a track running from -0.70 to +1.00: the patch itself at +1.00, the patch beside it at +0.80, ten patches away at +0.22, and the far corner at -0.16. It notes that the model taught itself the row and the column, which is what that cross is. Step three shows 197 tokens, a CLS chip outlined in terracotta followed by p1 through p5 and 191 more, passing through 12 layers in 266 milliseconds on a Mac CPU and producing traffic light at 0.156 of 1,000 classes. It explains that the CLS token belongs to no patch, is read out at the end, and is the only one the classifier looks at, and that the next four guesses were mailbag 0.061, street sign 0.051, trench coat 0.050 and cloak 0.034, because ImageNet has no class for a street. Step four, outlined in terracotta, shuffles the 196 patches and shows the scrambled image beside three bars: traffic light before at 0.156, traffic light after at 0.011, and umbrella after at 0.324. It notes that every patch is still there and every pixel unchanged, only the order moved, and that the model is now twice as confident about an umbrella as it ever was about the street. The caption reads: the patches carry the picture, and the position vectors carry where the picture was.
The three printed vectors are the real output of the patch embedding layer on this photo. Patch 106 is the square outlined on the image, so you can see which part of the street it came from.

The patch embedding is one matrix multiplication and nothing else, with no convolution and no pooling. The layout inside a patch survives, because every patch is flattened in the same pixel order, so the matrix can learn edge and texture patterns within those 16 by 16 pixels. The paper found its learned filters "resemble plausible basis functions for a low-dimensional representation of the fine structure within each patch". What the embedding can't tell is where a patch sits among the others, for example that patch 92 is directly above patch 106. That arrangement comes from the position vectors added in step two.

Those position vectors are learned, and the paper is explicit that they start out knowing nothing, saying "the position embeddings at initialization time carry no information about the 2D positions of the patches and all spatial relations between the patches have to be learned from scratch". What they look like afterwards is the heatmap: a patch is most similar to itself, then to its neighbours, with a cross along its own row and column. The model worked out the shape of a grid from photographs.

The shuffle in step four shows the model uses that arrangement. Every pixel is still present and only the order of the patches changed, and the answer went from a traffic light at 0.156 to an umbrella at 0.324. The drop shows that the model reads the arrangement of the patches, and a CNN given the same shuffled photo would likely lose its answer too.

Keep reading

The rest of this article is free with an account

Create a free account to read the remaining 6 sections. It takes about twenty seconds and there's nothing to pay. The same account opens the slide decks and CV reviews.

  1. 02Where Vision Transformers show up
  2. 03Patches, positions, and heads that behave like convolutions
  3. 04The checkpoints you'll see, as of September 2026
  4. 05Choosing, and when a CNN is still the answer
  5. 06How to try it
  6. and 1 more