TL;DR
A vision-language model (VLM) is a neural network that takes images and text as input and works with both. Some VLMs put the two kinds of input into one shared space, so a picture and a sentence can be compared directly. Others attach an image encoder to a language model, so the model can answer questions about a picture or describe it in words.
Where you'll see it: image search that accepts a plain-English query, zero-shot image classification, and chat assistants that can read a photo, a chart or a screenshot.
Intuition
Two translators into one language
Think of two interpreters who each speak only one language: one knows pictures, the other knows text. If they agree on a shared vocabulary of meanings, a caption and the photo it describes can be matched by meaning, even though neither interpreter understands the other's format. A vision-language model builds that shared vocabulary out of numbers. An image encoder turns a picture into a vector, a text encoder turns a sentence into a vector, and training pushes matching pairs to land near each other.
There is a second way to use the same idea. Instead of matching two vectors, keep the image as a short sequence of vectors and hand that sequence to a language model, as if the picture were a long prefix of words. The language model can then talk about the picture in the same way it talks about any text. Most modern chat-style VLMs work this way.
The reason these systems exist is that images carry information that text describes badly, and text carries intent that pixels do not. A fixed list of labels such as "cat" or "dog" throws away everything except the label. A model that reads free text can handle "a cat asleep on a red chair" or "why is this chart going down?" without anyone collecting labels for those exact phrases.
flowchart LR
IMG[Image] --> VE[Vision encoder]
VE --> PROJ[Projection into shared space]
TXT[Text prompt] --> TE[Text encoder or token embeddings]
PROJ --> FUSE{Shared space or language model}
TE --> FUSE
FUSE --> OUT[Similarity score or generated text]
The math
A VLM has three parts that appear in most designs: an image encoder , a text encoder or token embedding , and a head that uses both. For an image and a text , the encoders produce vectors
where is the embedding dimension. In the shared-space design, both vectors are normalised to length one, and the score of the pair is their cosine similarity
which lies between and . Training makes the score high for matching pairs and low for mismatched ones. The standard objective for this is contrastive learning, where each image in a batch of pairs must pick out its own caption among the candidates. Written with a temperature and cross-entropy over one row of the similarity matrix, the image-to-text term for pair is
The denominator is a Softmax over the batch. A smaller makes the softmax sharper, so the model is penalised more for near-misses. The full loss averages this term with the matching text-to-image term.
In the generative design, the image is turned into vectors and placed before the text tokens . The language model then factorises the probability of the text given the image in the usual way:
Each factor is a next-token prediction, exactly as in a language model. The only new piece is the conditioning on . Training minimises the negative logarithm of this product, summed over a dataset of image-text pairs.
Zero-shot classification
Given class names, write one prompt per class, such as "a photo of a dog". Embed each prompt with . For a new image, compute for every class and turn the scores into probabilities with a softmax, using a fixed scale in place of :
Choosing the class with the largest probability is a classifier whose label set was written in words at test time. No new training is needed to add a class.
Worked examples
Use two-dimensional unit vectors so the numbers are easy to check. The image embeddings are and . The text embeddings are and . Take .
- Pair scores are dot products. .
- .
- , and .
- Divide by . The logits for row 1 are (correct) and (wrong).
- and . The sum is .
- The probability of the correct caption for image 1 is .
- The loss for that row is .
By symmetry, row 2 and both column terms also give , so the batch loss is . The loss is not zero because the correct pair scores only against a wrong score of . Training would push the diagonal up and the off-diagonal down until the correct pair dominates.
These scores are illustrative, not measured. Suppose the image has cosine similarity with the prompt "a photo of a dog" and with "a photo of a cat". Use scale .
- Scale the scores: and .
- The difference is . With two classes, the softmax reduces to a sigmoid of the difference.
- .
- The model says "dog" with about 95 percent probability, even though the two raw scores differ by only .
The large scale is what turns small cosine differences into confident probabilities. It is also why a model can look very sure about a wrong answer when two prompts are close.
- P(dog) as the logit gap varies
Take a ViT-style encoder that cuts a image into patches. That gives patch vectors. A small projection maps each one into the language model's embedding size, which gives 196 visual tokens.
- The user sends a prompt of 30 text tokens, such as "What is wrong with this wiring?"
- The language model's input becomes tokens.
- The model's attention runs over all 226 positions. The image tokens are treated like any other tokens in the context.
- Each generated answer token is predicted from the 226 inputs plus the answer tokens so far.
The cost of the image is therefore a fixed block of extra context. A larger image or finer patches add more tokens and make every later step more expensive. Many designs reduce the visual token count with a learned query module, such as the Q-Former in BLIP-2, so the language model sees fewer image tokens.
Tradeoffs and failure modes
| Situation | Problem | Better choice |
|---|---|---|
| You need fast search over millions of images | Running a generative VLM on every pair is too slow | A shared-space model, where image vectors are computed once and indexed |
| You need an answer about one image | A shared-space model returns a score, not a sentence | A generative VLM that conditions a language model on image tokens |
| Your labels are a closed, well-defined set | Zero-shot prompts may underperform a trained classifier | A supervised classifier, or a few-shot fine-tune of a VLM |
| Fine detail matters, such as small text or counts | Patch grids can blur small objects, and the encoder may drop details | Higher input resolution, or more visual tokens |
| Prompt wording changes the answer | Zero-shot scores are sensitive to the exact prompt | Average several prompt templates per class |
| The image is out of the training distribution | The model may match a plausible but wrong caption confidently | Check on a labelled sample from your own data before trusting it |
Failure modes to expect in practice: hallucinated objects (the text describes something not in the image), attribute mix-ups (a red car and a blue bike swap colours), and weak spatial reasoning (left and right, or counting above a few items). A VLM also inherits the biases of its image-text training data. Web captions are noisy, so a model trained on them can learn loose associations.
History
Joint image-and-text models existed before 2020, but most were trained on small, carefully labelled datasets. Transformers changed the picture in two ways. The text side moved to large language models trained on web-scale text, and the image side moved to vision transformers in 2020, which let the same architecture handle both.
In 2021 OpenAI's CLIP paper trained an image encoder and a text encoder together on 400 million image-text pairs gathered from the internet, using the contrastive objective above. The paper's abstract reports that the zero-shot model matches the accuracy of a fully supervised ResNet-50 on ImageNet, without using any of ImageNet's 1.28 million training images. CLIP made the shared-space design the default for image-text retrieval and zero-shot classification.
From 2022 onward, the generative design gained ground. Flamingo (Alayrac et al., 2022) and BLIP-2 showed that a frozen vision encoder and a frozen language model could be joined by a small trainable bridge. LLaVA (2023) extended this to instruction following: it used a simple projection layer and a dataset of image-based conversations, and showed that a capable chat model could come from modest extra training.
Check yourself
QuestionRecall: what does the shared-space design compare, and how is the comparison scored?Show answer
It compares an image embedding with a text embedding. Both are normalised to unit length, and the score is their cosine similarity, the dot product of the unit vectors. Matching image-text pairs should get high scores and mismatched pairs low scores.
QuestionComputation: an image has cosine similarity with the prompt for class A and with the prompt for class B. With scale , what is to three decimal places?Show answer
Scale the scores to and . The gap is , so , which rounds to to three decimals. The point of the answer is that a gap of in cosine similarity, once scaled, gives almost certainty. The scale hides how close the two scores are.
QuestionWhy does the contrastive loss in the batch example use the other captions as negatives, and what happens if the batch contains two near-identical photos of the same dog?Show answer
Each image in the batch has one correct caption. The other captions in the batch serve as wrong answers, so the softmax denominator has one positive and negatives. If two images are near-duplicates with different captions, the model is asked to separate two things that look almost the same. This pushes the loss up and can make training noisy. Large batches make the chance of a true near-duplicate pair higher, which is one reason data cleaning matters for this objective.
QuestionApplied: you are building a photo search feature for a catalogue of 10 million product images, where users type short queries. Which design do you choose and why?Show answer
Choose a shared-space model. Encode every image once, store the vectors in an approximate nearest-neighbour index, and encode each query at search time. A query then costs one text encoding and one vector search, not one forward pass of a generative model per image. A generative VLM would be far too slow for this scale, since it would have to read every image for every query.
QuestionApplied: a chat assistant gets a photo of a chart and must answer a question about its trend. Why is the shared-space design a poor fit for this task?Show answer
A shared-space model outputs a similarity score between an image and a text. It cannot produce an open-ended answer such as "sales fell in the third quarter". The task needs a model that reads the image tokens and generates text token by token, which is the generative design.