When you upload a screenshot to ChatGPT and it reads the text, identifies the UI elements, and tells you the bug β what's actually happening?
It's not OCR. It's not a separate image analysis pipeline. The model is literally seeing your image as tokens β the same way it sees text. Your screenshot gets chopped into patches, converted into embeddings, and fed into the same transformer that handles language.
Text, images, audio β to a multi-modal model, they're all just sequences of vectors. The unification is beautiful. And understanding it changes how you use these tools.
What "Multi-modal" Actually Means
A modal is a type of input or output. Text is one modality. Images are another. Audio, video, 3D β each is a modality.
Modality Examples How AI Processes It
| Text | Chat, code, documents | Tokenizer β embeddings |
|---|---|---|
| Image | Photos, screenshots, diagrams | Patch encoder β embeddings |
| Audio | Speech, music, sound effects | Spectrogram β embeddings |
| Video | Clips, streams | Frame sampling β image embeddings |
A multi-modal model handles two or more of these in a single architecture. GPT-4V handles text + images. Gemini handles text + images + audio + video. The key insight: they all get converted to the same representation β embedding vectors β before the transformer sees them.
How Images Become Tokens
This is the core trick. A transformer only understands sequences of vectors. So how do you feed it an image?
Step 1: Patch Extraction
The image gets divided into a grid of square patches. Think of it like cutting a photo into tiles:
Original image: 1024 Γ 1024 pixels
Patch size: 16 Γ 16 pixels
Grid: 64 Γ 64 = 4,096 patches
Each patch = one "image token"
A single 1024Γ1024 image becomes 4,096 tokens. That's why image inputs are expensive β they eat a huge chunk of your context window.
Step 2: Patch Embedding
Each 16Γ16 pixel patch (which is 16 Γ 16 Γ 3 = 768 raw values for RGB) gets projected into the model's embedding dimension through a linear layer or small CNN:python
Simplified patch embedding
patch = image[y:y+16, x:x+16] # 16Γ16Γ3 = 768 values
patch_flat = patch.flatten() # [768]
embedding = linear(patch_flat) # [768] β [d_model]Now it's the same shape as a text token embedding!
Step 3: Position Encoding
Just like text tokens need position information, image patches need to know where they are in the grid. 2D position embeddings encode both row and column:
Patch (0,0) β position embedding for top-left
Patch (0,1) β position embedding for top-center...
Patch (63,63) β position embedding for bottom-rightStep 4: Into the Transformer
Now you have a sequence of 4,096 vectors, each the same dimension as text token embeddings. The transformer processes them with standard self-attention β each patch attends to every other patch, learning spatial relationships.
The final output? A set of rich image representations that understand edges, objects, text, layout β everything.
π§
CLIP: The Bridge Between Text and Images
CLIP (Contrastive Language-Image Pre-training) by OpenAI (2021) was the breakthrough that made modern multi-modal AI possible.The Training Trick
CLIP trains two encoders simultaneously:
Image encoder β turns images into embedding vectors
Text encoder β turns text descriptions into embedding vectors
The training objective: make matching image-text pairs have similar embeddings and non-matching pairs have different embeddings.
Training pair 1: [Photo of dog on beach] β "a dog playing on a sandy beach"
Training pair 2: [Photo of city skyline] β "urban skyline at sunset"
Goal: embed(dog_photo) β embed("dog on beach")
embed(dog_photo) β embed("city skyline")This was trained on 400 million image-text pairs scraped from the internet. The result: a model that understands the relationship between visual concepts and language.
Why CLIP Matters
CLIP creates a shared embedding space where text and images coexist. You can:
Search images with text β embed your query, find nearest image embeddings
Classify images zero-shot β embed class names as text, see which is closest
Build multi-modal models β use CLIP's image encoder as the "eyes" for an LLM
python
Zero-shot classification with CLIP
import clip
image = load_image("mystery_photo.jpg")
labels = ["a cat", "a dog", "a car", "a building"]
image_features = clip.encode_image(image)
text_features = clip.encode_text(labels)Find closest match
similarities = image_features @ text_features.T
best_match = labels[similarities.argmax()]β "a cat"
π
How GPT-4V Sees: The Full Pipeline
GPT-4V (and similar models like Claude's vision, Gemini) combine a vision encoder with the language model. Here's the full pipeline:
Architecture
Image β Vision Encoder (CLIP/ViT) β Projection Layer β LLM
Text β Tokenizer β Embedding Layer βββββββββββββββββ LLM
β
Output TokensStep by step:
Image enters the vision encoder β Usually a ViT (Vision Transformer) pre-trained with CLIP. This converts the image into a sequence of rich feature vectors.
Projection layer β The vision encoder's output dimension might not match the LLM's embedding dimension. A projection layer (linear or MLP) maps vision features into the LLM's space.
Interleaving β The projected image tokens get inserted into the sequence alongside text tokens:
Sequence: [
"What", "is", "shown", "in", "this", "image", "?"]The LLM processes everything together β Self-attention operates over both image and text tokens. The model can attend from text tokens to image tokens and vice versa. This is how it "understands" the image in context.
Output is text β The model generates text tokens autoregressively, same as always. But now its predictions are informed by both the text prompt and the image content.
Token Counts
This is why vision queries are expensive:
| Image Resolution | Patches (approx) | Token Equivalent | Context Used |
|---|---|---|---|
| 512 Γ 512 | 1,024 | ~1,000 tokens | Medium |
| 1024 Γ 1024 | 4,096 | ~4,000 tokens | Large |
| High-detail mode | Multiple crops | ~8,000 tokens | Very large |
GPT-4V's "high detail" mode actually processes the image at multiple resolutions β a low-res overview plus high-res crops of different regions β to capture both global context and fine details. This can use thousands of tokens for a single image.
Vision Transformers (ViT): The Eyes
The Vision Transformer (ViT) is the standard architecture for image encoding in multi-modal systems.
ViT vs CNN
Traditional computer vision used CNNs (Convolutional Neural Networks) β specialized architectures with convolutional filters that slide across images. ViT proved that a standard transformer, with minimal modifications, can match or beat CNNs:
Feature CNN (ResNet) ViT
| Core operation | Convolution (local patterns) | Self-attention (global patterns) |
|---|---|---|
| Locality | Built-in (filter size) | Learned (attention patterns) |
| Scale | Diminishing returns | Scales with data + compute |
| Multi-modal fusion | Requires adapter | Native (same architecture as LLM) |
The key advantage of ViT for multi-modal: since it's a transformer, its outputs are naturally compatible with LLM inputs. No awkward conversion needed.
SigLIP β The Evolution
SigLIP (Sigmoid Loss for Language-Image Pre-training) improves on CLIP by using sigmoid loss instead of softmax contrastive loss. This removes the need for large batch sizes during training and produces better image representations. Many modern multi-modal models (Gemini, PaLI) use SigLIP-based vision encoders.Multi-modal Generation: Creating Images
So far we've talked about understanding images (vision β text). What about generating them (text β vision)?
This is where models like DALL-E, Stable Diffusion, and Midjourney come in. They take a different approach:
Approach 1: Diffusion (Separate Model)
Most current systems use a separate diffusion model for image generation (covered in Episode 60). The LLM generates a text description, which is fed to the diffusion model.
Approach 2: Native Multi-modal Generation
Some newer models generate images natively within the same architecture using discrete visual tokens:
Text tokens β LLM β Visual tokens β Image decoder β Image
"A sunset over [V_001][V_445] Image decoder Rendered
Mumbai skyline" [V_887][V_023] (trained to map sunset
[V_156]... visual tokens photo
to pixels)Gemini and Chameleon (Meta) take this approach β they tokenize images into discrete codes using a VQ-VAE (Vector Quantized Variational Autoencoder), then the LLM predicts these visual tokens just like it predicts text tokens.
π¬
Audio: The Third Modality
Audio follows a similar pattern to images:
Speech β Tokens
Audio waveform β Convert to spectrogram (frequency vs time image)
Spectrogram β Feed through audio encoder (like Whisper's encoder)
Audio embeddings β Project into LLM's embedding space
Interleave with text β LLM processes everything together
Audio: [wave_token_1, wave_token_2, ..., wave_token_N]
Text: "Transcribe this audio:"
Combined: [text_tokens..., audio_tokens...]
Output: "The speaker said: Hello, how are you today?"
Whisper (OpenAI) is the most widely used speech encoder. It converts audio into text with remarkable accuracy across 99 languages β the "CLIP of audio."Real-time Voice Models
GPT-4o's voice mode takes this further β it processes audio tokens directly and generates audio tokens as output, without going through text as an intermediate step. This enables natural conversation with emotion, tone, and even singing.
π‘οΈ
The Universal Sequence Model
The endgame of multi-modal AI is a universal sequence model β one architecture that handles all modalities natively:
Input: [text_tokens] + [image_tokens] + [audio_tokens] + [video_tokens]
β β β β
Tokenizer ViT Encoder Audio Encoder Frame Sampler
β β β β
Embeddings Embeddings Embeddings Embeddings
β β β β
ββββββββββββ Single Transformer ββββββββββββββββ
β
Output: [text_tokens] or [image_tokens] or [audio_tokens]Gemini 2.0 is closest to this vision today. It can take text, images, audio, and video as input, and generate text, images, and audio as output β all within one model.
π¦
Practical Takeaways
Images become tokens β patches are extracted, embedded, and fed into the same transformer as text
CLIP bridges vision and language β it creates a shared embedding space for both modalities
Image inputs are token-expensive β a single high-res image can use 4,000-8,000 tokens of context
Vision Transformers replaced CNNs β standard transformer architecture works for images with minimal changes
Audio follows the same pattern β spectrograms get encoded into embeddings and interleaved with text
The future is universal models β single architectures handling all modalities natively
π
What's Next?
Episode 59: Voice & TTS β How does speech synthesis actually work? What makes Whisper so good at transcription? How do ElevenLabs and CosyVoice clone voices? We'll break down the full pipeline from text to human-sounding speech.
β Previous
Ep 57: Mixture of Experts
Next β
Ep 59: Voice & TTS
Next: Episode 59 β Voice & TTS
Close your eyes and listen to someone speak. Not the words β the way they speak. AI is learning to replicate all of that.
This is part of a 98-episode series covering AI engineering from tokens to production deployment.