Log inStart free
LESSON 25.02 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Vision Transformers

Watch an 8 × 8 image become patch tokens and one image embedding.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 25.02 · VIT BAY8×8 IMAGE · 4 PATCHES OF 4×4
01
Stage 1 of 6 · Cut into patches
The 8 × 8 image splits into 4 patches of 4 × 4 pixels. Each patch becomes one token.
Explain it simply

A transformer compares every token with every other token. If each of these 64 pixels were a token, that would be 64 times 64, or 4,096 comparisons. So the Vision Transformer cuts it into 4 by 4 squares: 4 tokens instead of 64. A real 224 pixel photo cut into 16 pixel patches gives 196 tokens.

An 8 by 8 image of a 7. A grid splits it into 4 patches of 4 by 4 pixels, numbered row by row.

The class token and the attention weights are random, not trained.
pixels and tokensstencils, patch grid, positionsattention and embeddingnegative value
12341234patchesN = 8·8 / 4² = 4 patchesthe image and its patchesimage 8 × 812341234patchesN = 8·8 / 4² = 4 patchesthe image and its patchesimage 8 × 8
Toy: an 8 × 8 image of a 7, 4 numbers per token
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
N=H⋅WP2\sy{n}{data}{N} = \dfrac{H \cdot W}{\sy{P}{param}{P}^2}
N=8⋅842=4N = \dfrac{8 \cdot 8}{4^2} = 4

The patch count is the pixel count over the patch area.

Common mix-ups

MYTHA Vision Transformer knows where each patch sits by itself.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With 2 px patches, how many tokens enter attention?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.