Macalinao StudioLearnAll enriched lessons ↗
High school path · 7 sectionsSwitch to college ↗

High school / LONGER LESSON 04

Vision transformers: pixels become a sequence

Count patch tokens and follow their projection into attention.

Preparation: Area, multiplication and matrix shapes.

Plan 20–35 minutes with the activities; this is a study estimate, not a timed requirement. Both paths have complete narration. Your notes and progress are kept separately for each level.

Section 01 / 07

Tile the image deliberately

High-school path. Count patch tokens and follow their projection into attention.

Preparation: Area, multiplication and matrix shapes. Work through one section at a time. Predict the experiment result before changing its controls, then explain what the example leaves out.

A vision transformer can divide an image into non-overlapping patches and turn each patch into a token. Patch size changes sequence length and how much local detail each token starts with. Cut a square picture into equal square tiles and count them before discussing the model.

Worked step 1. A 192 by 192 image with 16-pixel patches gives 12 by 12 tiles.

Worked step 2. There are 144 patch tokens.

Try it yourself. What happens with 8-pixel patches?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. There are 24 by 24, or 576 tokens: four times as many.

Section 02 / 07

Project a flattened patch

Flatten the patch’s pixel values and apply a learned projection. The resulting token width is a design choice, not necessarily the number of pixels in the patch. A tile’s many color measurements become a new list of learned features.

Worked step 1. At P=16, RGB flattened width is 768.

Worked step 2. Project to width 384.

Worked step 3. The projection matrix has 768 times 384 weights before bias.

Try it yourself. Does each output feature correspond to one original pixel?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. Not generally. Each can combine many input pixel values through learned weights.

Section 03 / 07

Keep position and content distinct

Patch content alone does not describe its location in the image. Position signals help distinguish arrangements; changing image resolution may require an explicit position-handling strategy. The same sky-colored tile means something different at the top or bottom of a scene.

Worked step 1. Move one tile without changing its pixels.

Worked step 2. Its content projection stays the same.

Worked step 3. Its positional context changes.

Try it yourself. Can an unordered bag of identical patch tokens recover their arrangement?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. No. The arrangement must enter through position information or another spatial mechanism.

Section 04 / 07

Count attention pairs

Dense attention compares every query token with every key token. Halving patch width on a fixed image quadruples token count and can multiply the pair count by sixteen. More tiles create many more possible conversations between tiles.

N = HW/P²; dense pairs = N²

Worked step 1. At 144 tokens, pair count is 20,736.

Worked step 2. At 576 tokens, it is 331,776.

Worked step 3. This is sixteen times larger.

Try it yourself. Are these counts including a class token?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. No. Adding one class token changes the counts to 145 squared and 577 squared.

Section 05 / 07

Compare inductive biases

Convolutions encode local weight sharing and spatial structure directly. A basic ViT relies on patching, positions and attention, and its performance depends strongly on training setup. Different tools start with different assumptions about what patterns are likely to matter.

Worked step 1. Train or inspect two models under matched data and evaluation.

Worked step 2. Record compute and resolution.

Worked step 3. Compare failure cases, not just one score.

Try it yourself. Can unequal pretraining explain a benchmark gap?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. Yes. Architecture is only one factor, so control or report the others.

Section 06 / 07

Test resolution as a trade-off

More pixels can reveal small details while increasing cost. Evaluate whether the added detail improves the intended task and whether preprocessing preserves the relevant evidence. A larger picture helps only if the important detail survives cropping and resizing.

Worked step 1. Compare a small object before and after resizing.

Worked step 2. Count tokens for both resolutions.

Worked step 3. Measure task accuracy and latency.

Try it yourself. Does more resolution guarantee better predictions?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. No. Distribution shift, preprocessing and model capacity can limit or reverse the benefit.

Section 07 / 07

Mastery and transfer

Bring the pieces together. First answer the checkpoint without the worked solutions. Then explain the mechanism in your own words, using one numerical example from this lesson.

Halving patch width on a divisible square image makes token count… Option 1: Twice as large. Option 2: Four times as large. Option 3: Unchanged.

Pause here and choose an answer before continuing. The checkpoint explanation follows.

Reveal worked solution

The correct choice is option 2: Four times as large. Both spatial dimensions contain twice as many patches.

Transfer task. Change one assumption in the worked example. State your prediction, calculate or test it in Workbench, then explain whether the result supports your prediction.

Reveal worked solution

Self-check rubric. Name the changed assumption, keep the other inputs fixed, show at least one intermediate calculation, and distinguish what the toy example guarantees from what would require a trained model or a real measurement.

Sources and scope

Original worked examples and teaching text, grounded in these primary references. Numerical fixtures explain mechanisms; model quality and hardware performance require separate measurements. Both levels share key examples, with different explanations and checkpoints.

Reset this high school path?

This removes only this path’s notes, progress and experiments from this browser.