Part 8

Vision: Convolutions and Tokens

Mehmet Kerem Turkcan
Associate Research Scientist
Center for Smart Streetscapes, Columbia University
New York, USA
keremturkcan.com; mkt2126@columbia.edu

Move through the deck with (i) the arrow keys, (ii) a presentation clicker, or (iii) the buttons at the bottom left. The gear at the bottom right opens the slide settings.

Part 7 Overview

  1. The agent: Part 7 put the model in a loop with tools; everything that entered the loop was text.
  2. The question: The assistant students use also answers questions about photographs. Pixels are numbers, so something must arrange them for a network.
  3. Two methods: convolution slides small filters across the image; tokens cut the image into patches that enter the same window as words.

Part 9 opens attention, which also reads image tokens.

The image as a table of numbers

A grayscale image is a table of brightness values, 0 for black through 255 for white. This illustrative scene, a drawing, is 128 by 128 pixels: 16,384 numbers.

An illustrative grayscale scene: a house with a roof, door, and window under a sun.
The amber square marks the 12 by 12 crop shown at right.

The crop sits on the roof's left edge, so its numbers fall from sky (about 180) to roof (about 60) along a diagonal. Every question about the picture is a question about this table.

183 183 183 183 183 183 183 183 182 183 182 182 182 182 182 182 182 182 182 182 182 181 183 185 181 181 181 181 181 181 181 181 180 184 179 126 180 180 180 180 180 180 180 179 184 170 107 58 180 180 180 180 180 179 179 184 158 89 56 61 179 179 179 179 178 180 182 142 75 56 61 60 178 178 178 177 180 177 124 64 57 61 60 60 178 178 177 181 168 106 58 59 61 60 60 60 176 176 181 156 88 56 61 61 60 60 60 60 177 179 140 74 56 61 60 60 60 60 60 60 174 123 64 57 61 60 60 60 60 60 60 60 105 58 59 61 60 60 60 60 60 60 60 60
The actual values of the crop, cell by cell; the diagonal edge is visible in the numbers.

The filter: a weighted sum slid everywhere

A filter is a small table of weights. At each position, it multiplies its weights with the 9 pixels beneath it and adds the products, Part 5's weighted sum; it writes one number and slides one pixel onward.

\begin{pmatrix}-1&0&1\\-2&0&2\\-1&0&1\end{pmatrix}

This filter asks one question at every position: is the right side brighter than the left? On the toy grid (illustrative values 10 and 90), it writes 4\times(90-10)=320 where the bright edge passes and 0 on the flat regions.

Because one filter of 9 weights is reused at every position, convolution stays cheap, and a pattern learned in one corner is recognized anywhere.

10 10 10 10 90 90 90 90 10 10 10 10 90 90 90 90 10 10 10 10 90 90 90 90 10 10 10 10 90 90 90 90 10 10 10 10 90 90 90 90 10 10 10 10 90 90 90 90 10 10 10 10 90 90 90 90 10 10 10 10 90 90 90 90 input, 8 by 8 output, 6 by 6 0 0 320 320 0 0 0 0 320 320 0 0 0 0 320 320 0 0 0 0 320 320 0 0 0 0 320 320 0 0 0 0 320 320 0 0
Step the fragment to watch the window slide; the two output columns of 320 trace the edge.

What filters find

The same arithmetic on the house image, with three classic filters:

The original house scene.
original
Vertical edge filter output: the house's vertical outlines glow.
vertical edges
Horizontal edge filter output: rooflines and the horizon glow.
horizontal edges
Blur filter output: a softened copy of the scene.
blur (average of 9)

A convolutional layer runs many filters at once, and training chooses their weights: Part 4's loss discovers the edge detector from the data, because edge features lower the loss on later tasks.

Layer upon layer

Stacking the operation lets each layer detect larger patterns. The first layer reads pixels and finds edges; the next layer reads the first layer's outputs, so its filters see combinations of edges: corners and textures; deeper layers see parts, then whole objects. Zeiler and Fergus (2014) made the ladder visible by tracing each layer's strongest responses back to the pixels.

Between layers, pooling shrinks the map by keeping each small region's largest response: a 2 by 2 pooling over (320,\,0,\,320,\,0) keeps 320. Pooling discards the exact position, so the network gains tolerance to small shifts while the map shrinks to a quarter of its values.

The activation function from Part 5 sits after every layer, because stacked linear filters would collapse into one filter, the same collapse Part 5 proved on matrices.

For the classroom: students verify the pooling: which number survives from (12, 7, 40, 3)? Why can the network afford to lose the other three?

From cat cortex to checks

David Hubel and Torsten Wiesel recorded from single neurons in a cat's visual cortex (1959) and found cells tuned to oriented edges at specific positions; their 1962 paper sorted them into simple and complex cells, a hierarchy from edges toward tolerance of position. They shared in the 1981 Nobel Prize in Physiology or Medicine (one half went to Roger Sperry, one quarter to each of them).

Kunihiko Fukushima built the hierarchy into a machine, the neocognitron (1980), alternating detecting layers and tolerance layers. Yann LeCun and colleagues added Part 4's backpropagation: their 1989 network read handwritten ZIP code digits, and LeNet-5 (LeCun, Bottou, Bengio, and Haffner, 1998) read, in the paper's words, "several million checks per day" in NCR's deployed systems.

The training set from that work, MNIST, holds 60,000 handwritten digits at 28 by 28 pixels each and remains the field's first classroom exercise. The 28 by 28 size returns in 2026, in the token counting of a frontier assistant.

AlexNet and the readout

AlexNet (Krizhevsky, Sutskever, and Hinton, 2012), which Part 6 showed training on two GTX 580s, stacked five convolutional layers and three fully connected layers: 60 million weights. The final layers are Part 3's classifier, a weighted sum and softmax over 1,000 object names, so every part of the machine is arithmetic from Parts 3 and 5.

  1. Convolutional layers find edges, textures, and parts, with pooling between them.
  2. The feature map flattens into one long vector, Part 5's list.
  3. Fully connected layers and a softmax map the vector to 1,000 probabilities, exactly Part 3's classifier built from Part 5's matrices.

Training follows Part 6 step for step: cross entropy on labeled images, a backward sweep, a weight update, all on GPUs.

History: AlexNet cut the previous ImageNet error by nearly half in one year, and convolutional networks led computer vision for the following decade.

Tokens: an image cut into patches

16 patches (illustrative; ViT cuts 16 by 16 pixels each) patch 1 patch 16 each patch flattens to a vector, is multiplied by the embedding matrix, receives a position embedding, and enters the window as one token
Advance the fragment: copies of the patches leave the image and land as a token row.

The Vision Transformer (Dosovitskiy et al., ICLR 2021) is titled after exactly this move: "An Image is Worth 16x16 Words." A 224 by 224 image cut into 16 by 16 patches gives 14\times14=196 tokens, a short paragraph's worth of picture.

The patch arithmetic

Everything in the pipeline is Part 5. A tiny worked case, a 2 by 2 patch with illustrative values:

\begin{pmatrix}10&90\\10&90\end{pmatrix}\ \to\ (10,\,90,\,10,\,90)\ \to\ E\,(10,\,90,\,10,\,90)^{\mathsf T}

The patch flattens into a list of 4 numbers, and the embedding matrix E, learned like every other weight, multiplies the list and produces a vector of the model's embedding width. With the illustrative E=\begin{pmatrix}1&0&0&1\\0&0.1&0.1&0\end{pmatrix} the patch becomes the vector (100,\,10): table times list, exactly as Part 5 taught.

A position embedding is added so the model knows which patch sat where, exactly as word tokens carry positions. From this point on, the transformer sees no difference between a patch token and a word token.

A picture enters the model as 196 vectors, and the machinery that reads them is the gray box Part 9 opens.

What the Vision Transformer traded

Convolution carries built in assumptions: nearby pixels matter together, and a pattern means the same thing anywhere. The Vision Transformer discards both and lets attention learn where to look, so it must relearn locality from data.

The paper measured the cost in training data and the gain in accuracy. Trained on ImageNet alone, the transformer trails comparable convolutional networks, because transformers "do not generalize well when trained on insufficient amounts of data"; pretrained on 14 million to 300 million images, it matches or beats them, and the authors conclude that "large scale training trumps inductive bias."

convolutionpatch tokens
localitywired inlearned
same pattern anywherewired inlearned
training data neededlessmore
readerthe filter stackattention (Part 9)

Vision inside the assistant

When students photograph their homework, the assistant reads the image as patch tokens. CLIP (Radford et al., announced January 5, 2021) trained a vision encoder by predicting which caption goes with which image across 400 million pairs; LLaVA (Liu et al., 2023) projected such patch features straight into a language model's embedding space, so image patches arrive as tokens among the words. The frontier assistants followed: GPT-4 announced image input on March 14, 2023, Gemini launched as natively multimodal on December 6, 2023, and Claude 3 shipped vision on March 4, 2024.

Part 7's context applies to pictures directly, because a picture is context. Anthropic's current documentation counts one visual token per 28 by 28 pixel patch, up to 1,568 tokens per image at the standard tier and 4,784 at the high resolution tier (2026); MNIST's whole digit, 28 by 28, is exactly one such patch.

OpenAI's documentation counts 32 by 32 pixel patches for its smaller models and 512 by 512 tiles for the larger ones; the patch sizes differ, while the billing idea is the same: pictures are counted in patches.

Drawing with next token prediction

If a picture can enter the model as tokens, the model can also emit a picture, token by token. Image GPT (Chen et al., ICML 2020) trained a transformer "to auto-regressively predict pixels, without incorporating knowledge of the 2D input structure." DALL-E (Ramesh et al., announced January 5, 2021) compressed each 256 by 256 image into a 32 by 32 grid of discrete codes, 1,024 image tokens from a learned codebook, and trained one autoregressive model over the text tokens followed by the image tokens.

The cost is the sequence length: 1,024 tokens for one small image, each conditioned on all the previous ones. Part 10 reaches image generation differently: diffusion shapes the whole canvas at once out of noise.

caption: a house under a sun (illustrative) 16 image tokens, emitted in reading order
One more fragment plays the generation: a 4 by 4 toy version of DALL-E's 32 by 32 grid.

History: DALL-E's codebook does the compressing that convolutional layers once did, so that an autoregressive transformer can fit a whole picture inside its sequence.

Check for understanding

Exercise 1. The vertical edge filter from the animation meets a column where the values jump from 20 to 100. What does it write there? What does it write on the flat regions?

It writes 4\times(100-20)=320 on the edge and 0 on the flat regions, because the weighted sum cancels wherever left and right match.

Exercise 2. A 224 by 224 image is cut into 16 by 16 patches. How many tokens enter the window? How does that compare with a paragraph of text?

(224/16)^2=196 tokens, about the length of a long paragraph; a picture takes roughly as much of the context window as its own caption would.

Part 8 Overview

  1. Images are numbers: a grayscale picture is a table of brightness values, and every method reads that table.
  2. Convolution: a small weighted sum slides everywhere, training discovers edge and texture filters, pooling buys shift tolerance, and stacked layers climb from edges to objects (Hubel and Wiesel to LeNet to AlexNet).
  3. Tokens: the Vision Transformer flattens 16 by 16 patches through an embedding matrix into the same window as words; 196 tokens per image, read by attention.
  4. The trade: convolution wires locality in and needs less data; patch tokens learn where to look and win at scale.
  5. In the assistant: images are billed as patch tokens in the context, and next token prediction can also draw, one image token at a time.

Next: Part 9 opens the gray box, attention, which reads word tokens and patch tokens alike.

Sources: convolution

  • D. Hubel, T. Wiesel, 1959, “Receptive fields of single neurones in the cat's striate cortex,” Journal of Physiology 148; 1962, “Receptive fields, binocular interaction and functional architecture in the cat's visual cortex,” Journal of Physiology 160; Nobel Prize in Physiology or Medicine 1981, one half to R. Sperry, one quarter each to Hubel and Wiesel.
  • K. Fukushima, 1980, “Neocognitron: A Self-organizing Neural Network Model for a Mechanism of Pattern Recognition Unaffected by Shift in Position,” Biological Cybernetics 36.
  • Y. LeCun et al., 1989, “Backpropagation Applied to Handwritten Zip Code Recognition,” Neural Computation 1(4). Y. LeCun, L. Bottou, Y. Bengio, P. Haffner, 1998, “Gradient-Based Learning Applied to Document Recognition,” Proceedings of the IEEE 86(11); LeNet-5; “several million checks per day” in NCR systems.
  • MNIST: Y. LeCun, C. Cortes, C. Burges; 60,000 training digits, 28 by 28 pixels.
  • A. Krizhevsky, I. Sutskever, G. Hinton, 2012, “ImageNet Classification with Deep Convolutional Neural Networks,” NeurIPS; 60 million parameters, five convolutional and three fully connected layers.
  • M. Zeiler, R. Fergus, 2014, “Visualizing and Understanding Convolutional Networks,” ECCV; edges, then textures, then parts, then objects, layer by layer.

Sources: tokens and the assistant

  • A. Dosovitskiy et al., 2021, “An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale,” ICLR; “large scale training trumps inductive bias.”
  • M. Chen et al., 2020, “Generative Pretraining From Pixels,” ICML (Image GPT). A. Ramesh et al., 2021, “Zero-Shot Text-to-Image Generation” (DALL-E, announced January 5, 2021); a 32 by 32 grid of discrete image tokens.
  • A. Radford et al., 2021, “Learning Transferable Visual Models From Natural Language Supervision” (CLIP); 400 million image and caption pairs. H. Liu et al., 2023, “Visual Instruction Tuning” (LLaVA), NeurIPS.
  • OpenAI, March 14, 2023, GPT-4 with image input. Google, December 6, 2023, Gemini, “natively multimodal.” Anthropic, March 4, 2024, Claude 3 with vision.
  • Anthropic vision documentation (platform.claude.com, read July 2026): one visual token per 28 by 28 pixel patch; 1,568 and 4,784 token tiers. OpenAI vision documentation (read July 2026): 32 by 32 pixel patches for smaller models; 512 by 512 tiles with base and per tile counts for larger ones.
  • The house scene, its filter outputs, and every grid on these slides were generated for the deck (illustrative) with the kernels shown.
  • Owner: Mehmet Kerem Turkcan; Associate Research Scientist; Center for Smart Streetscapes, Columbia University; New York, USA; keremturkcan.com; mkt2126@columbia.edu.
Intro to AI, Part 8: VisionM. K. Turkcan, Columbia University