Vision-Language Models: How an LLM Sees an Image
You'll learn to
- -Describe the path from an image to tokens a language model can read
- -Compute how many tokens an image costs from its size and patch size
- -Explain why high-resolution images are tiled, and what that does to cost and context
- -List where vision-language models are unreliable and how to test them
Tip: the highlighter is on - just select any text below to mark it. Use the highlighter button up top to change color or turn it off. Highlights are saved on this device only. Log in to save them to your account instead.
A language model reads tokens. An image is a grid of pixels. To let a model answer 'what is wrong with this circuit board?', something has to turn the grid into a sequence the language model can read. That something is the heart of a vision-language model, often shortened to VLM, and it explains both what these models can do and what they cost.
An Analogy: A Mosaic Read Tile by Tile
Picture a mosaic made of small square tiles. Describing it to someone over the phone, you might read out each tile's color and pattern in order. A vision-language model does something similar. The image is cut into small square patches, each patch becomes a vector, and the language model reads those vectors in sequence the way it reads words. The Vision Transformer paper, titled An Image Is Worth 16x16 Words, showed that a pure transformer working on a sequence of image patches can recognize images very well.
The Path From Pixels to an Answer
- -The image is resized and cut into fixed-size patches, for example 14 by 14 pixels.
- -A vision encoder, often one trained with the contrastive idea from the CLIP chapter, turns the patches into vectors that describe what they show.
- -A projector, in the simplest versions a small neural network, maps those vectors into the same space as the language model's word embeddings.
- -The resulting visual tokens are placed in the prompt next to the text tokens, and the language model produces its answer as usual.
LLaVA is a well-known example. Its authors connected a vision encoder to a language model and trained it on instruction-following data about images, which they generated by asking a language-only GPT-4 to write conversations from image captions. A follow-up note reports that using a CLIP encoder at 336 pixels with a simple MLP projection gave strong results across eleven benchmarks. This is the synthetic data idea from the adapting models module, applied to pictures.
What an Image Costs
Every patch becomes a token, so bigger images cost more and fill the context faster. The code computes the number of patch tokens for several sizes. For high-resolution inputs many systems cut the image into tiles of the encoder's native size and add one downscaled overview, which multiplies the cost. It then shows how many images fit in a 32,000 token window with 1,000 tokens kept for text, and a made-up price of 3 dollars per million input tokens.
A 224 by 224 image with 16 pixel patches is 14 by 14, so 196 tokens. A 336 by 336 image with 14 pixel patches is 24 by 24, so 576 tokens. A 1024 by 768 photo, cut into 12 tiles plus an overview, is 7,488 tokens, so only 4 such photos fit in the window and 100,000 of them cost about 2,246 dollars at the made-up price. A 2048 by 1536 scan is 20,736 tokens, and just one fits. The same arithmetic applies to every provider, even though the exact tiling rules differ.
Where They Fail
- -Counting and fine detail: small objects, many objects and small text can be missed or invented.
- -Spatial reasoning: left of, above, behind and measurements are weak points.
- -Confident hallucination: the model describes things that are not in the picture.
- -Resolution mismatches: text that is readable to you can be unreadable after resizing.
Test on your own images, not on a public benchmark. Build a small labeled set of the pictures your users really send, including the blurry and awkward ones, and score the model on it, as the Evals modules describe. Also decide what happens to faces, documents and screenshots that contain personal data.
Interview Signal is part of Pro
See a real weak answer next to a real strong one for this exact topic.
Quiz is part of Pro
Test what you just read with a short quiz, and bank the XP.
Discussion0
Join the Discussion
Sign in to leave comments, reply to others, or like insights.
No comments yet. Be the first to start the thread!