Availit World How AI really works, in your language

Lesson 38 of 4638 minFacts checked October 21, 2026

Vision: how a model sees a picture

Show a model a photo of a medicine box, a maths problem or a street sign, and it can read it and explain it. This lesson opens the box. You will see how a picture becomes tokens, how an “eye” is joined to a language model, why one photo can cost as much room as a short book chapter, how well today’s models read scripts such as Urdu, Pashto and Arabic, and where they still fail in ways a child would not. At the end you send a picture to a model on your own computer.

In this lesson you will

  • Explain how a vision transformer cuts a picture into patches and turns each patch into a token
  • Describe how CLIP-style training puts pictures and words in one shared space, and why the training pictures matter
  • Compare the two ways of giving a language model eyes: a small adapter, or training both together from the start
  • Work out how many tokens a picture costs under different models, and when to shrink it first
  • Read real error rates for documents in Urdu, Pashto and Arabic, and know what they mean for you
  • Recognise the typical mistakes of vision models and check for them
  • Send a picture to a local model through the OpenAI-style API
On this page
  1. From pixels to tokens
  2. Teaching pictures and words one language: CLIP
  3. Giving a language model eyes
  4. How many tokens is a picture?
  5. Reading documents, in many scripts
  6. What vision models get wrong
  7. Send a picture to a model on your computer
  8. Remember
  9. Check yourself

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.

  1. Resize the picture to the size the model expects, for example 224 × 224 pixels.
  2. Cut it into patches of 16 × 16 pixels: 14 across and 14 down.
  3. 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).
  4. Add a position embedding to each vector, so the model knows where in the picture the patch came from.
  5. 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.
Counting patches
224 ÷ 16 = 14

patches across, and 14 down

14 × 14 = 196

patches: the picture becomes 196 tokens

16 × 16 × 3 = 768

numbers in one patch, before it becomes a vector

Quick check

A ViT cuts a 224 × 224 picture into 196 patches of 16 × 16 pixels. How many patches does a 448 × 448 picture give?

Show the answer

Answer: 784 448 ÷ 16 = 28 patches across and 28 down, and 28 × 28 = 784. Doubling the side doubles both directions, so the number of tokens goes up four times.

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).

One training step of CLIP
N pairs → N × N similarities

N right pairs, and N² − N wrong ones to push apart

N = 32,768

the batch size CLIP used

32,768² ≈ 1.07 billion

similarities 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

In CLIP training, what pulls a picture’s vector towards the vector of its own caption?

Show the answer

Answer: A contrastive loss: right pairs close together, wrong pairs in the same batch far apart No labels are needed beyond the captions themselves. The other captions in the batch serve as the wrong answers.

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.

A picture and a question, inside an adapter-style model
  1. Pictureresized, cut into patches
  2. Vision encoderone vector per patch
  3. Projectorturns them into the language model’s vectors
  4. Language modelreads picture tokens, then your question
  5. 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.

Four ways a picture becomes tokens
DesignExampleStrengthWeakness
One fixed squareLLaVA-1.5 (2023)Simple and cheap to trainAlways 576 tokens; the edges are cut off; small print is lost
Tiles of fixed sizeInternVL3 (2025)More detail in big picturesUp to 13 × 256 = 3,328 tokens; tiles follow the shape, not the detail
The picture’s own sizeQwen2.5-VL to Qwen3.8Keeps the shape and the detailA big photo costs many tokens, up to 16,384
Squeezed for documentsDeepSeek-OCR (2025)A whole page in a few hundred tokensBuilt for reading text, not for chat about photos

Quick check

In LLaVA-style training, what is trained in the first stage, while the rest stays frozen?

Show the answer

Answer: The projector between the encoder and the language model Stage one teaches only the small projector to translate the encoder’s vectors into the language model’s space, using simple captions. Stage two trains the language model too, on conversations about pictures.

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.

A 12-megapixel phone photo in Qwen3.5
4032 ÷ 32 = 126

tokens across

3024 ÷ 32 = 94.5 → 94

tokens down (rounded to a whole number; an exact half goes to the even one)

126 × 94 = 11,844

tokens for one photo: as much room as about 8,900 English words

Try itCut a picture into tokens

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

A model uses one token for each 32 × 32 square of pixels. About how many tokens does a 1920 × 1080 screenshot cost?

Show the answer

Answer: About 2,000 1920 ÷ 32 = 60 across and 1080 ÷ 32 ≈ 34 down, and 60 × 34 = 2,040.

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.

DeepSeek-OCR’s sizes
ModePictureTokens
Tiny512 × 512, resized64
Small640 × 640, resized100
Base1024 × 1024, padded256
Large1280 × 1280, padded400
Gundamn tiles of 640 plus one 1024 viewn × 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:

Character error rate (CER)
CER = (S + D + I) ÷ N

wrong 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

Reading Urdu, Pashto and Arabic: character error rate (lower is better)
TestBest model testedAn open-weight modelTesseract
Urdu book pages in Naskh style6.6 % (Gemini Pro, mid-2025)10.4 % (Llama 4 Maverick)95.5 %
Urdu book pages in Nastaliq style12.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

A model’s character error rate on Nastaliq pages is 12 %. Your page has 2,000 letters. About how many mistakes should you expect to fix?

Show the answer

Answer: About 240 12 % of 2,000 is 240: roughly one mistake in every eight letters, enough to change many words.

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?

0 of 8 sorted
  • 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

An agent reads web pages through screenshots. Why do the words inside those screenshots need care?

Show the answer

Answer: The model may treat sentences in the picture as instructions Text in a picture reaches the model like any other text. Treat it as information, and keep the agent’s limits in code.

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.

Start the serverbash
# 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 -c sets. 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 model about a picturepython
"""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 content can 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_tokens shows 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.

  1. Decide what you need: a description, or every word exactly.
  2. Shrink pictures you only need described; keep and crop pictures you need read.
  3. Ask for exact copying, and ask the model to mark what it cannot read instead of guessing.
  4. Check readings that matter against the picture yourself, especially in non-Latin scripts.
  5. Never let words inside a picture decide what an agent does.
  6. 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.

Check yourself

6 questions. Tap the answer you think is right.

0 of 6 answered

Why does a vision transformer cut a picture into patches instead of making one token per pixel?

Show the answer

Answer: Attention compares every token with every other, so millions of pixel tokens would cost far too much Attention’s cost grows with the square of the number of tokens. Patches of 16 × 16 cut the count 256 times.

What does zero-shot recognition with CLIP need?

Show the answer

Answer: One written description per group, compared with the photo in the shared space The photo’s vector is compared with the vectors of sentences such as “a photo of a mango”, and the closest one wins.

A model always turns a picture into 576 tokens. What happens to a big photo of a page of small print?

Show the answer

Answer: It is shrunk so far that the small print is lost With a fixed budget, each token stands for a bigger patch as the photo grows. Patches of over 100 pixels a side cannot hold small letters.

You only want to know whether a photo shows a cat. What saves the most tokens with a model like Qwen3.5?

Show the answer

Answer: Shrinking the photo before sending it Qwen spends one token per 32 × 32 pixels, so a smaller picture costs fewer tokens. A 1,024-pixel photo costs 768 tokens instead of 11,844.

The best model tested had a character error rate of about 12.5 % on Urdu Nastaliq book pages. What does that mean for a page of 1,000 letters?

Show the answer

Answer: About 125 letters to fix 12.5 % of 1,000 is 125: about one mistake every eight letters. Useful as a first draft, but a person has to check it.

A screenshot an agent reads contains a sentence that tries to give the agent orders. What is the right defence?

Show the answer

Answer: Treat words in pictures as information, never instructions, and let code limit what the agent may do No model can be trusted to ignore such text every time. The limits that matter belong in code, as in the harnesses lesson.

Lesson complete

Answer every question above to complete this lesson.

Your progress is saved on this device only.

Next lessonMaking pictures and video
Previous lesson All lessons

Choose your language