Foundation Models · M.Sc. AIS @ UniTN 2026
{name.surname}@unitn.it
University of Trento
Three ideas from the language block, and where each one comes back with images.
| Idea | In the language block | With images |
|---|---|---|
| Free labels | The text supervises itself: next token (GPT), masked words (BERT), corrupted spans (T5). | Can images supervise themselves too? What is their free label? (Section 1) |
| Dense retrieval | Encode queries and documents separately, rank by cosine, index with FAISS, score with Recall@K. A cross-encoder reranks the top \(K\). | CLIP: the documents are images. Fusion encoders play the reranker. (Sections 2–3) |
| Question answering | From extractive (a span of the passage, SQuAD) to generative answers. | VQA: the passage is an image, and the answer is generated. (Section 3) |
A high score does not prove the model read the passage.
With images the shortcut is to answer without looking. We will test it in the evaluation section.
So, back to the first row: what is the free label for pixels?
Sen, P. & Saffari, A. (2020). What do models learn from question answering datasets? EMNLP.
Annotation does not scale.
The data keeps moving. Distributions shift over time; you cannot relaunch an annotation campaign every year.
Solution: exploit the raw data itself. Self-supervised learning (SSL) builds a pretext task whose labels are generated automatically, and learns features by solving it.
Today’s question: does a vision encoder need language to learn to see, or can language be added afterwards? Section 1 uses no language at all, Section 2 adds it; we answer at the end.
A task we do not care about, designed so that solving it requires understanding the data.
The recipe:
You already know two pretext tasks:
| Model | What is hidden | Free label |
|---|---|---|
| GPT | the rest of the sentence | the next token |
| BERT | 15% of the words | the masked words |
After pretraining, the pretext task is thrown away: what we keep is the encoder and its features.
You have 1 billion unlabelled images and no annotators.
Apply the recipe to images: what would you hide or transform, and what would the model predict?
Your answers, mapped: rotate → predict the angle · grey → predict the colours · hide a region → paint it back · shrink → upscale · two crops of one image → “are they the same image?”

Solving the pretext task forces the model to learn features that transfer. The labels are generated automatically from the image.




The pretext task is thrown away, so we cannot judge it by its own loss. We judge the features it produced, and for that we need labels again: those of a downstream dataset, never used during pretraining.
| Protocol | What is trained | Labels needed | Cost | The question it answers |
|---|---|---|---|---|
| Linear probe | one linear layer | to train the layer | minutes | is the information linearly available? |
| k-NN | nothing | as the stored reference set | seconds per query batch | are similar images close? |
| Fine-tuning | everything | for the target task (often few) | hours to days, per task | is it a good starting point? |
| Visualisation | nothing | only to colour the points | seconds | what does the space look like? (qualitative) |
The protocols can disagree: an encoder can fine-tune very well and still do poorly on the linear probe. Report more than one.
Qualitative only: t-SNE distorts distances, so cluster sizes and the gaps between clusters mean little. Use it to spot problems; rank methods with the linear probe.

Learn an encoder \(f\) that scores positive pairs high and negative pairs low:
\[\text{score}(f(x), f(x^+)) \gg \text{score}(f(x), f(x^-))\]
With one positive and \(N-1\) negatives:
\[ \mathcal{L}_{\text{InfoNCE}} = -\log \frac{e^{\,\text{sim}(f(x),\, f(x^+))/\tau}}{e^{\,\text{sim}(f(x),\, f(x^+))/\tau} + \sum_{i=1}^{N-1} e^{\,\text{sim}(f(x),\, f(x^-_i))/\tau}} \]
Remember this formula: it comes back, unchanged, when we add language.
van den Oord, A. et al. (2018). Representation learning with contrastive predictive coding. arXiv.
The same row of similarities, \((0.30, 0.25, 0.10)\), at three temperatures. Logits \(=\) similarity \(/\ \tau\), then softmax:
τ = 1
logits \((0.30, 0.25, 0.10)\)
\(p = (0.36, 0.34, 0.30)\)
loss \(= -\log 0.36 = \mathbf{1.02}\)
Almost a coin flip: a gap of 0.05 is invisible.
τ = 0.1
logits \((3.0, 2.5, 1.0)\)
\(p = (0.57, 0.35, 0.08)\)
loss \(= -\log 0.57 = \mathbf{0.56}\)
The positive starts to stand out.
τ = 0.01
logits \((30, 25, 10)\)
\(p = (0.993, 0.007, 0.000)\)
loss \(= -\log 0.993 = \mathbf{0.007}\)
A small gap becomes a sure choice.
Illustrative similarities. Loss from van den Oord, A. et al. (2018). Representation learning with contrastive predictive coding. arXiv.

Chen, T. et al. (2020). A simple framework for contrastive learning of visual representations. ICML.

Chen, T. et al. (2020). A simple framework for contrastive learning of visual representations. ICML.
Protocol: pretrain on ImageNet without labels, freeze, train a linear classifier. Plot: number of parameters (x) vs top-1 accuracy (y); the grey cross is a supervised ResNet-50.
A 4× wider ResNet-50 matches a supervised ResNet-50, with about 16× the parameters.

Chen, T. et al. (2020). A simple framework for contrastive learning of visual representations. ICML.
Why now: the next methods work on patches. MAE hides patches, DINO’s attention maps show where [CLS] looks, and later a VLM feeds patch tokens straight into an LLM.
Dosovitskiy, A. et al. (2021). An image is worth 16x16 words: transformers for image recognition at scale. ICLR.
BERT for images: mask patches, reconstruct them.
He, K. et al. (2022). Masked autoencoders are scalable vision learners. CVPR.


Fine-tuning is excellent; the linear probe is weaker than contrastive methods. Masked features are good raw material, less “ready to use”.
This is the disagreement from the fine-tuning slide: judged by fine-tuning, MAE is one of the best encoders; judged by linear probe, it is not.
He, K. et al. (2022). Masked autoencoders are scalable vision learners. CVPR.
So far, two ways to pretrain without labels, and neither gives features that are ready to use:
Question: can a ViT learn without labels features that work frozen, with a k-NN or a linear layer? And does it learn anything a convnet does not?
Caron, M. et al. (2021). Emerging properties in self-supervised vision transformers. ICCV.
Caron, M. et al. (2021). Emerging properties in self-supervised vision transformers. ICCV.
Self-attention of the [CLS] token in the last layer of a ViT-S/8 trained with no labels. Each pair: the input image and where [CLS] looks.
No labels, no masks, no text, and the attention finds the objects.
The vision counterpart of “emergent” capabilities in LLMs.
Caron, M. et al. (2021). Emerging properties in self-supervised vision transformers. ICCV. Fig. 1.
Redrawn from Caron, M. et al. (2021). Emerging properties in self-supervised vision transformers. ICCV. Fig. 2.
Caron, M. et al. (2021). Emerging properties in self-supervised vision transformers. ICCV.
Collapse: student and teacher agree perfectly by outputting the same thing for every image. The loss is minimal and the features are useless. SimCLR avoided it with negatives; DINO has none. Two operations on the teacher’s output pull in opposite directions:
It needs a momentum teacher: slow-moving targets, and better than the student throughout training.
Caron, M. et al. (2021). Emerging properties in self-supervised vision transformers. ICCV. Sec. 3.1 and 5.3.
gt.params = gs.params # teacher starts as a copy of the student
for x in loader:
x1, x2 = augment(x), augment(x) # two random views
s1, s2 = gs(x1), gs(x2) # student outputs, n × K
t1, t2 = gt(x1), gt(x2) # teacher outputs, n × K
loss = H(t1, s2) / 2 + H(t2, s1) / 2 # each view predicts the other
loss.backward(); update(gs) # SGD on the student only
gt.params = l * gt.params + (1 - l) * gs.params # EMA teacher
C = m * C + (1 - m) * cat([t1, t2]).mean(dim=0) # running centre
def H(t, s):
t = t.detach() # stop-gradient
s = softmax(s / tps, dim=1)
t = softmax((t - C) / tpt, dim=1) # centre + sharpen
return -(t * log(s)).sum(dim=1).mean()Legend. gs, gt: student and teacher networks · tps, tpt: student and teacher temperatures (the teacher’s is lower: sharpening) · C: running centre of the teacher outputs · l, m: momentum rates of the EMA teacher and of the centre.
Adapted from Caron, M. et al. (2021). Emerging properties in self-supervised vision transformers. ICCV. Algorithm 1 (without multi-crop).

Overlap with the true masks (Jaccard, PASCAL VOC12): random 22.0 · supervised 27.3 · DINO 45.9 (ViT-S/16).
ImageNet top-1, ViT-S, frozen features:
| Method | Linear | k-NN |
|---|---|---|
| Supervised | 79.8 | 79.8 |
| BYOL | 71.4 | 66.6 |
| MoCo v2 | 72.7 | 64.4 |
| SwAV | 73.5 | 66.3 |
| DINO | 77.0 | 74.5 |
Other self-supervised methods lose 5–8 points going from linear probe to k-NN; DINO loses 2.5. Its features are organised so that neighbours share a class.
Caron, M. et al. (2021). Emerging properties in self-supervised vision transformers. ICCV. Fig. 4 and Table 2.
First appearance of this lecture’s recurring lesson: the data curation matters as much as the method.
Oquab, M. et al. (2024). DINOv2: learning robust visual features without supervision. TMLR.
Zhou, J. et al. (2022). iBOT: image BERT pre-training with online tokenizer. ICLR.
PCA of the patch features of images in the same column; the first 3 components are shown as RGB, the background is removed by thresholding the first one. The same colour lands on the same part (wings, heads, wheels) across poses, styles and even different objects: an eagle and a plane, a real horse and a drawing.
Oquab, M. et al. (2024). DINOv2: learning robust visual features without supervision. TMLR. Fig. 1.
| Model | Pretraining | What you get |
|---|---|---|
| DINOv2 / v3 | self-distillation + masking, curated web images | general frozen features, dense and global |
| Sapiens2 | masking + self-distillation, 1B curated human images | one backbone for human-centric tasks (pose, segmentation, normals, pointmaps) |
| SAM | MAE encoder + supervised data engine (1.1B masks) | promptable segmentation with points and boxes |
Most SSL methods are available in one library: solo-learn (SimCLR, MoCo, BYOL, SwAV, DINO, MAE, VICReg, …).
da Costa, V. G. T. et al. (2022). solo-learn: a library of self-supervised methods for visual representation learning. JMLR.
Kirillov, A. et al. (2023). Segment anything. ICCV.
Khirodkar, R. et al. (2026). Sapiens2. ICLR.
Every protocol we used ends the same way: to recognise a class, you need labelled images of that class.
Question: could we write the row for “capybara” from the word itself, instead of learning it from examples?
We would need images and words in the same space. And the web pairs them for free: alt-text, captions, titles, billions of them.
The free label for pixels, from the first slide: the text that comes with them.
Keep SimCLR’s contrastive machinery; make the positive of an image its caption.
Instead of class labels, supervise vision with the text that came with the image on the web.
Align matching image–text pairs, push the rest apart. The label space is now all of language.
At ICML 2021, two papers scaled this idea. The architectures differ, but the key difference is data curation:
Both work. Scale can compensate for noise, and curation can compensate for scale.
Radford, A. et al. (2021). Learning transferable visual models from natural language supervision. ICML.
Jia, C. et al. (2021). Scaling up visual and vision-language representation learning with noisy text supervision. ICML. Sec. 3.

\[ L_{v2t} = -\log \frac{e^{\,f_v(I)\cdot f_t(T)/\tau}}{\sum_{T'} e^{\,f_v(I)\cdot f_t(T')/\tau}} \] \[ L_{t2v} = -\log \frac{e^{\,f_t(T)\cdot f_v(I)/\tau}}{\sum_{I'} e^{\,f_t(T)\cdot f_v(I')/\tau}} \] \[ L = \tfrac{1}{2}(L_{v2t}+L_{t2v}) \]
Radford, A. et al. (2021). Learning transferable visual models from natural language supervision. ICML.
A batch of 3 pairs, \(\tau = 0.05\). The same InfoNCE, once per row and once per column:
Rows: image → text (\(L_{v2t}\))
dog photo: logits \((6, 5, 2)\), \(p(\text{"a dog"}) = 0.72\), loss \(0.33\)
cat photo: \(p(\text{"a cat"}) = 0.67\), loss \(0.40\)
car photo: \(p(\text{"a car"}) = 0.96\), loss \(0.05\)
\(L_{v2t} = (0.33 + 0.40 + 0.05)/3 = \mathbf{0.26}\)
Columns: text → image (\(L_{t2v}\))
“a dog”: \(p(\text{dog photo}) = 0.76\), loss \(0.28\)
“a cat”: \(p(\text{cat photo}) = 0.63\), loss \(0.47\)
“a car”: \(p(\text{car photo}) = 0.96\), loss \(0.04\)
\(L_{t2v} = \mathbf{0.26}\), and \(L = \tfrac{1}{2}(0.26 + 0.26) = \mathbf{0.26}\)
Dog and cat confuse each other (0.25, 0.24): their losses are the largest, so the gradient pushes them apart. The car is already easy.
Illustrative similarities. Loss from Radford, A. et al. (2021). Learning transferable visual models from natural language supervision. ICML.

Radford, A. et al. (2021). Learning transferable visual models from natural language supervision. ICML. Fig. 3.

This is the linear probe’s \(W\) with every row written by the text encoder: no labelled images, no training. That is what zero-shot means.
Radford, A. et al. (2021). Learning transferable visual models from natural language supervision. ICML.
Zero-shot CLIP vs. a supervised ResNet-50 linear probe. Each bar: CLIP’s accuracy minus the probe’s, one dataset.

Linear probe on CLIP features vs. EfficientNet-L2 (Noisy Student), same bar reading.

Left: with no labels at all, CLIP beats a fully supervised linear probe on 16 of 27 datasets. It loses on specialised or abstract tasks: satellite images, tumours, counting, distances. Right: give CLIP’s features a linear probe too, and they beat the best ImageNet model of the time on 21 of 27 datasets.
Radford, A. et al. (2021). Learning transferable visual models from natural language supervision. ICML. Fig. 5, 11.

A ResNet-101 trained on ImageNet vs. zero-shot CLIP (ViT-L/14), which never saw an ImageNet label. Same ImageNet accuracy (76.2%), very different behaviour off ImageNet: the ResNet collapses on sketches, renditions and hard natural images (2.7% on ImageNet-A), while CLIP holds at 60–89%.
How it’s measured. Top-1 accuracy on ImageNet classes, on new test sets: ImageNetV2 (new photos collected the same way), Sketch (drawings), ImageNet-R (renditions: art, cartoons, toys), ObjectNet (objects in unusual poses and places), ImageNet-A (natural photos that fool ResNets). CLIP on ImageNet-A: 77.1%.
Radford, A. et al. (2021). Learning transferable visual models from natural language supervision. ICML. Fig. 13.

Back to robustness. Fang et al. retrained CLIP-style models changing one factor at a time: dataset size, the loss, language supervision, the training distribution. Only the training distribution moved the robustness under shift; dataset size, the loss and language supervision did not. CLIP is robust mostly because of what it saw.
Radford, A. et al. (2021). Learning transferable visual models from natural language supervision. ICML.
Schuhmann, C. et al. (2022). LAION-5B: an open large-scale dataset for training next generation image-text models. NeurIPS.
Gadre, S. Y. et al. (2023). DataComp: in search of the next generation of multimodal datasets. NeurIPS.
Fang, A. et al. (2022). Data determines distributional robustness in contrastive language image pre-training (CLIP). ICML.
OpenAI released the model, not the data nor the curation code. MetaCLIP rebuilt the curation from the few lines in the CLIP paper:
Result: 400M pairs from CommonCrawl, same model and training as CLIP: 70.8% zero-shot on ImageNet (ViT-B/16) vs 68.3% for OpenAI’s CLIP. Only the data changed.
Xu, H. et al. (2024). Demystifying CLIP data. ICLR. Sec. 3, Table 4.

Chuang, Y.-S. et al. (2025). Meta CLIP 2: a worldwide scaling recipe. arXiv. Fig. 1, Table 1.
CLIP’s loss asks, for each image, “which of these \(|B|\) captions is mine?” The answer is normalised over the whole batch: the full \(|B| \times |B|\) similarity matrix, gathered across every GPU.
SigLIP asks \(|B|^2\) independent questions, “does image \(i\) go with caption \(j\)?”, each a binary logistic loss:
\[ \mathcal{L} = -\frac{1}{|B|}\sum_{i}\sum_{j} \log \sigma\big(z_{ij}\,(t\, \mathbf{x}_i \cdot \mathbf{y}_j + b)\big), \qquad z_{ij} = \pm 1 \]
Zhai, X. et al. (2023). Sigmoid loss for language image pre-training. ICCV.
Same matrix, scale \(t = 100\) and bias \(b = -25\). Each cell on its own: logit \(= t \cdot \text{sim} + b\), loss \(= -\log \sigma(z \cdot \text{logit})\).
Positive (dog photo, “a dog”), \(z = +1\)
logit \(= 100 \times 0.30 - 25 = 5\)
P(match) \(= \sigma(5) = 0.993\)
loss \(= -\log \sigma(5) = \mathbf{0.007}\)
A confident, correct “yes”: tiny gradient.
Hard negative (dog photo, “a cat”), \(z = -1\)
logit \(= 100 \times 0.25 - 25 = 0\)
P(match) \(= \sigma(0) = 0.5\)
loss \(= -\log \sigma(0) = \mathbf{0.69}\)
Undecided: most of the gradient is here.
Easy negative (dog photo, “a car”), \(z = -1\)
logit \(= 100 \times 0.10 - 25 = -15\)
P(match) \(= \sigma(-15) \approx 0\)
loss \(= -\log \sigma(15) \approx \mathbf{0}\)
A confident, correct “no”: no gradient.
No softmax over a row: each GPU can score its own block of the matrix without seeing the rest of the batch.

Simpler loss, less hardware, same or better accuracy: SigLIP (and SigLIP 2) became the default vision encoder of many open VLMs (e.g. PaliGemma, Google’s open VLM).
Zhai, X. et al. (2023). Sigmoid loss for language image pre-training. ICCV. Fig. 2.


(A) some plants surrounding a lightbulb · (B) a lightbulb surrounding some plants
Vote: match each caption to an image.
| cosine similarity | caption (A) | caption (B) |
|---|---|---|
| Image 1 | 0.326 | 0.332 |
| Image 2 | 0.322 | 0.325 |
CLIP’s answer: ✗ both captions pick Image 1, by 0.004 and 0.007. The two captions are 0.96 similar to each other: for CLIP they are almost the same point. It sees a lightbulb and plants; who surrounds whom is lost.
Thrush, T. et al. (2022). Winoground: probing vision and language models for visio-linguistic compositionality. CVPR. Images © Getty Images, licensed for research.


(A) it’s a fire truck · (B) it’s a truck fire
Vote: match each caption to an image.
| cosine similarity | caption (A) | caption (B) |
|---|---|---|
| Image 1 | 0.277 | 0.242 |
| Image 2 | 0.219 | 0.264 |
CLIP’s answer: ✓ each caption picks its own image, by 0.06 and 0.02, far wider margins than for the lightbulb. “Fire truck” is a fixed phrase seen countless times on the web: it behaves like a single word.
Thrush, T. et al. (2022). Winoground: probing vision and language models for visio-linguistic compositionality. CVPR. Images © Getty Images, licensed for research.
CLIP’s limits are not random: each one follows from how it was built.
| Cause | What breaks | Evidence |
|---|---|---|
| The objective. Picking the right caption among random ones never needs word order, so CLIP learns a bag of concepts | binding, word order, relations: “a red ball and a blue cube” = “a blue ball and a red cube” | the lightbulb pair (captions 0.96 similar). On all 400 Winoground pairs, CLIP ViT-B/32 gets 8% fully right (both images and both captions matched), below random guessing (16.7%) |
| The data. Web captions rarely state counts or distances, or mention what is absent | counting, distances, negation (“not a yellow coat”) | the zero-shot plot (“CLIP — it actually works”): CLEVRCounts −18, KITTI Distance (how far is the nearest car) −34. Negation, our run: on the fire-truck photo, “a photo of a dog” 0.92 vs “a photo with no dog” 0.08 |
| The interface. It only outputs a similarity score; the text encoder stops at 77 tokens | questions, explanations, long descriptions | every activity so far: CLIP can only rank captions we wrote |
CLIP knows what is in an image but little about how it is arranged, and it can only score captions we write.
The third row is what the next section fixes: connect the vision encoder to a model that generates language.
Radford, A. et al. (2021). Learning transferable visual models from natural language supervision. ICML. Fig. 5, Sec. 2.4.
Yuksekgonul, M. et al. (2023). When and why vision-language models behave like bags-of-words, and what to do about it? ICLR.
Thrush, T. et al. (2022). Winoground: probing vision and language models for visio-linguistic compositionality. CVPR. Table 3.
CLIP gives one score for the whole image. Many questions are about one region of it:
Question: can we tell CLIP where to look by editing the pixels, keeping the whole image, with no training?
Shtedritski, A., Rupprecht, C. & Vedaldi, A. (2023). What does CLIP know about a red circle? Visual prompt engineering for VLMs. ICCV.
Mark, don’t crop: draw a thin red ellipse around each candidate region, score every marked image against the query, keep the best. No training, no new parameters, and the context stays in the image.
Shtedritski, A., Rupprecht, C. & Vedaldi, A. (2023). What does CLIP know about a red circle? Visual prompt engineering for VLMs. ICCV. Our example: CLIP ViT-L/14 on one photo, illustrative.
Referring expressions, zero-shot (accuracy, %)
| Method | RefCOCO | RefCOCO+ | RefCOCOg |
|---|---|---|---|
| CPT (colour the box) | 32.2 | 31.9 | 36.7 |
| ReCLIP, crops | 42.0 | 47.4 | 57.8 |
| ReCLIP, crops + relation rules | 45.8 | 47.9 | 59.3 |
| Red circle | 49.8 | 55.3 | 59.4 |
How it’s measured. RefCOCO / RefCOCO+ / RefCOCOg: COCO photos, each with a sentence that names one object; RefCOCO+ forbids location words (“left”), RefCOCOg has longer sentences. A prediction counts if the chosen box overlaps the true one enough (intersection over union ≥ 0.5, Section 6); validation splits, higher is better. Naming keypoints (CUB-200 birds): given the keypoint positions and their names, % of names matched to the right position.
The data also teaches what circles mean. News sites circle missing people and suspects. Circling a person in a COCO photo raises how often CLIP picks a criminal label (“criminal”, “thief”, “suspicious person”) from 29.8% to 47.9% (ViT-L/14 at 336 px).
Shtedritski, A., Rupprecht, C. & Vedaldi, A. (2023). What does CLIP know about a red circle? Visual prompt engineering for VLMs. ICCV. Tables 2, 3, 5, 6, Fig. 6, Sec. 4.1.
from PIL import Image
from transformers import CLIPModel, CLIPProcessor
name = "openai/clip-vit-base-patch32"
model, proc = CLIPModel.from_pretrained(name), CLIPProcessor.from_pretrained(name)
labels = ["cat", "dog", "car"]
inputs = proc(text=[f"a photo of a {l}" for l in labels],
images=Image.open("pet.jpg"), return_tensors="pt", padding=True)
probs = model(**inputs).logits_per_image.softmax(dim=-1)
print(dict(zip(labels, probs[0].tolist())))Live: change the prompt template, add a distractor label, try a binding pair, draw a red circle.

CLIP’s shared space is not really shared: images and captions sit in two separate regions, and each pair is joined across the gap. The same happens in other contrastive models (video, medical images, proteins), and even with random weights (bottom row): the gap is there before training, and the contrastive loss keeps it.
How to read it. UMAP (a 2-D projection that keeps neighbours close) of paired embeddings: red = images (or video, medical images, proteins), blue = text, a grey line joins each pair. Top: trained models. Bottom: the same architectures with random weights.
Liang, W. et al. (2022). Mind the gap: understanding the modality gap in multi-modal contrastive representation learning. NeurIPS. Fig. 1.

FLAVA’s goal: a true vision-and-language foundation model should be good at vision, at language, and at vision-language, all at the same time. Before it, each family was good at one side:
One model, three encoders (image, text, multimodal), trained with unimodal losses (masked image / text modelling, also on unpaired data) and multimodal ones (contrastive, image–text matching). 70M public pairs.
| ViT-B/16 | VQAv2 | CoLA (text) | ImageNet linear |
|---|---|---|---|
| CLIP | 55.3 | 25.4 | 80.2 |
| FLAVA | 72.8 | 50.7 | 75.5 |
How it’s measured. VQAv2: answer accuracy on visual questions. CoLA: classify whether an English sentence is grammatical (Matthews correlation, a text-only task). ImageNet linear: linear-probe top-1 on frozen image features.
A step towards one model for everything, but still an encoder: it classifies and retrieves, it does not generate language.
Singh, A. et al. (2022). FLAVA: a foundational language and vision alignment model. CVPR. Table 5.
Four design choices, each with its own literature:
Blue = frozen vision encoder, green = frozen LLM, purple = the part you design. The bar is the LLM’s 4K-token context: a text prompt takes a few tokens, and the image takes as many as your connector gives it.
You have a frozen vision encoder that outputs 576 tokens × 1024 dims (a 24×24 patch grid) and a frozen LLM with 4096-dim embeddings and a 4K-token context. How do you get the image into the LLM?
3 minutes in pairs.
576 tokens × 4096 dims in the input · or fewer tokens first · or new layers that look at the image from inside the LLM: the three families, next slide.
The three families that most open VLMs fall into. The question each one answers: where do the image features meet the text, and how many tokens do they cost?
| Family | Example | How visual features enter | Visual tokens | Trained |
|---|---|---|---|---|
| Projection | LLaVA | linear / MLP maps patch features into the LLM input sequence | all patches (256 in LLaVA, 576 in LLaVA-1.5, more with high resolution) | projector, then LLM |
| Learned queries | BLIP-2, Qwen-VL | a small transformer with \(K\) learned queries compresses the image | fixed \(K\) (32–256) | Q-Former / resampler |
| Cross-attention | Flamingo, Llama 3.2-V | new gated cross-attention layers inside the LLM attend to image features | none in the sequence | new layers (Llama 3.2-V also tunes the image encoder) |
Not the only routes. Encoder-free models skip the vision encoder and feed raw patches straight into the LLM (Fuyu). Early-fusion models turn images into discrete tokens and train one transformer on both from scratch (Chameleon). Unified models that also generate images, for example with a diffusion head (Transfusion), are beyond this lecture.
Bavishi, R. et al. (2023). Fuyu-8B: a multimodal architecture for AI agents. Adept AI blog.
Chameleon Team (2024). Chameleon: mixed-modal early-fusion foundation models. arXiv.
Zhou, C. et al. (2025). Transfusion: predict the next token and diffuse images with one multi-modal model. ICLR.
The three families in the order they appeared: Frozen (2021) → Flamingo (2022) → BLIP-2 (2023) → LLaVA (2023).

The root of family (a): images become “foreign words” in the LLM’s input.
Tsimpoukelli, M. et al. (2021). Multimodal few-shot learning with frozen language models. NeurIPS.

Alayrac, J.-B. et al. (2022). Flamingo: a visual language model for few-shot learning. NeurIPS. Fig. 3.
How do you add new layers to a frozen LLM without breaking it?
Each new layer (a cross-attention, then an MLP, the transformer’s feed-forward block) is a residual branch scaled by a learnable gate:
\[ y = x + \tanh(\alpha_1)\,\text{XAttn}(x, V) \] \[ y \leftarrow y + \tanh(\alpha_2)\,\text{MLP}(y) \]
Alayrac, J.-B. et al. (2022). Flamingo: a visual language model for few-shot learning. NeurIPS. Sec. 2.2.
Zero-init gates: start as the identity, then learn the change. A new module begins silent, so a pretrained (or very deep) network is not disturbed.
| Model | What starts at zero | What it is for |
|---|---|---|
| Flamingo (2022) | \(\tanh(\alpha)\) on new cross-attention and MLP layers | add vision to a frozen LLM |
| LoRA (2022, next lecture) | \(B = 0\), so the update \(\Delta W = BA\) is 0 | fine-tune a frozen LLM cheaply |
| ControlNet (2023, generation lecture) | “zero convolutions” around a trainable copy of the encoder | add spatial control to a frozen diffusion model |
| ReZero (2021) | every residual branch scaled by \(\alpha = 0\) | train very deep networks fast |
Routing gates are a different idea: an input-dependent value multiplies the signal at every step, to decide what passes. A sigmoid in \([0, 1]\) in LSTM, GRU and GLU; a Swish in the SwiGLU MLPs of today’s LLMs (e.g. LLaMA).
Hu, E. J. et al. (2022). LoRA: low-rank adaptation of large language models. ICLR. · Zhang, L. et al. (2023). Adding conditional control to text-to-image diffusion models. ICCV.
Bachlechner, T. et al. (2021). ReZero is all you need: fast convergence at large depth. UAI. · Shazeer, N. (2020). GLU variants improve Transformer. arXiv.
Hochreiter, S. & Schmidhuber, J. (1997). Long short-term memory. Neural Computation.
By 2023, end-to-end vision-language pretraining had become prohibitively expensive. Meanwhile, excellent unimodal models were free to download: CLIP-style image encoders and LLMs.
Question: how do you align a frozen image encoder with a frozen LLM, training only a small module in between?
Li, J. et al. (2023). BLIP-2: bootstrapping language-image pre-training with frozen image encoders and large language models. ICML.
The queries learn to pull out of the image what a caption would describe.
Li, J. et al. (2023). BLIP-2: bootstrapping language-image pre-training with frozen image encoders and large language models. ICML. Redrawn from Fig. 1–2; Sec. 3.1, 3.2, 3.4.
Only the small module between the two frozen models learns to speak the LLM’s language.
Li, J. et al. (2023). BLIP-2: bootstrapping language-image pre-training with frozen image encoders and large language models. ICML. Redrawn from Fig. 3; Sec. 3.3, Table 2.

Why not stop after stage 1? The Q-Former’s text branch is small and knows only captions: no world knowledge, no reasoning, no instructions. Stage 1 teaches the queries what to look at; the LLM does the talking. Without stage 1, the LLM fails (zero-shot VQA drops sharply, next slide). When nothing must be generated, the Q-Former is enough: for image–text retrieval, BLIP-2 fine-tunes the stage-1 model and uses no LLM at all.
Li, J. et al. (2023). BLIP-2: bootstrapping language-image pre-training with frozen image encoders and large language models. ICML. Fig. 1 and Sec. 4.4.

Limit: it describes images well, but it is not an assistant. Trained on single image–caption pairs, it gains nothing from in-context examples, and it was never tuned on multimodal instructions. That is the gap LLaVA targets.
How it’s measured. Zero-shot VQAv2: open-ended questions on images, no VQA training; VQA accuracy (an answer counts if at least 3 of 10 annotators gave it). BLIP-2 65.0 vs Flamingo-80B 56.3.
Li, J. et al. (2023). BLIP-2: bootstrapping language-image pre-training with frozen image encoders and large language models. ICML. Fig. 5, Table 2, Sec. 5.
Question: can instruction tuning be carried over to images, to build a general-purpose visual assistant? The obstacle: almost no multimodal instruction data exists.
Liu, H. et al. (2023). Visual instruction tuning. NeurIPS.
Intuition: GPT-4 (text-only in 2023) cannot see, so describe the image to it in words. Give it the COCO captions and the object boxes, a symbolic version of the image, and ask it to write conversations as if it were looking at the photo.
Three kinds of answers:
158K samples, generated almost for free.


Liu, H. et al. (2023). Visual instruction tuning. NeurIPS. Table 1.
The bet: the connector matters less than the data. It paid off: LLaVA became a common starting point for open VLMs.
Liu, H. et al. (2023). Visual instruction tuning. NeurIPS.

How it’s measured. LLaVA-Bench (COCO): 90 questions on 30 COCO images; text-only GPT-4 rates LLaVA’s answer and its own reference answer (written from the captions) from 1 to 10; score = LLaVA’s rating as a % of GPT-4’s. ScienceQA: ~21K multiple-choice science questions, many with an image; accuracy.
Liu, H. et al. (2023). Visual instruction tuning. NeurIPS. Tables 4, 7.
Every gain in resolution is paid in visual tokens. Keep that in mind for video.
Liu, H. et al. (2024). Improved baselines with visual instruction tuning (LLaVA-1.5). CVPR.
Liu, H. et al. (2024). LLaVA-NeXT: improved reasoning, OCR, and world knowledge. Blog post.
Wang, P. et al. (2024). Qwen2-VL: enhancing vision-language model’s perception of the world at any resolution. arXiv.
Most VLMs squeeze every image into the encoder’s fixed input: resize to 336px, or cut it into fixed tiles (LLaVA-NeXT). Qwen’s bet across three releases: feed the input at its own size and duration, and give the model positions that know space and time.
| Release | Connector | The new idea |
|---|---|---|
| Qwen-VL (2023) | learned queries, family (b): 256 queries, one cross-attention layer | fixed 448px input |
| Qwen2-VL (2024) | projection, family (a): an MLP merges 2×2 neighbouring patches | native dynamic resolution: any image size, a variable number of tokens; M-RoPE positions in time, height, width |
| Qwen2.5-VL (2025) | same MLP merger | a ViT trained from scratch with window attention; time positions in seconds; data from 1.2T to 4.1T tokens |
Qwen moved from family (b) to family (a): images of any size need a variable number of tokens, which a fixed set of learned queries cannot give.
Bai, J. et al. (2023). Qwen-VL: a versatile vision-language model for understanding, localization, text reading, and beyond. arXiv.
Wang, P. et al. (2024). Qwen2-VL: enhancing vision-language model’s perception of the world at any resolution. arXiv.
Bai, S. et al. (2025). Qwen2.5-VL technical report. arXiv.

Bai, S. et al. (2025). Qwen2.5-VL technical report. arXiv. Fig. 1, Sec. 2.1.
M-RoPE: RoPE (rotary position embedding) encodes a token’s position by rotating its query and key vectors; M-RoPE gives every token three position ids, (time, height, width), instead of one.

The same idea for outputs: boxes and points are written in the image’s real pixel coordinates (earlier models rescaled them to [0, 1]). The model sees the true size of objects, which helps its grounding (detect, point, count).
Bai, S. et al. (2025). Qwen2.5-VL technical report. arXiv. Sec. 2.1.2–2.1.3.
Wang, P. et al. (2024). Qwen2-VL: enhancing vision-language model’s perception of the world at any resolution. arXiv. (M-RoPE figure)
Data, 1.2T → 4.1T tokens. Captions, OCR, visual knowledge (landmarks, species, celebrities), documents parsed into HTML, grounding in absolute coordinates, video, agent interactions. Interleaved web pages are scored for image–text relevance and complementarity, and only the good ones are kept.
| Stage | Trained | Data | Tokens | Context |
|---|---|---|---|---|
| Pre-training 1 | ViT only | captions, knowledge, OCR | 1.5T | 8K |
| Pre-training 2 | ViT + LLM | + interleaved, VQA, video, grounding, agent, pure text | 2T | 8K |
| Pre-training 3 | ViT + LLM | + long video, long documents, long agent traces | 0.6T | 32K |
| Post-training | LLM (ViT frozen) | SFT on ~2M samples (half text-only), then DPO (preference tuning, next lecture) |
Bai, S. et al. (2025). Qwen2.5-VL technical report. arXiv. Sec. 2.2–2.3, Table 2.
Most VLM papers change the encoder, the connector, the LLM and the data all at once, so it is hard to tell which choice made the difference. Three papers isolate them with controlled experiments:
| Design choice (anatomy slide) | Paper | Its question |
|---|---|---|
| ③ LLM and ② connector | Idefics2 (2024) | which component matters most? which way in? |
| ① Vision encoder | Cambrian-1 (2024) | which encoder, and does it need language? |
| ④ Data | Molmo / PixMo (2025) | can we get there without copying a closed model? |
Laurençon, H. et al. (2024). What matters when building vision-language models? NeurIPS.
Tong, S. et al. (2024). Cambrian-1: a fully open, vision-centric exploration of multimodal LLMs. NeurIPS.
Deitke, M. et al. (2025). Molmo and PixMo: open weights and open data for state-of-the-art vision-language models. CVPR.
Controlled ablations, one change at a time, same data and compute.
Laurençon, H. et al. (2024). What matters when building vision-language models? NeurIPS. Findings 1–5.
The same VLM recipe with 20+ vision encoders swapped in: the LLM is used as a probe for the encoder.
Back to the opening question: language is the best supervision so far, but not the only one.
How it’s measured. MMMU: college-level exam questions with images. MathVista: math on charts and figures. AI2D: science diagrams. CV-Bench: 2,638 hand-checked questions on counting, spatial relations, depth order and distance.
Tong, S. et al. (2024). Cambrian-1: a fully open, vision-centric exploration of multimodal LLMs. NeurIPS. Findings 1, 6, 7.
The problem: open models had become distillations of closed ones. LLaVA’s data was written by GPT-4; later datasets use GPT-4V captions (ShareGPT4V). The weights are open, but nobody knows how to build a strong VLM from scratch.
The answer: collect the data from people, without any external VLM.
Result: fully open data, and the 72B model ranks second by human preference, just behind GPT-4o (Elo 1077 vs 1079).
How it’s measured. Human preference: ~870 annotators compared the answers of two anonymous models on the same image and prompt (325K comparisons); an Elo score is fitted from the wins, as in Chatbot Arena.
Deitke, M. et al. (2025). Molmo and PixMo: open weights and open data for state-of-the-art vision-language models. CVPR. Sec. 3, Table 1.
vLLM serves a model on a GPU machine behind the same HTTP API as OpenAI’s: any OpenAI client works, you only change the address. Images travel inside the message, encoded as text (base64).
import base64, os
from openai import OpenAI
client = OpenAI(base_url=os.environ.get("VLLM_BASE_URL", "http://LAB-HOST:8000/v1"), # the lab server
api_key=os.environ.get("VLLM_API_KEY", "EMPTY"))
MODEL = "Qwen/Qwen2.5-VL-7B-Instruct" # whatever the lab serves
def as_data_url(path): # image file -> text the API can carry
return "data:image/jpeg;base64," + base64.b64encode(open(path, "rb").read()).decode()
resp = client.chat.completions.create(model=MODEL, max_tokens=200, messages=[
{"role": "user", "content": [ # one user turn: text + image together
{"type": "text", "text": "What is unusual about this image?"},
{"type": "image_url", "image_url": {"url": as_data_url("scene.jpg")}}]}])
print(resp.choices[0].message.content) # the generated answerOn the lab box: vllm serve Qwen/Qwen2.5-VL-7B-Instruct. Export VLLM_BASE_URL to point your client at it.
A 10-minute video, sampled at 1 frame per second, 256 visual tokens per frame.
How many tokens? How would you fit it into the LLM?
1 minute to compute, 2 minutes for fixes.
\(600 \times 256 = \mathbf{153{,}600}\) tokens, before any text: 37× a 4K context.
Most video VLMs reuse the image encoder frame by frame, so the token count explodes. Every design is a way to cut the budget without losing when things happen.
At the extreme, LLaMA-VID keeps 2 tokens per frame. Qwen2.5-VL uses all four: dynamic frame sampling, the 2×2 merger, two consecutive frames per patch, time ids in seconds.
Li, Y. et al. (2024). LLaMA-VID: an image is worth 2 tokens in large language models. ECCV.
Bai, S. et al. (2025). Qwen2.5-VL technical report. arXiv. Sec. 2.1.
Video did not need a new recipe: at each step it reused what had just worked for images.
So the real question is not the architecture: does a model built on image features actually use time? Next slides.
Luo, H. et al. (2022). CLIP4Clip: an empirical study of CLIP for end to end video clip retrieval. Neurocomputing. · Lin, B. et al. (2024). Video-LLaVA: learning united visual representation by alignment before projection. EMNLP.
Li, K. et al. (2023). VideoChat: chat-centric video understanding. arXiv. · Zhang, Y. et al. (2024). Video instruction tuning with synthetic data (LLaVA-Video). arXiv.
A single well-chosen frame matches many video-language models on standard benchmarks.
| MSR-VTT-MC | NExT-QA | NExT-QA, hard subset | |
|---|---|---|---|
| one frame picked by ATP (CLIP features) | 93.2 | 49.2 | 20.2 |
| best video model | 92.1 (VideoCLIP) | 49.7 (HGA) | 44.1 (HGA) |
Much of “video QA” is image QA in disguise.
Quick check: one frame of a benchmark question. Hands up: can you answer it?
How it’s measured. Multiple-choice accuracy (%), 5 options per question, so chance = 20%. MSR-VTT-MC: pick the caption that matches the video. NExT-QA: answer a descriptive, temporal or causal question. Hard subset: the NExT-QA questions that ATP models cannot answer.
Buch, S. et al. (2022). Revisiting the “video” in video-language understanding. CVPR. Tables 1, 3.
Video LMMs are built with many design choices that are never justified. Studying them properly is too expensive:
| Obstacle | Why |
|---|---|
| Training is costly | a video is thousands of tokens |
| Evaluation is costly | 184 GPU-hours to evaluate one 3B model |
| Benchmarks mislead | many questions are answered from text or one frame |
Question: how do you explore the video design space cheaply, and measure what really needs video?
Zohar, O. et al. (2025). Apollo: an exploration of video understanding in large multimodal models. CVPR.
① ApolloBench: test only what needs video. Ask open-source models every multiple-choice question three times: with the video, with only the centre frame, with only the text. Drop the questions that more than half of the models get right without the video. Keep the 400 that best separate models, and check them by hand. 41× faster to run, and it still ranks models like the full benchmarks.
② Scaling Consistency: explore small, then scale. Design choices that win on a ~2–4B model also win on 7B (R² > 0.9: the scores of 21 design variants at the small size predict their scores at 7B). Below that size, they do not transfer.
How well design choices made on a model of each size predict those on 7B (red curve)

Zohar, O. et al. (2025). Apollo: an exploration of video understanding in large multimodal models. CVPR. Sec. 2–3, Fig. 3.
You have 16 frames’ worth of budget for every video, short or long.
Would you sample 16 frames per video, or a fixed number of frames per second?
And how many tokens per frame would you keep?
1 minute, then vote.

Zohar, O. et al. (2025). Apollo: an exploration of video understanding in large multimodal models. CVPR. Findings 2, 3, 6; Fig. 4.
Zohar, O. et al. (2025). Apollo: an exploration of video understanding in large multimodal models. CVPR. Findings 4, 5, 7–9.
Apollo-3B beats most 7B video models (55.1 on LongVideoBench).
Apollo-7B leads its size class (70.9 on MLVU, 63.3 on Video-MME with subtitles), close to 30B models.
The message: a careful study on small models, with a benchmark that really needs video, beats scaling up blindly.
How it’s measured. All multiple-choice accuracy on long videos. LongVideoBench: 3.8K web videos up to an hour, questions that refer to a specific moment. MLVU: 1.7K videos of 3 min to 2 h, 9 tasks. Video-MME: 900 videos from 11 s to 1 h, 2,700 expert questions, with or without subtitles.
Zohar, O. et al. (2025). Apollo: an exploration of video understanding in large multimodal models. CVPR. Table 4.
Girdhar, R. et al. (2023). ImageBind: one embedding space to bind them all. CVPR.
Same recipe as for images and video: encoders per modality, a connector, an LLM, aligned in time.
Xu, J. et al. (2025). Qwen2.5-Omni technical report. arXiv. Redrawn from Fig. 2.
| Task | Metric: what it measures | Typical benchmarks | |
|---|---|---|---|
| Retrieval (image ↔︎ text) | Recall@K: is the right match among the top \(K\)? | COCO, Flickr30k | → coming up |
| Zero-shot classification | top-1 accuracy with class names as prompts | ImageNet; shifted: -R, -A, Sketch | ✓ seen, Section 2 |
| Representations | linear probe, k-NN accuracy on frozen features | ImageNet, transfer suites | ✓ seen, Section 1 |
| VQA | answer accuracy: agreement with several human answers | VQAv2, GQA | → coming up |
| Captioning | CIDEr, BLEU-4, SPICE: overlap with reference captions | COCO Captions, NoCaps | → coming up |
| Grounding | accuracy at IoU ≥ 0.5 on the box (spatial) or time span (temporal) | RefCOCO / + / g; temporal: Charades-STA | → coming up |
Each query has one true match among thousands of candidates. R@1 asks for a perfect ranking; R@5 and R@10 forgive near misses, which matters when the other top images also fit the text.
Open-ended answers are compared by exact string match after normalisation (case, articles, number words), so “2 cats” and “two” depend on the normaliser. Multiple-choice benchmarks (MMMU, MMBench) avoid this, but they only test whether the model picks the right option.
Antol, S. et al. (2015). VQA: visual question answering. ICCV.
Goyal, Y. et al. (2017). Making the V in VQA matter: elevating the role of image understanding in visual question answering (VQAv2). CVPR.
Holtzman, A. et al. (2021). Surface form competition: why the highest probability answer isn’t always right. EMNLP.
Papineni, K. et al. (2002). BLEU: a method for automatic evaluation of machine translation. ACL. · Vedantam, R. et al. (2015). CIDEr: consensus-based image description evaluation. CVPR.
Anderson, P. et al. (2016). SPICE: semantic propositional image caption evaluation. ECCV.
Zhang, T. et al. (2020). BERTScore: evaluating text generation with BERT. ICLR.
Sellam, T. et al. (2020). BLEURT: learning robust metrics for text generation. ACL.
Hessel, J. et al. (2021). CLIPScore: a reference-free evaluation metric for image captioning. EMNLP.
Spatial: phrase → box (RefCOCO). Temporal: phrase → time span in a video (Charades-STA). Correct if IoU ≥ 0.5; video papers report R@1 at IoU 0.5 and 0.7.
Yu, L. et al. (2016). Modeling context in referring expressions. ECCV.
Gao, J. et al. (2017). TALL: temporal activity localization via language query. ICCV.
Broad suites: MMMU (11.5K college-exam questions, 30 subjects), MMBench (3.2K multiple-choice, 20 abilities, options rotated), MME (yes/no questions, scored in points), SEED-Bench (multiple-choice over images and video). Hallucination: two ways to catch objects that are not there.
Yue, X. et al. (2024). MMMU: a massive multi-discipline multimodal understanding and reasoning benchmark for expert AGI. CVPR. · Liu, Y. et al. (2024). MMBench: is your multi-modal model an all-around player? ECCV.
Fu, C. et al. (2025). MME: a comprehensive evaluation benchmark for multimodal large language models. NeurIPS D&B. · Li, B. et al. (2024). SEED-Bench: benchmarking multimodal large language models. CVPR.
Rohrbach, A. et al. (2018). Object hallucination in image captioning. EMNLP.
Li, Y. et al. (2023). Evaluating object hallucination in large vision-language models. EMNLP.
Hands up: who can answer anyway?
Questions from Chen, L. et al. (2024). Are we on the right way for evaluating large vision-language models? NeurIPS. Fig. 1.

Chen, L. et al. (2024). Are we on the right way for evaluating large vision-language models? NeurIPS. Fig. 1.

Report several metrics, run a blind (text-only) baseline, and keep qualitative probing in the loop.
Tong, S. et al. (2024). Eyes wide shut? Exploring the visual shortcomings of multimodal LLMs. CVPR. Fig. 2.

Language: necessary for the interface. For the encoder: so far an efficient shortcut, with no proof that it is necessary.
Fan, D. et al. (2025). Scaling language-free visual representation learning. arXiv. Fig. 1.
Exit ticket: one thing CLIP can’t do, and which architecture fixes it.
M.Sc. AIS · Foundation Models · Fall 2026