Multimodal Models — CLIP, LLaVA, and Vision-Language
Models that see and understand images and text together. CLIP for zero-shot image classification, LLaVA for visual question answering.
Every model in this track so far processes one modality — text or images. Multimodal models process both simultaneously and reason about how they relate to each other.
A vision model can tell you "this image contains a leather jacket." A language model can tell you "leather jackets are a classic American wardrobe staple." Neither can answer: "does this product photo match this description — A brown leather bomber jacket with a shearling collar?" That requires understanding both modalities and the relationship between them. Multimodal models do exactly this.
The two dominant approaches: CLIP (Contrastive Language-Image Pre-training, OpenAI 2021) learns a shared embedding space where semantically similar images and text are close together. It enables zero-shot image classification with any text labels — no training on those labels required. LLaVA (Large Language and Vision Assistant) connects a vision encoder to an LLM, enabling open-ended conversations about images. Ask it any question about any image and it generates a natural language answer.
Real production uses: Shopify uses CLIP-based retrieval to match user search queries to product images without pre-defined categories. Amazon uses multimodal models to verify that product photos match product descriptions. DoorDash uses them to check that restaurant dish photos match their menu descriptions. Every e-commerce platform now has multimodal search — text query → image results, or image query → similar products.
Think of a bilingual dictionary — it maps words from English to Spanish and back. CLIP is a bilingual dictionary between visual language and text language. Show it an image of a leather jacket and it gives you a vector. Show it the text "classic leather bomber jacket" and it gives you a similar vector. They are translations of the same concept into a shared numeric language. Similarity in this shared space means semantic similarity across modalities.
The critical insight: CLIP was trained on 400 million (image, text) pairs from the internet. It never needed explicit labels. The training signal came purely from the natural language captions that humans wrote alongside images. This is the largest self-supervised multimodal dataset ever assembled.
CLIP — contrastive pretraining in a shared embedding space
CLIP has two encoders: an image encoder (Vision Transformer or ResNet) and a text encoder (Transformer). Both encoders project their inputs into the same 512 or 768 dimensional embedding space. Training uses contrastive loss: for a batch of N (image, text) pairs, the N correct pairs should be close in embedding space and the N² − N incorrect pairs should be far apart. After training, any image and any text can be compared by cosine similarity of their embeddings.
What you can build with CLIP — zero-shot, retrieval, and embeddings
LLaVA — connecting a vision encoder to an LLM for image conversation
CLIP maps images to embeddings but cannot generate text about images — it can only score similarity. LLaVA (Liu et al., 2023) bridges this gap by connecting a visual encoder to a language model. The architecture is three components: a CLIP vision encoder that extracts image patch features, a projection MLP that maps vision features into the LLM's embedding space, and a language model (LLaMA or Mistral) that generates responses conditioned on both image features and text.
Three production patterns — product search, document understanding, and quality control
CLIP vs LLaVA vs GPT-4V vs Gemini Vision — which to use
Image search, zero-shot classification, visual deduplication, embedding index. Cannot generate text.
Document parsing, product description generation, open-ended visual QA, image captioning.
Complex visual reasoning, charts, diagrams, medical images, multi-image comparison.
Long documents with many images, video understanding, cost-effective GPT-4V alternative.
Every common multimodal mistake — explained and fixed
Two-stage retrieval — how multimodal systems actually get built in production
Almost nobody puts a single multimodal model in front of every request. CLIP-style embeddings are cheap — a few milliseconds per image, a fraction of a cent per million comparisons — but they can only score similarity, not reason. LLaVA, GPT-4o Vision, and Gemini Vision can reason about an image in detail, but each call costs real money and multiple seconds of latency. Production systems combine both: a fast embedding model narrows millions of candidates down to a handful, and a slower reasoning model is only invoked on that narrowed set, where its cost is easy to justify.
Pinterest's visual search, Google Lens, and Shopify's product discovery all run this way: a CLIP-family encoder embeds every catalogue image once, offline, into a vector index (usually FAISS or a managed vector database). A user's photo or text query gets embedded at request time and matched against the index in single-digit milliseconds, even across tens of millions of items. Nothing generative touches the hot path — generation is reserved for cases that genuinely need it.
Insurance claims processing is a clean example of where the second stage earns its cost. A claims team photographs thousands of vehicle damage submissions daily. A CLIP-style classifier does the first pass — bumper scratch, cracked windshield, total loss, fraud flag — for a fraction of a cent per image. Only the claims that land in the ambiguous or high-value buckets get escalated to a VLM that writes an actual adjuster-style report: what is damaged, how severely, whether the described accident story matches what the photo shows. Running the expensive model on every submission would be both slower and unnecessary for the ninety percent of clearly routine cases.
Video is the same pattern one level removed. Nobody runs a vision-language model on every frame of a video — that is thousands of expensive calls for a single upload. Instead, systems sample keyframes (one every second, or at scene-cut boundaries), embed each sampled frame with CLIP, and index the video as a bag of frame embeddings. Search and moderation both operate on that lightweight index first; a generative model is only called on the small number of frames that actually need a written description or a policy decision.
Five things people get wrong about multimodal models
Simply feeding image captions into an LLM's text input is not what CLIP or LLaVA do, and it is not what makes a model genuinely multimodal. CLIP trains its image and text encoders jointly, in the same contrastive objective, so both learn to land in a shared geometric space. LLaVA's projection layer is trained specifically so the LLM can attend to visual tokens the same way it attends to text tokens. The defining feature is a shared representation learned end to end for both modalities together, not two independent models stapled at the API boundary with a text description passed between them.
Scale helps, but alignment is an explicit training objective, not a side effect of data volume. CLIP's contrastive loss is specifically engineered to pull matching pairs together and push non-matching pairs apart across the whole batch — without that objective, an image encoder and a text encoder trained separately would produce vector spaces that are not comparable at all, even on billions of examples. Getting alignment right also depends on caption quality (noisy web alt-text weakens it measurably), batch size (more negatives per batch produces a harder, more informative training signal), and temperature tuning. None of that is automatic.
In practice, CLIP-style embeddings show a measurable 'modality gap' — image embeddings and text embeddings cluster in separate regions of the shared space rather than fully overlapping, even for well-matched pairs. Cosine similarity across modalities still works because relative distances are preserved, but treating the space as if an image and its perfect caption should land at literally the same point is not how these models actually behave. This is measurable, has been studied directly, and matters in practice: pooling image and text embeddings together naively (for example averaging them into a single index) tends to underperform keeping the comparison directional.
Fluent, accurate-sounding descriptions and genuine understanding are not the same capability, and VLMs reliably demonstrate the gap. The hallucination failure mode documented earlier in this module — confidently describing details that are not in the image at all — happens precisely because the language model component is doing what language models do: generating plausible next tokens conditioned on the visual features it was given, not verifying claims against ground truth. A model can nail the general gist of a photo while inventing a specific brand name, a count of objects, or an exact piece of text that was never actually visible.
For pure retrieval and classification tasks, a well-tuned CLIP embedding index regularly beats routing every request through a large generative VLM — it is faster by roughly three orders of magnitude, costs a small fraction as much, and a similarity score is often literally all the task needs. Reaching for GPT-4o Vision or Gemini Vision on every request regardless of whether the task calls for free-form reasoning is a common and expensive default. The right model choice depends on what the output actually needs to be — a score, a category, or a written explanation — not on which model scores highest on a general benchmark.
Multimodal models — 5 questions interviewers actually ask
There are roughly three families. Dual-encoder fusion, what CLIP does, keeps the two encoders entirely separate and only compares their outputs at the end via a similarity score — cheap, but limited to retrieval and classification, no generation. Cross-attention fusion, used by models like Flamingo, interleaves dedicated cross-attention layers into the language model so text tokens can attend directly to visual features at multiple depths of the network — more expressive, more expensive, and requires custom architecture changes. LLaVA takes a third, much cheaper path: a small trainable projection MLP maps vision features into the same embedding space the LLM already uses for text tokens, then simply concatenates them as if they were additional text tokens — the frozen LLM's existing self-attention does the fusion work it already knows how to do, with almost no new architecture required.
For a batch of N image-text pairs, CLIP computes the cosine similarity between every image and every text embedding, producing an N by N matrix. The N correct pairs sit on the diagonal; everything off the diagonal is a negative. The loss is symmetric cross-entropy applied twice — once treating each image as a classification problem over the N texts (which text matches this image), once treating each text as a classification problem over the N images — and the two are averaged. This works because it never needs explicit class labels, only naturally occurring (image, caption) pairs scraped from the web, and because larger batches supply more negative examples per step, which makes the discrimination task harder and produces a sharper, more useful embedding space.
Images and text carry information at fundamentally different densities and structures. A single photo contains far more raw information than its one-sentence caption captures — the caption is a lossy, human-chosen summary, so the same image could pair correctly with many different valid captions, and the same caption could plausibly match many different images. The model has to learn which parts of that huge visual signal actually correspond to the sparse textual signal, with no direct supervision pointing at which pixels matter. That many-to-many, unequal-information-density relationship is why naive approaches (like just averaging pixel and word embeddings) fail, and why it took a specifically designed contrastive objective at very large scale to make the alignment work well.
First, the text prompts — CLIP was trained on natural image captions, so a bare category word like 'jacket' underperforms a full sentence like 'a photo of a leather jacket on a white background' by a wide margin; prompt ensembling (averaging embeddings across several prompt templates per class) usually helps further. Second, preprocessing — image resizing and normalisation have to match exactly what the model was trained with, or embeddings come out meaningless. Third, whether the domain is even one CLIP saw much of during pretraining — general web images are well covered, but narrow domains like specific fashion catalogues or medical imagery often need fine-tuning on a small labelled set before zero-shot performance becomes reliable.
I would start by asking what the output actually needs to be. If the feature is 'find products that look like this photo' or 'search products by description,' that is retrieval — a CLIP embedding index against a vector database gives millisecond latency at a tiny fraction of the cost, and a generative model would add nothing but latency. If the feature needs to produce a written explanation — 'why did you flag this listing,' 'what is wrong with this product photo' — that requires actual generation, which means a VLM. In most real systems the answer is both: CLIP handles the high-volume narrowing step, and a VLM is reserved for the much smaller set of cases that need a generated explanation, which keeps the expensive model's cost bounded and justified.
You can build with multimodal models. Next: production RAG systems that go beyond the basics.
You now understand the full generative AI landscape — GANs, VAEs, diffusion models, LLMs, fine-tuning, and multimodal models. Module 67 returns to RAG with production techniques: reranking retrieved chunks for better precision, hybrid dense-sparse search that combines semantic and keyword retrieval, and evaluation frameworks that measure RAG quality systematically. These are the techniques that separate toy RAG demos from production systems that customers actually trust.
Reranking retrieved chunks, hybrid dense-sparse search, and the patterns that separate production RAG from toy RAG.
🎯 Key Takeaways
- ✓CLIP trains two encoders — image (ViT) and text (Transformer) — to produce embeddings in a shared 512/768-dim space using contrastive loss on 400M (image, text) pairs. After training, cosine similarity between any image and text embedding measures their semantic relatedness. No task-specific training required — this is what enables zero-shot classification.
- ✓CLIP contrastive (InfoNCE) loss: for a batch of N pairs, maximise similarity for the N correct (image, text) pairs and minimise similarity for the N²−N incorrect pairs. The loss is symmetric cross-entropy along both rows (image→text) and columns (text→image) of the N×N similarity matrix. Larger batches = more negatives = stronger learning signal.
- ✓Always write descriptive text labels for CLIP, not just category names: "a photo of a red leather jacket" outperforms "jacket" significantly. Always L2-normalise embeddings before computing cosine similarity. Use ViT-L/14 over ViT-B/32 for better fine-grained product representations.
- ✓LLaVA connects a CLIP vision encoder → 2-layer projection MLP → LLM backbone. The projection MLP is the only new component — it maps 256 patch tokens from CLIP (1024-dim) into the LLM embedding space (4096-dim). The LLM then generates text attending to both visual tokens and text tokens simultaneously.
- ✓Production decision: CLIP for high-volume retrieval and classification (5ms, free, self-hosted), LLaVA-7B for text generation about images (1-5s, free, needs GPU), GPT-4o Vision for complex reasoning (3-10s, $0.01-0.03/image), Gemini Flash for cost-effective high-quality VQA. Never use a generative VQA model for pure retrieval — embeddings are orders of magnitude faster.
- ✓Three key production patterns: multimodal search (CLIP embeddings + FAISS index, text or image queries against indexed product catalogue), document understanding (LLaVA extracts structured data from receipts, invoices, screenshots without OCR), quality control (CLIP zero-shot scores photos against quality criteria descriptions — no labelled examples needed).
Discussion
0Have a better approach? Found something outdated? Share it — your knowledge helps everyone learning here.