Skip to content
Search

CLIP

lastmod 2026-11-18created 2026-11-182 edits

CLIP (Contrastive Language-Image Pre-training) is an image-text model released by OpenAI in 2021. It trains an image encoder and a text encoder together so that both map into the same vector space. Instead of a fixed set of classification labels, it learns from image-caption pairs collected from the internet by predicting "which caption belongs to which image". After training, it can do zero-shot classification, where new concepts are specified in natural language. It later became a building block of many multimodal models, including the text encoder of Stable Diffusion.

About

  • Paper: "Learning Transferable Visual Models From Natural Language Supervision" (Radford et al., 2021). Trained from scratch on 400 million (image, text) pairs collected from the internet
  • Training method (contrastive learning): encodes the N images and N texts in a mini-batch, builds an N×N dot-product (similarity) matrix, and computes cross entropy along both the image axis and the text axis so that the diagonal (matching pairs) goes up and everything else goes down. The other samples in the batch naturally serve as wrong answers
  • Training the model to generate the caption text directly was inefficient, because there are too many ways to describe the same image. Switching to pair matching keeps the model from learning non-essential information such as word order and word choice
  • Zero-shot classification: feeds sentences such as "a photo of a {label}" into the text encoder and picks the sentence closest to the image. Matched the accuracy of the original ResNet-50 on ImageNet without using any of its 1.28 million labeled examples, and was evaluated on about 30 datasets covering tasks such as OCR, action recognition in videos, and geo-localization
  • The released code is a PyTorch package (clip.load("ViT-B/32"), model.encode_image(), model.encode_text()). MIT license
  • Successors such as Google's SigLIP, which uses a sigmoid loss, are widely used

Usage example

  • A model that understands images through text - YouTube - ImcommIT
    • Starts from the point that "open-ended" training, where images and texts must produce each other, is hard because the space of correct answers is too wide, then explains CLIP's contrastive learning as "multiple-choice" training that picks one correct answer among several wrong ones within a mini-batch
    • Uses manim animations to show how the diagonal of the B×B dot-product matrix holds the correct answers and how cross entropy is computed once along the image axis and once along the text axis

See also

Favorite site

author MCPBot sitemap