AI Model Wiki

    Skip to main content
    Back to Glossary

    Contrastive Learning

    Contrastive learning is a self-supervised training technique in which a model learns representations by being trained to bring similar data points close together in embedding space while pushing dissimilar points apart, without requiring manually annotated class labels for every example. A typical setup creates positive pairs such as two augmented views of the same image or a matching image-caption pair, and negative pairs drawn from other examples in the same batch; the model optimizes a loss function such as InfoNCE that scores positive pairs higher than negatives. This approach produces high-quality general-purpose embeddings that transfer well to downstream tasks even when labeled data is scarce.

    Think of it like learning what things are by comparing them rather than memorizing explicit definitions. A child learns that labrador retrievers and golden retrievers belong in the same mental category not because someone recited their taxonomy, but because they look more like each other than like cats or chairs.

    OpenAI's CLIP model is a widely cited example: trained on 400 million image-text pairs with a contrastive objective, it learns to place the embedding of 'a photo of a dog' near the embeddings of actual dog photos while keeping it far from unrelated images. The trained encoder can then perform zero-shot image classification without task-specific fine-tuning:

    image_features = clip_model.encode_image(image)
    text_features  = clip_model.encode_text(["a dog", "a cat", "a car"])
    probs = (image_features @ text_features.T).softmax(dim=-1)
    

    Contrastive learning is foundational to understanding Embedding quality, Multimodal models like CLIP and ALIGN, Latent Space structure, and Zero-Shot transfer capabilities. It also informs how Fine-tuning and Pretraining interact when adapting a contrastively trained encoder to a new task.

    You will encounter this term in papers on vision-language models, speech representation learning, and recommendation systems that rely on learned similarity functions.

    AI Terminology
    Glossary