AI Run Lab

All chapters

Extending the sequence beyond text

Images, audio and text begin as different types of data. Several model families turn parts of each input into vectors that can be processed together.

Open this chapter with experiments and audio

How can a picture become a sequence?

A digital RGB image has three numbers at each pixel. Divide a 224 × 224 image into squares of 16 × 16 pixels. Fourteen patches fit along each side, giving 196 patches. Each patch initially contains 16 × 16 × 3 = 768 color values. A learned projection turns those values into a vector of the width used by the model. Position information tells the network where the patch came from.

The shape provides useful checks. If the model uses a width of 384, the sequence of patch vectors has shape 196 × 384 before any extra special token. The patch count is determined by resolution and patch size. The projection weights are reused for every patch. Increasing the resolution can therefore increase the sequence length without creating a new projection for every location.

for resolution in (224, 448):
    patch, channels, width = 16, 3, 384
    count = (resolution // patch) ** 2
    print(resolution, "pixels per side:", count, "patches")
    print("Components per patch:", patch * patch * channels)
    print("Projected sequence:", (count, width))

How can a language model answer an image question?

One design uses a vision encoder to compute visual features, then a projection or adapter to put these features into a form a language model can use. The model combines image information with the question and generates text. Other designs use cross-attention to attend to image features separately. Training on related images and text helps connect a visual pattern with the words used to describe it.

For a question such as “How many chairs are visible?”, identifying chair-like patches is only part of the task. The system must group patches belonging to one object, distinguish separate objects and produce the correct count. A fluent sentence alone cannot establish that localization or counting succeeded. Evaluate the answer on images with known counts, repeated patterns and partly hidden chairs.

Image patches

Project groups of pixel values into vectors.

Visual features and question

An adapter or attention links the modalities.

Generated text

The decoder produces answer tokens.

Generating an image step by step

A diffusion training procedure adds noise according to a predefined process and trains a network to estimate a quantity that helps reverse it. One common objective predicts the added noise. During sampling, start from noise and apply a trained denoising update repeatedly. Many practical systems perform this work in a compact latent representation and decode the final result to pixels.

A text prompt can condition the denoising network through text embeddings. Changing the prompt changes the information available at each update. Changing the random seed changes the initial noise, so the same prompt can produce different scenes. More sampling steps can increase work even when the count of learned parameters stays constant.

Compare what changes during inference

An autoregressive decoder grows a sequence token by token. A diffusion sampler refines a noisy representation over several updates. A state-space sequence model carries a learned update of an internal state across positions. Some reasoning systems spend additional inference computation generating candidate answers or checking them. These choices change how work is organized at prediction time.

Return to the room question from the beginning. Is the input a text description, a floor-plan image or a reading from a measuring instrument? Which component extracts the two lengths? Where is the area computed? Which part checks the units? Being able to trace those steps explains more about a real system than naming its model family alone.

What happens to the number of fixed-size patches if both image dimensions double?

It grows by a factor of four. In the example the sequence increases from 196 to 784 patches.

Dosovitskiy et al. · Vision Transformer

Ho et al. · Denoising Diffusion Probabilistic Models

Can the model read a digit that disappeared during resizing?

A technician photographs a pump label and asks for the rated pressure. In an illustrative vision pipeline, a 224 × 224 image is divided into 16 × 16 pixel patches. This yields 14 × 14 = 196 patches before any extra tokens. At 448 × 448 the same patch size gives 784. If all those positions enter a full attention layer together, the patch-to-patch score matrix has sixteen times as many entries. Actual systems can compress, pool or tile images and therefore have different costs.

A vision encoder turns patches into features. In an architecture such as LLaVA a learned projection connects visual features to the language model. If preprocessing collapses “8” and “3” to the same pixels, the later layers receive the same evidence for both. They can still generate a plausible number using context. Crop the label from the original image before resizing, hold the text prompt fixed and compare whether the cited reading changes. Include an unreadable crop as a test of whether the assistant expresses uncertainty.

Compare patch counts across image resolutions →

Sources · Dosovitskiy et al., 2020 · Liu et al., 2023