From pixels to tokens
To a computer, a picture is a grid of pixels, and each pixel is three numbers from 0 to 255: how much red, green and blue. A 12-megapixel phone photo is 4032 × 3024 pixels, which is more than 36 million numbers. A language model reads tokens, and each token is one embedding vector (the embeddings lesson). So the first job is to turn that huge grid into a short row of vectors.
For years, vision meant convolutional networks, which slide small filters across the picture (the before-transformers lesson). In 2020 a Google team showed that a plain transformer does the job just as well, if you first cut the picture into squares. Their paper was called “An image is worth 16×16 words”, and the model is the Vision Transformer, or ViT.
- Resize the picture to the size the model expects, for example 224 × 224 pixels.
- Cut it into patches of 16 × 16 pixels: 14 across and 14 down.
- Line up the numbers of each patch (16 × 16 pixels × 3 colours = 768 numbers) and multiply them by a learned matrix, which gives one vector per patch (the matrices lesson).
- Add a position embedding to each vector, so the model knows where in the picture the patch came from.
- Run the vectors through transformer layers. Attention lets every patch look at every other patch, so a patch of grey fur can learn that it belongs to a cat.
224 ÷ 16 = 14patches across, and 14 down
14 × 14 = 196patches: the picture becomes 196 tokens
16 × 16 × 3 = 768numbers in one patch, before it becomes a vector
Quick check
Teaching pictures and words one language: CLIP
A ViT trained to sort photos into 1,000 fixed groups knows “dog” and “cat” only as labels. To talk about pictures, a model needs pictures and words in the same space. In 2021 OpenAI’s CLIP did this by training two encoders side by side, one for pictures and one for text, on 400 million pictures with the captions people had written for them on the web.
The training is contrastive. In each step the model sees a large batch of picture–caption pairs. Each picture’s vector is pulled towards the vector of its own caption and pushed away from every other caption in the batch. Closeness is the dot product of the two vectors, after both are scaled to length 1 (the vectors lesson).
N pairs → N × N similaritiesN right pairs, and N² − N wrong ones to push apart
N = 32,768the batch size CLIP used
32,768² ≈ 1.07 billionsimilarities in a single step
After training, a photo of a mango and the sentence “a photo of a mango” land close together. That gives zero-shot recognition: to sort photos, write one sentence per group and pick the sentence whose vector is closest to the photo’s. With no training on the ImageNet photos at all, CLIP sorted them as well as a classic network trained on all 1.28 million of them.
Quick check
Giving a language model eyes
There are two main ways to join a vision encoder to a language model.
The adapter way. Take a trained vision encoder, often CLIP or SigLIP, and a trained language model, and train a small projector between them that turns picture vectors into vectors the language model can read. LLaVA (2023, from the University of Wisconsin–Madison, Microsoft Research and Columbia University) made this famous. LLaVA-1.5 used CLIP at 336 × 336 pixels, which gives 576 picture tokens, and a projector of just two layers. It was trained in two stages: first only the projector, on 558,000 pictures with captions; then the projector and the language model together, on 665,000 conversations about pictures. The whole training took about one day on a single machine with 8 graphics cards.
- Pictureresized, cut into patches
- Vision encoderone vector per patch
- Projectorturns them into the language model’s vectors
- Language modelreads picture tokens, then your question
- Answerordinary text tokens
To the language model, the picture is just a run of extra tokens in its context, between markers such as <|vision_start|> and <|vision_end|>, followed by your words. Attention treats picture tokens and word tokens the same way. That is why everything from the inference lessons still applies: picture tokens fill the KV cache and take time to read like any others.
The native way. Train on text and pictures together from the start of pretraining, so that seeing is not an add-on. Alibaba’s Qwen3.5 (February 2026) describes itself as natively multimodal through early fusion of text and vision, and Qwen3.8 takes pictures and video in the same single checkpoint. DeepSeek added pictures to its V4 line in 2026: first as an experiment, V4-Flash-Vision-Exp, a vision encoder and an “aligner” joined to the language model and trained further (open weights under the MIT licence on 1 September), then in V4.1-Flash. DeepSeek says the eyes are meant above all for agents that read screens, web pages and charts.
| Design | Example | Strength | Weakness |
|---|---|---|---|
| One fixed square | LLaVA-1.5 (2023) | Simple and cheap to train | Always 576 tokens; the edges are cut off; small print is lost |
| Tiles of fixed size | InternVL3 (2025) | More detail in big pictures | Up to 13 × 256 = 3,328 tokens; tiles follow the shape, not the detail |
| The picture’s own size | Qwen2.5-VL to Qwen3.8 | Keeps the shape and the detail | A big photo costs many tokens, up to 16,384 |
| Squeezed for documents | DeepSeek-OCR (2025) | A whole page in a few hundred tokens | Built for reading text, not for chat about photos |
Quick check
How many tokens is a picture?
To you a picture is one thing. To the model it is a run of tokens, and every token costs memory in the KV cache (the KV-cache lesson), time to read before the first word comes out (the press-enter lesson) and, with a provider, money (the APIs lesson). Models differ hugely in how many tokens they make.
Qwen’s rule is a good one to know. The picture keeps its shape, but both sides are rounded to multiples of 32 pixels, staying between 64 and 16,384 tokens. The encoder cuts 16 × 16 patches, then merges each block of 2 × 2 patches into one token, so each token covers 32 × 32 pixels.
4032 ÷ 32 = 126tokens across
3024 ÷ 32 = 94.5 → 94tokens down (rounded to a whole number; an exact half goes to the even one)
126 × 94 = 11,844tokens for one photo: as much room as about 8,900 English words
This interactive part needs JavaScript.
Try the small picture with InternVL3: its tiles are chosen by shape alone, so a 640 × 480 picture is blown up to twelve tiles and costs 3,328 tokens, eleven times more than Qwen spends on it. Try the A4 page with DeepSeek-OCR: the whole page costs 256 tokens. Then compare the patch sizes. A token that stands for 252 × 252 pixels of a phone photo cannot see small print.
Quick check
Reading documents, in many scripts
Reading text in pictures, called OCR (optical character recognition), is one of the most useful things vision models do: old books, exam papers, forms, signs and medicine labels. Classic OCR programs such as Tesseract find letters one at a time. A vision-language model reads more like a person, using the words around a letter to work it out.
DeepSeek-OCR (October 2025) asked a bold question. If a page shown as a picture takes fewer tokens than the same page typed out, could pictures be a way to squeeze long contexts (the context-engineering lesson)? Its encoder joins two parts: SAM (80 million parameters) for fine local detail and CLIP (300 million) for overall meaning, with a 16-times compressor between them. The decoder is a 3B mixture-of-experts model with about 570 million parameters active per token. When the page’s text had up to 10 times more tokens than the picture, it read the text back with about 97 % precision; at 20 times, about 60 %. On 20 machines it can read about 33 million pages a day, which DeepSeek uses to make training data.
| Mode | Picture | Tokens |
|---|---|---|
| Tiny | 512 × 512, resized | 64 |
| Small | 640 × 640, resized | 100 |
| Base | 1024 × 1024, padded | 256 |
| Large | 1280 × 1280, padded | 400 |
| Gundam | n tiles of 640 plus one 1024 view | n × 100 + 256 |
In January 2026, DeepSeek-OCR 2 replaced the encoder with one that reads the picture’s tokens in an order it learns, more like eyes following a page, and scored 3.73 points higher on the OmniDocBench v1.5 document test.
What about the world’s other scripts? DeepSeek-OCR’s 30 million training pages cover about 100 languages, but 25 million of them are Chinese and English. Recent studies give real numbers for three right-to-left scripts. They measure the character error rate:
CER = (S + D + I) ÷ Nwrong letters (S), missing letters (D) and extra letters (I), divided by the number of letters on the page (N)
N = 1,000, S = 60, D = 30, I = 10 → 10 %one mistake for every ten letters
more extra letters than real ones → over 100 %a program that adds rubbish can score worse than one that writes nothing
| Test | Best model tested | An open-weight model | Tesseract |
|---|---|---|---|
| Urdu book pages in Naskh style | 6.6 % (Gemini Pro, mid-2025) | 10.4 % (Llama 4 Maverick) | 95.5 % |
| Urdu book pages in Nastaliq style | 12.5 % (Gemini Pro, mid-2025) | 56.1 % (Llama 4 Maverick) | 142 % |
| Pashto printed in 1,000 fonts (PsOCR) | 10 % (Gemini Flash, early 2025) | 34 % (Qwen2.5-VL-7B) | not tested |
| Arabic documents of many kinds (KITAB-Bench) | 13 % (Gemini Flash, early 2025) | 49.2 % (Qwen2.5-VL) | 54 % |
From three studies: Arif and Farid, LREC 2026 (Urdu, OpenITI pages); the PsOCR team (Pashto, 2025, revised 2026); KITAB-Bench (Arabic, 2025). Each tested different models, mostly from 2024 and 2025, so newer models may do better. These were the latest published numbers we found in October 2026.
Three lessons stand out. First, even the best model makes about one mistake every eight to ten letters on Nastaliq or Pashto, and the same model makes about twice as many mistakes on Nastaliq as on Naskh. Second, on Nastaliq, Pashto and Arabic, the open-weight models in these tests made three to five times as many mistakes. Third, picture quality matters a great deal: in the Urdu newspaper test, sharpening blurry scans with a super-resolution model cut word errors by 25 to 71 %, and two models refused to read most of the blurry scans at all.
Quick check
What vision models get wrong
Vision models are impressive, and they are wrong in their own ways. Four kinds of mistake are worth knowing.
- Seeing what is not there. In the POPE test (2023, Renmin University of China), models were asked simple questions such as “Is there a car in the image?”. The first LLaVA answered yes to about 99 % of them, whether the object was there or not. Models most often invent objects that usually appear together with what is really there: a fork next to a plate, a car on a street. Newer models do much better, and POPE is now reported in many model papers.
- Counting and fine geometry. In “Vision language models are blind” (2024, Auburn University and the University of Alberta), four leading models were asked things a child can answer: do two circles touch, how many times do two lines cross, which letter has a circle around it. They averaged 58 %, and the best reached 78 %. When the shapes were moved apart, they scored almost 100 %. Further tests in the paper showed that the vision encoder did hold the answer; the language model failed to read it out.
- Seeing what they expect. In the same study, asked to count the rings in a logo like the Olympic one, models tended to answer 5, even when there were more. What a model knows about the world can overrule what is in front of it.
- Reading words in pictures as if you had typed them. A model reads text in a picture as easily as text in your message, so a sign, a screenshot or a document can contain sentences that try to give it orders. This is the indirect prompt injection of the tool-calling lesson, arriving through the eyes, and it matters most for agents that look at screens and web pages. The defence is the same: treat everything the model reads as information, never as instructions, and let code, not the model, decide what an agent may do.
Is each job usually safe to hand to a vision model, or one where you should check every answer?
-
Describe what is in a holiday photo
Answer: Usually fine
-
Read the dose on a medicine box
Answer: Check every answer
-
Count the people in a crowded photo
Answer: Check every answer
-
Turn a clear printed English page into text
Answer: Usually fine
-
Read a handwritten letter in Urdu
Answer: Check every answer
-
Say which of two bar charts shows growth
Answer: Usually fine
-
Say whether two thin lines on a building plan touch
Answer: Check every answer
-
Suggest a caption for a picture of a market
Answer: Usually fine
Quick check
Send a picture to a model on your computer
llama.cpp reads pictures through a second, smaller file called the multimodal projector, mmproj, which holds the vision encoder and the projector (the AI-stack lesson). With -hf, llama-server downloads it together with the model when the repository has one. The Qwen3.5-9B you used for the study helper can already see: its vision file is 0.92 GB, next to the 6.0 GB model.
# The same model as the study helper. -hf also downloads its vision file (mmproj).
llama-server -hf unsloth/Qwen3.5-9B-GGUF:UD-Q4_K_XL --jinja -c 16384 --port 8080
# In a second terminal
pip install openai
python look.py page.jpg "Copy the text exactly."
# Not using pictures? Add --no-mmproj to leave the vision file out and save about 1 GB.
# Short of graphics memory? Add --no-mmproj-offload to run the vision part on the processor.
- Ollama and LM Studio can also run vision models and offer the same OpenAI-style address (the local-AI lesson).
- A full-size phone photo can take nearly 12,000 tokens, most of the 16,384 that
-csets. Shrink photos you only need described, or start the server with a larger-c. - With little memory, look for the small sizes of Qwen or MiniCPM-V in GGUF form.
"""look.py: ask a vision model about a picture.
python look.py page.jpg "Copy the text exactly." """
import base64
import mimetypes
import os
import sys
from openai import OpenAI
client = OpenAI(base_url=os.environ.get("AGENT_BASE_URL", "http://127.0.0.1:8080/v1"),
api_key=os.environ.get("AGENT_API_KEY", "none"))
MODEL = os.environ.get("AGENT_MODEL", "local")
path, question = sys.argv[1], sys.argv[2]
kind = mimetypes.guess_type(path)[0] or "image/jpeg" # image/png, image/jpeg, ...
data = base64.b64encode(open(path, "rb").read()).decode("ascii")
reply = client.chat.completions.create(
model=MODEL,
messages=[{"role": "user", "content": [
{"type": "image_url", "image_url": {"url": f"data:{kind};base64,{data}"}},
{"type": "text", "text": question},
]}],
)
print(reply.choices[0].message.content)
print(f"\n[{reply.usage.prompt_tokens} tokens in, {reply.usage.completion_tokens} out]")
- The picture travels inside the message as text. Base64 turns every 3 bytes into 4 letters, so a 3 MB photo becomes 4 MB of text. The
data:image/jpeg;base64,part says what kind of file it is. - A message’s
contentcan be a list of parts, pictures and text in any order. Most servers that speak the OpenAI-style format accept this shape, local or online. prompt_tokensshows what the question really cost. Compare it with the demo above: servers can use their own size limits for pictures.- The same three environment variables as the study helper choose the server, so the code runs unchanged with a provider. Then the picture leaves your computer; with the local server it goes only to
127.0.0.1.
Try it with a page of a textbook. Ask it to copy the text exactly, then take the same page in poor light or at an angle and ask again. Then try a page in your own language. You will learn more about what the model can do for you from ten such tests than from any leaderboard.
- Decide what you need: a description, or every word exactly.
- Shrink pictures you only need described; keep and crop pictures you need read.
- Ask for exact copying, and ask the model to mark what it cannot read instead of guessing.
- Check readings that matter against the picture yourself, especially in non-Latin scripts.
- Never let words inside a picture decide what an agent does.
- Know where the picture goes: this computer, or which company.
Remember
- A vision transformer cuts a picture into patches, turns each patch into a vector and lets attention connect them. 224 × 224 pixels in 16 × 16 patches makes 196 tokens.
- CLIP-style contrastive training puts pictures and captions in one space, which lets a model match pictures and words with no labels. It learns the world its captions describe, which is mostly English, and such systems have worked less well on pictures from poorer homes.
- A projector can join a trained vision encoder to a trained language model (LLaVA). Newer models train text and pictures together from the start (Qwen3.5, Qwen3.8, DeepSeek’s V4 vision models).
- To the language model, a picture is a run of tokens like any other. One phone photo can be 576, 3,328 or 11,844 tokens, depending on the model.
- Shrink pictures you only need described; keep detail for reading. Smaller patches see smaller print.
- On Urdu Nastaliq and Pashto, even the best models make about one mistake every eight to ten letters, open models several times more. Check readings that matter.
- Vision models invent objects, miscount, see what they expect, and read words in pictures as if you had typed them. Treat what they read as information, never as orders.
Words to know
- Pixel
- One dot of a picture, stored as three numbers for red, green and blue.
- Patch
- A small square of a picture, such as 16 × 16 pixels, that becomes one vector in a vision transformer.
- Vision Transformer (ViT)
- A transformer that reads a picture as a row of patches. The usual vision encoder today.
- Vision encoder
- The part of a model that turns a picture into vectors.
- Projector
- A small network that turns a vision encoder’s vectors into vectors a language model can read.
- Contrastive training
- Training that pulls matching pairs, such as a picture and its caption, together and pushes the other pairs apart.
- Zero-shot
- Doing a task with no examples or training for it, such as sorting photos by comparing them with written descriptions.
- Natively multimodal
- Trained on text and pictures together from the start, instead of having vision added afterwards.
- Image token
- One of the tokens a picture becomes inside the model’s context. It takes memory and time like a word token.
- OCR
- Optical character recognition: reading the text in a picture and writing it out as text.
- Character error rate (CER)
- Wrong, missing and extra letters divided by the letters on the page. 10 % means one mistake every ten letters.
- Object hallucination
- A vision model saying that something is in a picture when it is not.
- mmproj
- The extra llama.cpp file that holds a model’s vision encoder and projector.
- Base64
- A way to write any file as plain letters and digits, so it can travel inside a text message. It makes the file about a third bigger.
Go to the source
This lesson is built on these papers and documents. Paper links open arxiv.org, a separate site.
-
An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
The Vision Transformer: patches as tokens, and a plain transformer instead of convolutions.
-
Learning Transferable Visual Models From Natural Language Supervision
CLIP: contrastive training on 400 million pictures with captions, and zero-shot recognition.
-
Sigmoid Loss for Language Image Pre-Training
SigLIP: a yes-or-no loss for each pair instead of a softmax over the batch.
-
SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features
More languages, and encoders that keep a picture’s own shape.
-
Does Object Recognition Work for Everyone?
Recognition systems were less accurate on household things from poorer homes, and why.
-
Improved Baselines with Visual Instruction Tuning
LLaVA-1.5: a two-layer projector, two training stages and about one day on one machine.
-
Qwen3-VL Technical Report
Pictures at their own size, interleaved MRoPE, DeepStack and video timestamps.
-
InternVL3.5: Advancing Open-Source Multimodal Models in Versatility, Reasoning, and Efficiency
Shanghai AI Laboratory’s tiles, pixel shuffle and a router that picks the resolution.
-
DeepSeek-OCR: Contexts Optical Compression
A page as a few hundred tokens, and how much text survives each level of compression.
-
DeepSeek-OCR 2: Visual Causal Flow
An encoder that learns the order in which to read a page.
-
Evaluating Object Hallucination in Large Vision-Language Models
POPE: yes-or-no questions that show models inventing objects.
-
Vision language models are blind: Failing to translate detailed visual features into words
Simple geometry that leading models get wrong, and why.
-
From Press to Pixels: Evolving Urdu Text Recognition
Urdu newspapers and books in Naskh and Nastaliq: classic OCR against vision-language models.
-
PsOCR: Benchmarking Large Multimodal Models for Optical Character Recognition in Low-resource Pashto Language
A million Pashto pictures in 1,000 fonts, and how eight models read them.
-
KITAB-Bench: A Comprehensive Multi-Domain Benchmark for Arabic OCR and Document Understanding
Arabic documents of many kinds, from tables to handwriting.
-
llama.cpp: multimodal
How llama-server loads a vision file and the flags that control it.
Check yourself
6 questions. Tap the answer you think is right.
0 of 6 answered
Lesson complete
Answer every question above to complete this lesson.
Your progress is saved on this device only.
Next lessonMaking pictures and video