AILearn AI
LearnGlossarySources
ID/EN
Learn AI — open material for learning AIEvery lesson cites its original sources.
◈Multimodal, Video & 3D
  1. Vision Transformers and CLIP
  2. Multimodal LLMs (Vision-Language Models)
  3. Video Generation
  4. 3D: NeRF, Gaussian Splatting and Text-to-3D
Modules
  1. ◎ AI Foundations
  2. ∿ Classical Machine Learning
  3. ⌬ Neural Networks
  4. ↘ Training Results & Evaluation
  5. ▦ Deep Learning Architectures
  6. ✎ Large Language Models
  7. ◐ Image Generation
  8. ♪ Audio & Speech AI
  9. ◈ Multimodal, Video & 3D
  10. ↻ Reinforcement Learning
  11. ⚙ ML Development & MLOps
  12. ★ Advanced & Frontier Topics
Learn/Multimodal, Video & 3D

Multimodal LLMs (Vision-Language Models)

How a language model learns to see: a vision encoder, a connector (linear/MLP projection, Q-Former, Perceiver Resampler + gated cross-attention) and an LLM, trained in stages. Flamingo, BLIP-2, LLaVA, GPT-4V-style systems, their knobs and failure modes.

Advanced~28 min·6 references
Key terms
Vision-language model (VLM)MultimodalLarge language model (LLM)CLIPVision Transformer (ViT)TokenInstruction tuningHallucination

A vision-language model (VLM) takes images (and often video frames) plus text and answers in text: describing photos, reading charts and receipts, answering questions about screenshots, or acting as the 'eyes' of an Agent (LLM agent). Training one from scratch would be enormously expensive, so almost every VLM reuses two pretrained parts, a vision encoder such as CLIP's ViT and an Large language model (LLM), and learns a small bridge between them. This lesson is about that bridge.

≈
An interpreter between two experts
Picture a brilliant writer who has never seen anything (the LLM) and a superb photographer who cannot write (the vision encoder). You don't retrain either of them; you hire an interpreter who turns the photographer's impressions into 'words' the writer understands. The connector is that interpreter: it maps image features into the LLM's token-embedding space.

The common blueprint

  1. Vision encoder (usually a frozen ViT from CLIP/SigLIP/EVA-CLIP) turns the image into a grid of patch features, e.g. 24×24 = 576 vectors for a 336 px image with 14 px patches.
  2. Connector maps those features into the LLM's embedding space, either keeping one token per patch (projection) or compressing them into a fixed number of tokens (learned queries).
  3. LLM reads the visual tokens together with the text tokens and generates the answer with ordinary Next-token prediction.
H_v = W · Z_v (or MLP(Z_v)) input to LLM = [ H_v ; embed(text tokens) ] p(answer | image, question) = Π p(yᵢ | H_v, question, y_<i)
The simplest connector (LLaVA): a projection W of the vision features Z_v into 'visual tokens' H_v that are concatenated with text embeddings.
In words: Project the vision features into the LLM's embedding space to get visual tokens, put them in front of the embedded text, and let the LLM predict the answer one token at a time, each token conditioned on the image tokens, the question and the answer so far.
Symbols(hover a symbol in the formula)
H_v
visual tokens in the LLM's embedding space
W
the projection matrix (1024 × 4096 for a 7B LLM)
Z_v
patch features from the vision encoder (576 × 1024 for CLIP ViT-L/14 at 336 px)
MLP(Z_v)
LLaVA-1.5's 2-layer MLP connector instead of a single matrix
;
concatenation along the sequence
embed(text tokens)
the LLM's ordinary word embeddings of the prompt
Π
product over all answer tokens
yᵢ
the i-th answer token
y_<i
all answer tokens before position i
▸Worked example
Z_v: 576 × 1024 → W: 1024 × 4096 (4,194,304 weights) → H_v: 576 × 4096 2-layer MLP (1024 → 4096 → 4096): 4,194,304 + 16,777,216 ≈ 21M weights, still tiny next to a 7B LLM A 30-token question → the LLM reads 576 + 30 = 606 positions A 3-token answer with probabilities 0.9, 0.8, 0.95 → p(answer | …) = 0.9 · 0.8 · 0.95 = 0.684

Three landmark designs

Flamingo (DeepMind, 2022): gated cross-attention

Flamingo[1] keeps a vision encoder and a 70B Chinchilla LM frozen. A Perceiver Resampler compresses any number of image or video-frame features into 64 visual tokens. New gated cross-attention layers are inserted between the frozen LM layers; each has a tanh gate initialized at 0, so at the start the model behaves exactly like the original LM and gradually learns to 'look'. Trained on web pages with interleaved images and text, Flamingo is a strong few-shot learner: show it a few (image, answer) examples in the prompt and it adapts, like In-context learning in text LLMs.

BLIP-2 (Salesforce, 2023): the Q-Former

BLIP-2[2] keeps both the image encoder and the LLM frozen and trains only a lightweight Q-Former (~188M parameters): a small transformer with 32 learned query vectors that cross-attend to the image features and extract the most text-relevant information. Stage 1 trains the Q-Former against the frozen image encoder with image-text contrastive, matching and generation losses; stage 2 connects its 32 outputs to the frozen LLM through a linear layer. With 54× fewer trainable parameters than Flamingo-80B, it outperformed it by 8.7% on zero-shot VQAv2.

LLaVA (2023): simple projection + visual instruction tuning

LLaVA[3] showed that a plain linear projection from CLIP ViT-L/14 features into a Vicuna LLM works surprisingly well, if the training data is right. Stage 1 trains only the projection on ~595K image-caption pairs (feature alignment). Stage 2 fine-tunes the projection and the LLM on 158K multimodal instruction-following examples that were generated by prompting text-only GPT-4 with captions and bounding boxes (conversations, detailed descriptions, complex reasoning), i.e. Instruction tuning for vision. LLaVA-1.5[4] swapped in a 2-layer MLP connector, 336 px images (576 visual tokens) and academic VQA data, reaching state-of-the-art results with a training run of about a day on a single 8-GPU node.

Loading interactive…
Walk through how an image and a question become one token sequence, then the two training stages at the bottom. Notice how little is new: a frozen CLIP encoder, an ordinary LLM, and only a small projection in between that turns patch features into 'words'.
ModelConnectorVisual tokens per imageWhat is trainedSignature strength
FlamingoPerceiver Resampler + gated cross-attention in the LM64Resampler + new cross-attn layers (LM and vision frozen)Few-shot, interleaved images/video
BLIP-2Q-Former (32 learned queries)32Q-Former + projection onlyVery parameter-efficient
LLaVA / LLaVA-1.5Linear / 2-layer MLP projection256 / 576Projection, then projection + LLMSimple, strong chat ability, easy to reproduce

GPT-4V-style systems. Commercial models (GPT-4 with vision, Gemini, Claude) accept images natively, but their architectures and training data are not published, so treat claims about their internals with caution. Publicly known trends: much higher and dynamic image resolution (splitting large images into tiles, as in LLaVA-NeXT's 'AnyRes'), large-scale interleaved and OCR-heavy data, video as sequences of frames, and some 'natively multimodal' models trained on mixed modalities from the start rather than glued together afterwards.

knobImage resolution / visual token count
What it is
How many visual tokens each image becomes (set by input resolution, patch size, tiling and any compression in the connector).
↑ If you increase it
Better OCR, small objects, charts and documents; but more tokens fill the Context window, slow down prefill and raise cost (LLaVA-1.5: 576 tokens per image; tiled high-res modes can use thousands).
↓ If you decrease it
Faster and cheaper, more images fit in the context; fine text becomes unreadable and the model may hallucinate details it cannot see.
Typical values
224–336 px (256–576 tokens) for single-image VLMs; dynamic tiling up to ~1–4 MP for document-focused models.
knobNumber of learned queries
What it is
In Q-Former / Perceiver-Resampler connectors: the fixed number of output tokens that summarize the image.
↑ If you increase it
More visual detail reaches the LLM; higher cost per image. Gains flatten once the queries can represent what the task needs.
↓ If you decrease it
A tighter bottleneck: cheap, good for many images or long videos, but fine-grained information (text, counts, positions) is lost.
Typical values
32 (BLIP-2), 64 (Flamingo).
knobtemperature / do_sample
What it is
The usual LLM decoding settings, applied to the VLM's text output.
↑ If you increase it
More varied, creative captions, but also more invented objects and details (visual hallucination).
↓ If you decrease it
Greedy or low temperature gives more factual, repeatable descriptions; preferred for OCR, extraction and evaluation.
Typical values
do_sample=False (greedy) or temperature 0–0.2 for factual tasks; 0.7 for creative captions.
python
import torch
from PIL import Image
from transformers import AutoProcessor, LlavaForConditionalGeneration

model_id = "llava-hf/llava-1.5-7b-hf"
model = LlavaForConditionalGeneration.from_pretrained(
    model_id, torch_dtype=torch.float16, device_map="auto"
)
processor = AutoProcessor.from_pretrained(model_id)

conversation = [
    {"role": "user", "content": [
        {"type": "image"},
        {"type": "text", "text": "What is written on the sign, and what is unusual here?"},
    ]},
]
prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
image = Image.open("street.jpg")
inputs = processor(images=image, text=prompt, return_tensors="pt").to(model.device, torch.float16)

out = model.generate(**inputs, max_new_tokens=120, do_sample=False)  # greedy: factual
print(processor.decode(out[0], skip_special_tokens=True))
Asking LLaVA-1.5 about an image with Hugging Face transformers.
!
Failure modes to expect
Object [[hallucination]]: VLMs confidently mention objects that are not there, often ones that usually co-occur (a 'fork' next to a plate). Language prior over vision: the LLM answers from common sense rather than the pixels (asked about an unusual image, it describes the usual case). Counting and spatial reasoning are weak, inherited from CLIP-style encoders. Low resolution hides small text. Prompt injection via images: text inside an image can carry instructions; never let a VLM agent act on image text without safeguards.
▸Go deeper: why freeze, and what the stages buy you
  • Freezing the LLM protects its language ability and knowledge (no catastrophic forgetting) and makes training cheap; unfreezing it in a later stage (LLaVA) improves instruction following at higher cost.
  • Alignment stage: with only the connector trainable, caption data teaches it to map visual features to things the LLM can name.
  • Instruction stage: diverse question–answer data teaches the model to follow requests about images instead of just captioning them.
  • Alignment with preferences (RLHF/DPO on visual data) is increasingly used to reduce hallucination.

CLIP[5] is the reason this works at all: its image features are already aligned with language, so a small projection is enough to make them 'readable' to an LLM. The transformers LLaVA docs[6] cover prompt formats, batching and newer LLaVA variants.

Quiz

1.
What is the role of the connector in a VLM such as LLaVA?
2.
Why are Flamingo's new cross-attention layers gated with tanh(α) where α starts at 0?
3.
Your VLM cannot read the small print on a receipt photo. Which change is most likely to help?
4.
Where did LLaVA's 158K visual instruction-following examples come from?
5.
A VLM describes 'a fork and knife' next to a plate in a photo that contains only the plate. What is this called?
Score: 0/5

References

  1. [1]
    Flamingo: a Visual Language Model for Few-Shot Learning
    PaperAlayrac et al.2022arxiv.org
  2. [2]
    BLIP-2: Bootstrapping Language-Image Pre-training with Frozen Image Encoders and Large Language Models
    PaperLi et al.2023arxiv.org
  3. [3]
    Visual Instruction Tuning (LLaVA)
    PaperLiu et al.2023arxiv.org
  4. [4]
    Improved Baselines with Visual Instruction Tuning (LLaVA-1.5)
    PaperLiu et al.2023arxiv.org
  5. [5]
    Learning Transferable Visual Models From Natural Language Supervision (CLIP)
    PaperRadford et al.2021arxiv.org
  6. [6]
    LLaVA — Transformers documentation
    DocsHugging Facehuggingface.co
← Previous
Vision Transformers and CLIP
Next →
Video Generation