What Is a Vision Transformer?
How a transformer reads a photo as small patches, why it needs so much data, and what it costs, explained simply for your AI interview.
In short
A vision transformer is a transformer that reads an image as a row of small square patches, much as a language model reads words. It was introduced in 2020, and it needs a lot of training data to do well against older image models.
11 min readIntermediateOccasional · estimateFacts checked 27 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
A vision transformer is a transformer that reads a picture as a row of small square patches, the way a language model reads words. Each patch becomes one item, and every item can look at every other item. It needs a lot of training data, because it has fewer built-in image habits than older convolutional networks. Its cost also grows fast with the number of patches, so I would test a simple convolutional network first on a small dataset.
A vision transformer is a transformer that reads pictures. A transformer is the design that has become the standard for language tasks: it reads a row of pieces, and each piece looks at every other piece. For a picture, the pieces are small square patches, such as 16 by 16 pixels. Each patch becomes one item in the row, the way a word does in a sentence.
Here is how a photo becomes a label. The image is cut into patches. Each patch is turned into a list of numbers, and a position is added so the model knows where it sits. An extra slot goes at the front of the row. After the transformer layers, the final value of that slot goes to a small classifier, which picks the label. So a photo of a dented car door can come out labelled "dent".
The catch is data. Convolutional networks, the older image design, come with built-in habits about pictures, such as looking at neighbouring pixels. A vision transformer has fewer of those habits, so with a small set of labelled photos it often trails a convolutional network. The 2020 paper found the gap closes with large training data. The cost also grows fast: attention compares every patch with every other, so a 1024 by 1024 photo cut into 16 by 16 patches has 4,096 patches, and about 16.8 million pairs to compare in each attention head.
In an interview, say that it depends on the data, name the trade-off, and offer to test a convolutional network first.
What is a vision transformer, in plain words?
A vision transformer, or ViT, is a transformer that works on pictures. A transformer is the design that has become the standard for language tasks. It reads a row of pieces, such as words, and lets each piece look at every other piece. A vision transformer does the same with an image, after cutting the image into pieces.
The pieces are small squares of the picture called patches. The paper that introduced the idea used 16 by 16 pixel patches as its running example. Each patch is handled the way a language model handles a word.
Think of a claims assessor at an insurer who gets a phone photo of a dented car door. She does not take in the whole photo at once. She cuts it into a grid, checks each square, and compares squares to see which parts belong to the same dent. A plausible case is an app that reads photos of car damage and tags the panel, so a person only checks the unclear ones.
Key words
- Patch
- A small square of the picture, such as 16 by 16 pixels.
- Token
- One item the transformer reads. For images, each patch becomes one token.
- Self-attention
- The step where every token looks at every other token and decides which ones matter to it.
- Class token
- An extra slot added at the front. Its final value is used to give the label.
A Google Research team posted the paper to arXiv on 22 October 2020. Its title says the idea in one line: "An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale".
How does a vision transformer turn a photo into a label?
It runs a few steps in order. The chart shows the path, and the steps below follow it.
From photo to label
Car door photo
one picture, 224 by 224 pixels
Patches
Cut into 16 by 16 tiles
196 tiles for 224 by 224
Tiles become numbers
each tile gets its position
Transformer
every tile looks at every tile
Label: dent
read from the class token
- 1The photo is cut into square tiles of 16 by 16 pixels.
- 2Each tile becomes a list of numbers, with its position added.
- 3All the tiles go into the transformer, which compares them.
- 4The label is read from the class token, the extra slot.
- 1
Cut the picture into patches
A 224 by 224 pixel photo cut into 16 by 16 squares gives 14 rows of 14, so 196 patches.
- 2
Turn each patch into numbers
A learned step turns every patch into a list of numbers, called its embedding.
- 3
Add a position to each patch
Without a position, the model would not know which tile sat at the top or the bottom of the door.
- 4
Add the class token
One extra learnable slot goes at the front, so the row has 197 items: 196 patches and this slot.
- 5
Read the label
The transformer layers run, and the final value of that slot goes to a small classifier that picks the label.
The middle part is the standard transformer stack, called an encoder: layers of self-attention, each followed by a small per-patch network, repeated. Each attention step lets every patch use information from every other patch.
Why does it need so much data?
A convolutional neural network, or CNN, is the older image design. It has built-in habits about pictures. It looks at small neighbourhoods of pixels, and the same filter slides across the whole image. The paper calls these built-in assumptions inductive biases, the habits a model starts with before it sees any data.
- CNN
Built-in habits
Local looks and one filter reused everywhere, so it learns from fewer images.
- ViT
Learns the habits
Only the small per-patch networks inside each layer (called MLPs) are local. Attention looks across the whole picture, so layout must be learned from data.
- Small data
The CNN often wins
With few labelled images, the missing habits show, and a convolutional network usually does better.
“We show that this reliance on CNNs is not necessary and a pure transformer applied directly to sequences of image patches can perform very well on image classification tasks.”
Dosovitskiy et al., 2020, abstract
“We find that large scale training trumps inductive bias.”
Dosovitskiy et al., 2020, Section 1
The paper's answer is that more data closes the gap. It trained on larger sets, from 14M to 300M images, and found that large scale training beats the built-in habits. On mid-sized sets without strong regularisation (extra rules that stop the model memorising its training photos), a vision transformer trailed ResNets (a well-known family of convolutional networks) of comparable size by a few points.
A worked case: a mid-size insurer has 6,000 labelled damage photos. A plain vision transformer trained only on those photos is a risky bet. A safer route is a vision transformer first trained on a large general image set (pre-training), then trained further on the 6,000 photos (fine-tuning). Test a convolutional network, the older design, on the same photos before you choose.
Tip
Asked whether a vision transformer beats a CNN? Say it depends on the data. Large pre-training data favours the transformer. Small data often favours the CNN.
What does it cost, and why do patch sizes matter?
Attention compares every token with every other token. The paper makes the point for raw pixels, where each pixel would attend to every other pixel: "With quadratic cost in the number of pixels, this does not scale to realistic input sizes." Cutting the image into patches keeps the token count far below the pixel count. Doubling the number of tokens roughly quadruples the comparisons.
Take a 1024 by 1024 pixel photo cut into 16 by 16 patches. That gives 64 rows of 64, so 4,096 tokens. Each pair of tokens is compared, which is 4,096 times 4,096, about 16.8 million pairs per attention head, per layer.
Halve the patch to 8 by 8 and the tokens become 16,384. That is four times the tokens and sixteen times the pairs, about 268 million. Smaller patches see finer detail, but they cost much more to run.
Tip
Interview tip: cost grows with the square of the token count. Shrinking the patches is a quality lever with a steep bill.
How would you choose a model for a factory defect camera?
A plant makes steel brackets and has about 300 labelled defect photos a month. The lighting is fixed and the camera angle never changes. The team asks whether to use a vision transformer.
- Try first
A simple CNN
Small data and a fixed scene suit the built-in habits. It is the reference to beat.
- Try next
A vision transformer
First trained on a large image set, then trained further on the plant's photos.
Measure both on photos the models never saw in training, and check the speed on the hardware the factory really has. Pick the simpler model unless the transformer wins by a margin that matters to the line.
What does the interviewer want to hear?
A strong answer covers
- A plain definition: a transformer that reads an image as patches.
- How a photo becomes a label: patches, numbers, positions, class token.
- Why it needs data: fewer built-in image habits than a CNN.
- The cost: attention grows with the square of the number of patches.
- A test plan: a plain CNN, checked on photos it never trained on.
- Honest limits: it depends on the data and the hardware.
Common traps
Trap"A vision transformer is always better than a CNN."
BetterIt depends on the data size. With little data, a CNN often wins, as the paper found on mid-sized sets.
Trap"Smaller patches are free detail."
BetterSmaller patches mean more tokens, and attention cost grows with the square of that count.
Trap"Each patch is just a pixel."
BetterA patch is a block of pixels, turned into a list of numbers and treated as one token.
Can you spot the mistake?
Spot the mistake
A junior engineer wants a vision transformer trained from scratch on 2,000 photos, and says it will beat the CNN. What is wrong?
Quick check
A vision transformer with 16 by 16 patches reads a 224 by 224 photo. How many patches come out, not counting the class token?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
Last updated on 27 November 2026
Building a product that reads photos or documents?
I design and build AI products and agents, including the screens and the system behind them. Book a short call and tell me what your images need to show.