Vision Transformers & CLIP
Q: How do transformers handle images? How does CLIP enable zero-shot classification?
- ViT: split the image into 16×16 patches, linearly embed each, add position embeddings and a [CLS] token, run a standard transformer encoder. Less inductive bias than CNNs → needs large data (or strong augmentation/distillation: DeiT); scales very well. Variants: Swin (windowed attention, hierarchical), MAE pretraining (mask 75% of patches, reconstruct).
- CLIP: an image encoder and a text encoder trained contrastively on hundreds of millions of image–caption pairs (InfoNCE over the batch: matching pairs on the diagonal).
- Zero-shot classification: embed prompts like "a photo of a {class}", embed the image, pick the most similar text — no task-specific training. Also powers image search, text-to-image conditioning and the vision side of many multimodal LLMs (SigLIP uses a sigmoid loss instead of softmax).
- Limitations: biases from web data, weak at counting/spatial relations, prompt sensitivity (prompt ensembles help).