The Complete
Study Guide
23 chapters. Every topic from encoders to LLaVA. Ordered to maximize learning — each chapter builds on the previous ones. Use the sidebar to jump around.
Optimal Learning Order — Why This Sequence?
- Encoders & Decoders — the raw building blocks everything else uses
- Autoencoders (all variants) — encoders + decoders with a learning objective
- Attention Mechanism — one powerful idea you need before transformers
- Transformer Architecture — built entirely on attention
- Vision Transformer (ViT) — transformers applied to images
- GANs & Modern GAN Works — separate generative paradigm
- Transfer Learning & Fine-tuning — reusing learned models
- Knowledge Distillation & Transfer — compressing and moving knowledge
- Domain Adaptation — when distributions shift
- Active Learning & Semi-supervised AL — when labels are scarce
- Large Foundation Models — the big picture
- LLMs, LVMs, CLIP, BLIP — specific large model types
- LLaVA — ties vision + language together, capstone topic
Encoders Foundation
1.1 What Is an Encoder?
An encoder takes raw input — an image, a sentence, a signal — and turns it into a smaller, compressed form that still carries the important information. Think of it like summarizing a 300-page book into 3 paragraphs. You lose some detail, but the core meaning stays.
The compressed form is called a latent representation (or embedding). It lives in a space called latent space. Latent space is lower-dimensional, meaning it has fewer numbers but packs in more meaning per number.
1.2 How Encoders Work
An encoder is typically a neural network — layers of matrix multiplications followed by activation functions (like ReLU). Each layer transforms the data a bit more, gradually compressing and abstracting it.
1.3 Types of Encoders
- What is latent space and why is its lower dimensionality useful?
- What is the difference between a deterministic and a stochastic encoder?
- Name two types of layers commonly used in image encoders.
Decoders Foundation
2.1 What Is a Decoder?
A decoder is the reverse of an encoder. It takes a compressed latent representation and reconstructs an output — either the original input, or something generated in the same format.
Decoder: z → x̂ (reconstruct)
The output does not have to be exactly the original input. In generative models, the decoder generates new things from new latent vectors never seen during training. This is how we generate new images or text.
2.2 How Decoders Work
Decoders mirror encoders in structure but do the reverse operation.
2.3 Encoder-Only vs Decoder-Only vs Encoder-Decoder
This distinction is critical for understanding modern architectures.
| Architecture | Examples | Good For |
|---|---|---|
| Encoder-only | BERT, ViT, CLIP image encoder | Classification, understanding, retrieval |
| Decoder-only | GPT, LLaMA, Mistral | Text generation, completion |
| Encoder-Decoder | T5, BART, original Transformer | Translation, summarization, seq2seq tasks |
Autoencoders Foundation
3.1 The Core Idea
An autoencoder (AE) is a neural network trained to take an input, compress it into a small latent vector, and then reconstruct the original input from that vector — as accurately as possible.
Decoder: x̂ = g(z)
Loss: minimize ||x − x̂||²
The bottleneck forces the network to learn what is actually important in the data. If you compress a 784-dimensional image into a 32-dimensional vector, the network has no choice but to learn the essential structure.
3.2 Architecture
Input x (784-dim)
↓
[Encoder Layer 1: 784 → 256] ReLU
↓
[Encoder Layer 2: 256 → 128] ReLU
↓
[Bottleneck: 128 → 32] ← Latent code z
↓
[Decoder Layer 1: 32 → 128] ReLU
↓
[Decoder Layer 2: 128 → 256] ReLU
↓
[Output Layer: 256 → 784] Sigmoid
3.3 Applications
3.4 The Problem with Vanilla AEs — Motivating the Variants
This is exactly why we need the variants: Denoising AE, Stacked AE, Contractive AE, and Variational AE (VAE).
Denoising Autoencoders Foundation
4.1 The Main Idea
A Denoising Autoencoder (DAE) deliberately corrupts the input before feeding it to the encoder — then trains the network to recover the clean original. The training signal says: "here is noisy data, now reconstruct the clean version."
Take clean input x
Add noise → x̃ (corrupted version)
Feed x̃ to the encoder → latent z
Decode z → reconstruction x̂
Loss: minimize ||x − x̂||² (compare to the clean original, not the noisy one)
4.2 Types of Noise
4.3 Why This Works Better
By forcing the encoder to see corrupted inputs and still reconstruct clean outputs, you push it to learn the underlying data manifold — the smooth surface in high-dimensional space where real data lives. Noise pushes data off the manifold; the network learns to project it back.
- What is the key difference between a vanilla AE's loss and a DAE's loss?
- Why does noisy training produce a smoother latent space?
- What is a data manifold?
Stacked Autoencoders Foundation
5.1 The Idea
A stacked autoencoder is multiple autoencoders layered on top of each other. The compressed output of one AE becomes the input to the next. The motivation is greedy layer-wise pretraining — a technique from 2006 that made it possible to train deep networks before modern tricks like batch normalization existed.
5.2 Training Procedure
Phase 1: Layer-wise Pretraining
Train AE₁ on raw input x → get encoder₁
Pass x through encoder₁ → get z₁ (compressed)
Train AE₂ on z₁ → get encoder₂
Continue for as many layers as desired
Phase 2: Fine-tuning (Unrolling)
Stack all encoders and all decoders (in reverse). Train the whole network end-to-end with a small learning rate to refine everything together.
5.3 Why Layer-wise Pretraining Helps
The concept lives on in modern deep pretraining — BERT pretraining, LLM pretraining, MAE — all train hierarchically in some sense.
Contractive Autoencoders Foundation
6.1 Motivation
The contractive AE (CAE) addresses a specific problem: a vanilla AE's encoder is sensitive to small changes in input. If you perturb x slightly, the latent code z might change wildly. We want the opposite — a stable encoder that ignores small, irrelevant variations.
6.2 The Contractive Penalty
Where J_f(x) is the Jacobian matrix of the encoder — it measures how much each output of the encoder changes when each input dimension changes. ||·||²_F is the Frobenius norm (sum of squared entries).
Minimizing the Frobenius norm pushes the encoder to be insensitive to small input changes. This is the "contractive" property.
6.3 CAE vs DAE Comparison
| Property | DAE | CAE |
|---|---|---|
| How robustness is enforced | Corrupted input at training time | Analytic penalty on encoder Jacobian |
| What is penalized | Sensitivity (implicitly) | Sensitivity (explicitly, via gradient) |
| Computational cost | Lower | Higher (computing Jacobian is expensive) |
| Latent space quality | Smooth manifold structure | Smooth, insensitive to perturbations |
6.4 Missing Variant: Variational Autoencoder (VAE)
= Reconstruction term − KL regularization
Attention Mechanism Architecture
7.1 The Problem Attention Solves
Before attention, sequence models (RNNs) processed sequences step by step and had to compress the entire history into a fixed-size vector. Long sequences were a disaster — by the time you got to the end, the beginning was mostly forgotten.
Attention solves this by letting every position in the output look directly at any position in the input. No compression. No forgetting.
7.2 Query–Key–Value Framework
Think of attention like a database lookup:
The division by √d_k prevents dot products from growing too large (which would push softmax into flat saturation regions, killing gradients).
7.3 Step-by-Step Walkthrough
Sentence: "The cat sat on the mat." We want the representation of "sat" that incorporates context.
"sat" becomes a Query vector q
Every word becomes a Key vector k_i
Compute dot products: q·k_i for each word, then divide by √d_k
Apply softmax → get attention weights (sum to 1)
Multiply each word's Value vector v_i by its attention weight
Sum weighted Values → contextual representation of "sat"
7.4 Self-Attention vs Cross-Attention
Self-Attention
- Q, K, V all come from the same sequence
- Each position attends to every other position
- Used in transformer encoders (BERT)
- Used in decoder-only models (GPT)
Cross-Attention
- Q from one sequence, K and V from another
- Decoder queries look into encoder output
- Used in encoder-decoder transformers
- Used in multi-modal models (image → text)
7.5 Multi-Head Attention
Instead of one attention function, compute h parallel attention functions with different learned projections:
MultiHead(Q, K, V) = Concat(head₁, ..., headₕ) × W_O head_i = Attention(Q·W_Qi, K·W_Ki, V·W_Vi)
Each head can focus on different relationship types: one head might track syntactic dependencies, another semantic similarity, another positional patterns. Richer than single-head attention.
7.6 Positional Encoding
Attention has no notion of order — it treats input as a set, not a sequence. Positional encodings are added to input embeddings to inject order information.
- Why do we divide by √d_k in the attention formula?
- What is the difference between self-attention and cross-attention?
- Why do we need positional encodings in attention?
- What does each "head" in multi-head attention potentially specialize in?
Transformer Architecture Architecture
8.1 The Big Picture
The Transformer (Vaswani et al., "Attention Is All You Need," 2017) replaced recurrent networks for sequence-to-sequence tasks. It is built entirely on attention — no RNNs, no convolutions in the core architecture. The key insight: attention can replace sequential processing with parallel processing.
8.2 Full Architecture
INPUT TOKENS
↓
Token Embedding + Positional Encoding
↓
┌─────────────────────────────┐
│ ENCODER BLOCK (×N layers) │
│ ┌───────────────────────┐ │
│ │ Multi-Head Self-Attn │ │
│ └──────────┬────────────┘ │
│ + residual connection │
│ Layer Normalization │
│ ┌───────────────────────┐ │
│ │ Feed-Forward Network │ │
│ └──────────┬────────────┘ │
│ + residual connection │
│ Layer Normalization │
└─────────────────────────────┘
↓ Encoder Output (context)
┌─────────────────────────────┐
│ DECODER BLOCK (×N layers) │
│ ┌───────────────────────┐ │
│ │ Masked Self-Attention │ │ ← Causal: can't see future
│ └──────────┬────────────┘ │
│ + residual + LayerNorm │
│ ┌───────────────────────┐ │
│ │ Cross-Attention │ │ ← Attends to encoder output
│ └──────────┬────────────┘ │
│ + residual + LayerNorm │
│ ┌───────────────────────┐ │
│ │ Feed-Forward Network │ │
│ └──────────┬────────────┘ │
│ + residual + LayerNorm │
└─────────────────────────────┘
↓
Linear + Softmax → token probabilities
8.3 Key Components
output = sublayer(x) + x. Prevents vanishing gradients in deep stacks.FFN(x) = max(0, xW₁+b₁)W₂+b₂. Expands to 4× the model dimension, then contracts. Stores a lot of factual knowledge.8.4 Computational Complexity
Self-attention is O(n²d) in time and O(n²) in memory, where n is sequence length. This quadratic scaling is the main bottleneck for long sequences.
Vision Transformer (ViT) Architecture
9.1 The Core Idea
ViT (Dosovitskiy et al., 2020) asked a simple question: what if we just split an image into patches and treat them like a sequence of tokens, then apply a standard transformer? Turns out — it works extremely well, especially at scale.
9.2 Step-by-Step Architecture
Patch Embedding: Split 224×224 image into 16×16 patches → 196 patches. Each patch (16×16×3 = 768 values) is flattened and linearly projected to dimension d.
Class Token [CLS]: A special learnable token prepended to the sequence. Its final representation is used for classification. (Borrowed from BERT.)
Position Embeddings: Learned 1D position embeddings added to each patch embedding. The model learns which positions are where.
Transformer Encoder: L layers of multi-head self-attention + FFN. Each patch attends to every other patch. No convolutions.
Classification Head: Take the final [CLS] token → small MLP → class probabilities.
9.3 ViT vs CNN
| Property | CNN | ViT |
|---|---|---|
| Inductive bias | Strong (locality, translation equivariance baked in) | Weak (must learn from data) |
| Data efficiency | High — works with small datasets | Lower — needs more data to learn what CNNs assume |
| Scalability | Good | Excellent — scales very well with data and compute |
| Long-range dependencies | Hard (limited receptive field) | Easy — global attention from the first layer |
9.4 Important ViT Variants
- A 224×224 image with 16×16 patches produces how many patches?
- What is the [CLS] token and why is it useful?
- Why does ViT need more data than a CNN to perform well?
- What does MAE do and how is it related to denoising autoencoders?
Generative Adversarial Networks Generative
10.1 The Core Idea — A Two-Player Game
A GAN (Goodfellow et al., 2014) consists of two networks trained in opposition:
10.2 Training Loop
For each training step:
1. Sample batch of real data {x₁, ..., xₘ}
2. Sample batch of noise {z₁, ..., zₘ}
3. Generate fakes: {G(z₁), ..., G(zₘ)}
Update Discriminator:
Real samples → D should output 1
Fake samples → D should output 0
Minimize: −[log D(x) + log(1 − D(G(z)))]
Update Generator:
Want D(G(z)) ≈ 1 (fool D)
Minimize: −log D(G(z)) ← non-saturating loss
10.3 Why the Non-Saturating Loss?
The original G loss was log(1 − D(G(z))). Early in training, D can easily spot fakes (since G is terrible), so D(G(z)) ≈ 0 and the gradient ≈ 0 — G cannot learn.
The fix: use −log D(G(z)). When D(G(z)) ≈ 0, this loss is large, giving G a strong gradient to improve.
10.4 Common GAN Problems
10.5 Evaluation Metrics
Modern GAN Works Generative
11.1 DCGAN (2015)
The first practically successful image GAN. Key contributions: transposed convolutions in G, strided convolutions in D (no pooling), batch normalization, LeakyReLU in D. This architecture guideline became the universal GAN starting point.
11.2 Conditional GAN (cGAN, 2014)
Feed a class label (or other conditioning) to both G and D. G(z, y) → image conditioned on label y. Lets you control what the generator produces — ask for a "7" and get a 7.
11.3 Pix2Pix (2017)
Conditional GAN for paired image-to-image translation. Given (input image, target image) pairs, learn to translate between domains: sketch→photo, day→night, satellite→map. Loss = adversarial loss + L1 pixel-level reconstruction loss.
11.4 CycleGAN (2017)
Unpaired image-to-image translation. No need for matched pairs — just two sets of images (horses and zebras). Uses two generators and two discriminators, plus a cycle consistency loss: translating A→B→A should recover A.
11.5 StyleGAN (2019) / StyleGAN2 (2020)
Radical generator architecture redesign. Key ideas:
StyleGAN2 fixes blob artifacts from AdaIN. Powers "This Person Does Not Exist."
11.6 WGAN (Wasserstein GAN, 2017)
Addresses GAN instability theoretically. Replaces Jensen-Shannon divergence (implicit in standard GAN) with Wasserstein distance — a more stable training signal.
11.7 Progressive Growing (ProGAN, 2018)
Start generating 4×4 images, gradually increase to 8×8, 16×16, ... 1024×1024. Add new layers with smooth blending transitions. Makes training stable because the task starts easy (4×4) and the model builds on what it has already learned.
Transfer Learning Adaptation
12.1 What Is Transfer Learning?
Transfer learning uses knowledge gained from solving one problem to help solve a different (but related) problem. The core empirical observation: neural networks trained on one task learn feature representations that are useful for many other tasks.
12.2 Why It Matters
Training large models from scratch requires millions of labeled examples, weeks of GPU time, and enormous cost. Transfer learning lets practitioners start from a powerful pretrained model and adapt it with a small dataset in hours.
12.3 When to Use Which Strategy
| Dataset Size | Similarity to Pretraining Data | Recommended Strategy |
|---|---|---|
| Small | High | Feature extraction only (freeze all pretrained weights) |
| Small | Low | Feature extraction (risky) or few-shot methods |
| Large | High | Fine-tune all layers |
| Large | Low | Fine-tune all layers or train from scratch |
12.4 Negative Transfer
Fine-Tuning Adaptation
13.1 What Is Fine-Tuning?
Fine-tuning means taking a pretrained model and continuing training it on a new (typically smaller) dataset, adjusting weights to fit the new task. Unlike feature extraction (frozen backbone), fine-tuning lets the internal representations shift.
13.2 Standard Procedure
Load pretrained model weights
Replace the final classification head with a new one (random init) matching the new task's number of classes
Choose a small learning rate — usually 10–100× smaller than original training LR
Optionally freeze early layers initially, then unfreeze gradually ("unfreezing schedule")
Train on new dataset; monitor validation loss for overfitting
13.3 Parameter-Efficient Fine-Tuning (PEFT)
Modern LLMs have billions of parameters — full fine-tuning is expensive and risks overfitting. PEFT methods update only a small fraction of parameters:
where rank r ≪ min(d, k)
Parameters trained: d×r + r×k instead of d×k
13.4 Catastrophic Forgetting
When you fine-tune on a new task, the network can "forget" what it learned before. New gradient updates overwrite old knowledge. Mitigation: small LR, replay (mix old + new data), EWC (Elastic Weight Consolidation), or PEFT methods (frozen backbone prevents forgetting).
Knowledge Distillation Adaptation
14.1 The Core Idea
Knowledge distillation (Hinton et al., 2015) transfers knowledge from a large, accurate model (the teacher) into a smaller, faster model (the student). The student learns from the teacher's soft output probabilities, not just hard labels.
14.2 Why Soft Labels Carry More Information
A hard label says: "this image is a cat." That is all. The teacher's output probabilities say: "95% cat, 4% dog, 1% tiger." These soft labels reveal which classes are similar — a dog is more like a cat than a car is. This extra signal helps the student learn better representations.
14.3 Distillation Loss
+ (1−α) × L_KL(softmax(student/T) || softmax(teacher/T))
Where T is temperature — higher T makes soft labels softer (less peaked), making the small probabilities more readable and useful for the student.
14.4 Variants of Distillation
14.5 Real-World Applications
Knowledge Transfer Adaptation
15.1 Broader Than Distillation
Knowledge distillation is one specific method of knowledge transfer. Knowledge transfer is the broader idea — any method by which knowledge learned in one setting is made useful in another. This includes: transfer learning, fine-tuning, distillation, multi-task learning, zero-shot transfer, and few-shot transfer.
15.2 Zero-Shot Transfer
The model is tested on a task it was never explicitly trained on. Works when the model has learned sufficiently general representations. CLIP is the canonical example — trained to align image and text, it can classify images into any category by comparing image embeddings to text embeddings of class names. No task-specific training needed.
15.3 Few-Shot Transfer
The model sees only K examples (K = 1, 5, or 10) of the new task and must generalize. This is the goal of meta-learning — training models to be good at learning quickly.
Domain Adaptation Adaptation
16.1 The Problem
You train a model on data from one distribution (source domain) and deploy it on data from a different distribution (target domain). Performance degrades — sometimes catastrophically. Example: train on California sunshine photos, deploy in winter fog in Germany.
16.2 Types of Distribution Shift
16.3 Key Methods
- What is covariate shift and why does it degrade model performance?
- How does DANN use an adversarial objective — and how is it similar to GANs?
- What is unsupervised domain adaptation and why is it the hardest variant?
Active Learning Adaptation
17.1 The Setting
You have a large pool of unlabeled data. Labeling is expensive (requires human annotators). You have a limited labeling budget. The question: which examples should you label to maximize model performance?
17.2 The Active Learning Loop
1. Start with small labeled set L, large unlabeled pool U 2. Train model on L 3. Score each unlabeled example using an acquisition function 4. Select top-K highest scoring examples from U 5. Have humans label those K examples 6. Add to L; go to step 2 7. Repeat until labeling budget is exhausted
17.3 Acquisition Functions
17.4 Batch Active Learning
Most real scenarios require selecting a batch of K examples at once. Naive approach: pick top-K by individual score. Problem: they might all be similar (redundant). Better: balance informativeness with diversity.
Semi-Supervised Active Learning Adaptation
18.1 Combining Two Paradigms
Semi-supervised learning (SSL) uses both labeled and unlabeled data to improve the model. Active learning selects which examples to label. Together: use unlabeled data to improve the model, then use the improved model to better choose what to label next. A virtuous cycle.
18.2 Semi-Supervised Learning Methods (Background)
18.3 VAAL (Variational Adversarial Active Learning)
Trains a VAE on all data (labeled + unlabeled). Trains a discriminator to distinguish labeled from unlabeled data in latent space. Query examples the discriminator cannot tell apart from labeled data — regions of latent space not yet covered by labeled examples.
18.4 Why Combine SSL and AL?
Large AI Foundation Models Frontier
19.1 What Is a Foundation Model?
A foundation model is a large model trained on vast amounts of broad data that can be adapted to many downstream tasks. Term coined by Stanford HAI in 2021. Properties: massive scale (billions of parameters), generality (not one task), emergent capabilities (appear at scale), adaptability (fine-tune / prompt for specific applications).
19.2 Pretraining Paradigms
| Paradigm | Method | Used In |
|---|---|---|
| Masked Language Modeling | Mask tokens, predict them | BERT, RoBERTa |
| Causal Language Modeling | Predict next token | GPT, LLaMA, Mistral |
| Contrastive Pretraining | Align representations from different modalities | CLIP, ALIGN |
| Masked Image Modeling | Mask patches, reconstruct them | MAE, BEiT |
| Multi-task Pretraining | Many tasks with different prompts | T5, FLAN, Gemini |
19.3 Emergent Abilities
Certain capabilities appear only above a scale threshold. Below: near-random performance. Above: sudden, dramatic improvement. Examples: few-shot learning (GPT-3+), chain-of-thought reasoning, multi-step arithmetic, instruction following without explicit training. Not fully understood — active research area.
19.4 RLHF — Making Models Behave
Reinforcement Learning from Human Feedback shapes model behavior toward being helpful, honest, and harmless.
Fine-tune LLM with supervised learning on high-quality human demonstrations
Collect human preferences: show pairs of model responses, humans pick which is better
Train a reward model to predict human preferences from these pairs
Use RL (PPO) to optimize the LLM to maximize the reward model's score
Large Language Models (LLMs) Frontier
20.1 Architecture
Modern LLMs are transformer decoder-only models: causal self-attention only, trained to predict the next token autoregressively. No encoder, no cross-attention.
20.2 Scaling Laws
Chinchilla (2022) showed the optimal relationship: train on ~20 tokens per parameter. Many earlier models were over-parameterized and under-trained (too big, too little data). Loss follows power laws with both model size and training data size.
20.3 In-Context Learning
GPT-3 showed that LLMs can perform few-shot learning just from prompt formatting — no gradient updates. Give the model a few examples in the prompt; it infers the task from context and answers. The model is learning from context at inference time, without updating weights.
20.4 Chain-of-Thought Prompting
Adding "Let's think step by step" dramatically improves performance on reasoning tasks. The model generates intermediate reasoning steps before the final answer. The final answer is conditioned on the reasoning chain — externalizing computation that would otherwise need to happen implicitly.
Large Vision Models (LVMs) Frontier
21.1 What Are LVMs?
Large Vision Models are foundation models for visual data — pretrained on massive image datasets, adaptable to many vision tasks. Same philosophy as LLMs: pretrain at scale, adapt as needed.
21.2 Key Models
21.3 Self-Supervised Methods for Vision (Important Background)
Multi-Modal LLMs — CLIP, BLIP & Beyond Frontier
22.1 What Makes a Model Multi-Modal?
A multi-modal model processes data from multiple modalities simultaneously — text, images, audio, video. The challenge is learning a joint representation space where different modalities can communicate with each other meaningfully.
22.2 CLIP (OpenAI, 2021)
Trained on 400 million (image, text) pairs from the internet. Learns to align image and text embeddings in a shared space.
22.3 BLIP (2022)
Addresses CLIP's weakness: noisy web training data. BLIP bootstraps cleaner training data.
22.4 BLIP-2 (2023)
Freeze a pretrained image encoder AND a pretrained LLM. Bridge them with a lightweight Q-Former — 32 learnable query tokens that attend to image features. Only the Q-Former is trained. Extremely parameter-efficient.
Frozen Image Encoder → Q-Former → Frozen LLM
↑
32 learnable query tokens
22.5 Flamingo (DeepMind, 2022)
Connects a frozen vision encoder to a frozen LLM using cross-attention layers inserted between LLM layers. Trained on interleaved image-text sequences. Enables few-shot visual question answering — give a few (image, question, answer) examples, then ask about a new image.
22.6 ImageBind (Meta, 2023)
Extends CLIP to 6 modalities: image, text, audio, depth, thermal, IMU. Uses images as the binding modality — aligning all modalities to images implicitly aligns them to each other. Enables cross-modal retrieval between modalities that were never directly paired in training (e.g., retrieve audio from text).
- What is contrastive learning and why does it train CLIP effectively?
- How does CLIP perform zero-shot classification without being explicitly trained on classification?
- What problem does BLIP's CapFilt solve?
- What does the Q-Former do in BLIP-2, and why is freezing both encoder and LLM advantageous?
LLaVA Frontier
23.1 What Is LLaVA?
LLaVA (Large Language and Vision Assistant, Liu et al., 2023) connects a CLIP vision encoder to a LLaMA/Vicuna LLM using a simple linear projection layer. Despite its architectural simplicity, it achieves strong performance on visual dialogue and question answering. It democratized multi-modal LLM research.
23.2 Architecture
Image Input
↓
CLIP Image Encoder (frozen ViT-L/14)
↓ visual features [N × D_clip]
Linear Projection Layer (trainable)
↓ visual tokens [N × D_llm]
↕
LLM (LLaMA / Vicuna) — processes [visual tokens + text tokens] together
↓
Text output (answer to the question)
The visual features are projected into the LLM's embedding space and prepended to the text token sequence. The LLM sees them as "extra tokens" at the start of the sequence.
23.3 Training Data — The Key Innovation
LLaVA's training data was generated using GPT-4. The authors gave GPT-4 image captions and bounding boxes (text descriptions of visual content — not the actual images) and asked it to generate:
Total: 158K samples generated this way. High quality instruction-following data without expensive human annotation.
23.4 Two-Stage Training
Stage 1 — Feature Alignment
- Freeze: CLIP encoder + LLM
- Train: projection layer only
- Data: 595K image-caption pairs (CC-595K)
- Goal: make visual tokens meaningful to LLM
Stage 2 — End-to-End Fine-tuning
- Freeze: CLIP encoder only
- Train: projection layer + LLM
- Data: 158K GPT-4 generated instructions
- Goal: teach visual instruction following
23.5 LLaVA-1.5 and Beyond
23.6 Why LLaVA Matters
Summary Table — All Topics
| Topic | What It Does | Key Idea | Related To |
|---|---|---|---|
| Encoder | Compress input to latent | Learn compact representations | Autoencoders, ViT, CLIP |
| Decoder | Reconstruct from latent | Generate from representation | Autoencoders, Transformers |
| Autoencoder (vanilla) | Reconstruct input via bottleneck | Bottleneck compression | Foundation for all AE variants |
| Denoising AE | Reconstruct from corrupted input | Learn the data manifold | Diffusion models |
| Stacked AE | Hierarchical layer-wise pretraining | Train deep networks layer by layer | Deep pretraining, BERT |
| Contractive AE | Insensitive encoder via Jacobian penalty | Penalize sensitivity explicitly | Robust representations |
| VAE | Generate new data by sampling latent | Probabilistic latent space + KL prior | GANs, BLIP, generative models |
| Attention | Selective, weighted combination of context | Query-Key-Value lookup | Transformers, ViT, CLIP, LLaVA |
| Transformer | Sequence processing via stacked attention | Fully parallel, long-range dependencies | LLMs, ViT, BERT, T5 |
| ViT | Image processing via transformer | Patches as tokens | LVMs, CLIP image encoder, LLaVA |
| GAN | Generate realistic data via adversarial game | Generator vs Discriminator | CycleGAN, StyleGAN, domain adaptation |
| Modern GANs | Better, controllable generation | Stability tricks + architectural innovations | StyleGAN, CycleGAN, WGAN |
| Transfer Learning | Reuse pretrained knowledge | Pretrained features are general | Fine-tuning, distillation |
| Fine-tuning | Adapt pretrained model to new task | Update weights on new task data | LoRA, PEFT, LLaVA Stage 2 |
| Knowledge Distillation | Compress large model into small one | Soft label transfer with temperature | DistilBERT, DeiT, TinyBERT |
| Knowledge Transfer | Move knowledge between settings | Broad paradigm: zero/few-shot, meta-learning | CLIP zero-shot, MAML |
| Domain Adaptation | Handle distribution shift | Learn domain-invariant representations | DANN, CORAL, self-training |
| Active Learning | Label most informative examples | Acquisition function selects queries | Entropy, CoreSet, BADGE |
| Semi-supervised AL | Combine SSL and active learning | Use unlabeled data to improve querying | VAAL, FixMatch, Mean Teacher |
| Foundation Models | Pretrain at scale, adapt anywhere | General + emergent + adaptable | LLMs, LVMs, CLIP, LLaVA |
| LLMs | Language understanding and generation | Decoder-only transformers + scaling | GPT, LLaMA, ChatGPT |
| LVMs | Visual features at scale | Self-supervised ViT pretraining | SAM, DINOv2, CLIP image encoder |
| CLIP | Align image and text in shared space | Contrastive pretraining on 400M pairs | Zero-shot classification, LLaVA, BLIP |
| BLIP / BLIP-2 | Image-text understanding + generation | CapFilt bootstrapping + Q-Former bridge | VQA, captioning, multi-modal |
| LLaVA | Visual dialogue and instruction following | CLIP encoder → linear projection → LLM | Ties everything together |