Skip to content

vision transformer (ViT)

A vision transformer (ViT) is a neural network architecture that applies the transformer to images by cutting a picture into fixed-size patches and treating that sequence of patches the way a language model treats a sequence of tokens.

Each patch, typically 16 by 16 pixels, is flattened and mapped through a trainable linear projection into an embedding. A learnable class token is prepended to the sequence to gather a summary of the whole image, and learnable 1D position embeddings record where each patch sat in the original grid.

A standard transformer encoder then runs self-attention over the whole sequence, so every patch attends to every other patch from the first layer onward rather than building up a receptive field gradually as a convolutional neural network (CNN) does.

The widget below cuts the same picture into patches at three sizes, and the token sequence grows as the patches shrink. Picking a patch then shows what layer one reaches from it: every patch in the image under self-attention, or a single 3 by 3 neighborhood under a convolution.

Interactive diagram — enable JavaScript to view.

That global view costs the model its image-specific inductive bias, the built-in assumptions about image structure that help a model learn from fewer examples. Locality and translation equivariance are baked into every convolutional layer but not into attention, so a ViT trained on a mid-sized dataset such as ImageNet trails a comparable CNN.

The 2020 paper by Dosovitskiy and colleagues that introduced the architecture found that ordering reverses once pretraining data reaches 14 to 300 million images.

Hugging Face Transformers exposes the original Google checkpoints, whose names carry the patch size and input resolution, as in google/vit-base-patch16-224, and fine-tuning one on a smaller labeled set is the usual route to a specific task. Patch encoders of this shape now sit behind much of modern computer vision, including the image half of multimodal large language models.

Hugging Face Transformers: Leverage Open-Source AI in Python

Tutorial

Hugging Face Transformers: Leverage Open-Source AI in Python

Get hands-on with Hugging Face Transformers in Python. Download, run, and inspect pretrained open-source AI models, and speed up inference on GPUs.

intermediate ai

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Martin Breuss • Updated Oct. 17, 2026