Multimodal models

In one sentence

Images and audio are encoded into token-like vectors the LLM reads alongside text. They cost tokens (~85 to a few thousand per image) and fail on tiny text, counting and precise spatial reasoning.

The image becomes a sequence of vectors in the LLM's own embedding space; from there it is just a longer prompt.

How it works

  • A vision encoder (usually a ViT) cuts the image into patches and turns each into a vector.
  • A small projector maps those vectors into the LLM's embedding space, so image and text form one sequence.
  • Providers downscale large images first, so fine print can vanish; crop key regions at full resolution.
  • Audio cascades (ASR → LLM → TTS) are debuggable and leave a transcript, but add latency and drop tone.
  • Native speech-to-speech hears prosody and replies in ~0.3 s, but is harder to control and audit.

Check yourself

Answer to mark it learned; your answers aren't scored.

You extract data from photographed receipts with a vision model. Totals come out right, but line items on faded thermal paper are misread or invented. Best fix?

Go deeper

Full explanation

A multimodal model accepts more than text (images, audio, video, PDFs) and sometimes produces more than text. The common recipe turns each modality into tokens the LLM can already read.

Vision, step by step

  1. A vision encoder (usually a ViT, often CLIP-pretrained) cuts the image into patches, e.g. 14×14 px, and turns each into a vector.
  2. A small projector (linear layer or MLP) maps those vectors into the LLM's embedding space.
  3. The LLM attends over image and text tokens as one sequence. LLaVA-1.5 turns a 336×336 image into 576 tokens.

So images cost tokens: from ~85 to a few thousand per image depending on provider, size and detail setting. Providers downscale large images first, so fine print can vanish.

Audio comes in two architectures. A cascade (ASR such as Whisper → text LLM → TTS) is debuggable, swappable and leaves a transcript, but adds latency and drops tone. Native speech-to-speech (GPT-4o realtime, Gemini Live) hears prosody and replies in ~0.3 s, but is harder to control and audit.

Strong at: documents, charts, tables, UI screenshots, photos → JSON. Weak at: tiny text, counting objects, precise spatial relations and measurements, and it fails confidently.

Code Image to JSON, with a token estimate
pythonImage to JSON, with a token estimate
import base64, math
import anthropic
from PIL import Image

client = anthropic.Anthropic()
MODEL = "claude-sonnet-4-6"  # any vision-capable model
MAX_IMAGE_TOKENS = 1568  # standard tier; 4,784 on Claude 4.7+ (high-res)

def image_tokens(path: str) -> int:
    # Anthropic docs: one visual token per 28x28 px patch; bigger images are downscaled
    w, h = Image.open(path).size
    return min(math.ceil(w / 28) * math.ceil(h / 28), MAX_IMAGE_TOKENS)

def extract_receipt(path: str) -> str:
    data = base64.standard_b64encode(open(path, "rb").read()).decode()
    msg = client.messages.create(
        model=MODEL,
        max_tokens=512,
        messages=[{"role": "user", "content": [
            # Image first, then the instruction: the recommended order for vision
            {"type": "image", "source": {"type": "base64",
                                         "media_type": "image/png", "data": data}},
            {"type": "text", "text": "Return JSON {vendor, date, total, currency}. "
                                     "Use null for anything you cannot read clearly."},
        ]}],
    )
    return msg.content[0].text

print(image_tokens("receipt.png"), "approx. input tokens for the image")
print(extract_receipt("receipt.png"))
Real example

A finance team extracts totals from 10,000 photographed receipts. Each ~1000×1000 px photo costs ~1,300 image tokens on Claude (one per 28×28 px patch): ~13M input tokens, ~$40 at an assumed $3 per million (Claude docs, Nov 2026). Totals come out well, but faded thermal-paper line items get misread or invented. Downscaling to save tokens makes it worse; sending a second, cropped image of the line-item region at full resolution fixes most misses. Anything that fails a sum check (items ≠ total) goes to a human.

Trade-offs +3 · −3

+ You gain

  • One model reads scans, screenshots, charts and photos, replacing brittle OCR + layout pipelines for many documents.
  • Images keep layout, tables and visual cues that plain text extraction loses.
  • Native audio keeps tone and emotion and brings voice replies to the ~300 ms range.

− You pay

  • Token-hungry: a 20-page PDF sent as images can cost ~20–30k input tokens.
  • Weak at tiny text, counting, spatial relations and exact measurements, with confident errors.
  • Harder to evaluate: you need labeled image or audio test sets, not just text.

Use it when

Documents where layout matters (forms, invoices, tables), charts, UI screenshots, photo-driven workflows, and voice products where latency and tone matter.

Avoid it when

When clean text exists (digital PDFs, HTML), extract it: cheaper and more precise. For exact counts, measurements or pixel positions, use classic OCR or computer vision.

Numbers to know 5
  • LLaVA-1.5: one 336×336 image → 576 visual tokens (24×24 patches of 14 px).
  • Claude (2026 docs): 1 token per 28×28 px patch; max 1,568 per image, 4,784 on Claude 4.7+.
  • GPT-4o: 85 tokens at low detail; a 1024×1024 image at high detail ≈ 765 tokens.
  • Gemini 2.x: 258 tokens for an image ≤384 px per side (larger ones are tiled); audio ≈ 32 tokens/s.
  • GPT-4o voice: ~320 ms average reply vs 2.8–5.4 s for the earlier ASR→LLM→TTS Voice Mode.
Common pitfalls 4
  • Sending page images when a text layer exists: you pay image tokens for less precision.
  • Ignoring server-side downscaling: fine print becomes unreadable. Crop or tile the region you need.
  • Trusting counts and spatial claims ("third row, left column") without a deterministic check.
  • Going speech-to-speech with no plan for transcripts, guardrails and audit logs.
Interview questions 2

Answer out loud first, then reveal.

How does an LLM "see" an image?Show answer

It never sees pixels directly. A vision encoder, typically a ViT, splits the image into fixed-size patches and embeds each one; a projector maps those embeddings into the same space as the LLM's word embeddings; then the LLM attends over image and text tokens as one sequence. The practical consequences: each image costs hundreds to a few thousand tokens, resolution is capped so small text can disappear, and counting or geometry is weak because patches are coarse.

Designing a voice agent: cascade or native speech-to-speech?Show answer

I'd default to a cascade: streaming ASR, a text LLM, streaming TTS. Every hop is swappable, I get transcripts for guardrails, evals and audits, and I can use the strongest text model with tools. With streaming at each stage I can get turns to roughly a second. I'd pick native speech-to-speech when tone, interruptions and ~300 ms responsiveness are the product, like coaching, and accept less control and harder debugging. Either way, I still log a transcript.