6.5.4 · D1Research Frontiers & Practice

Foundations — Self-supervised and contrastive learning (SimCLR, CLIP)

2,097 words10 min readBack to topic

This page is the toolbox. The parent note throws around symbols like , , , , , and as if you already own them. Here we earn each one from nothing, in an order where every symbol only uses symbols we already built.


0. The picture that holds everything: the embedding map

Before any symbol, hold this image in your head.

Figure — Self-supervised and contrastive learning (SimCLR, CLIP)

Every image (or sentence) becomes a single dot on a flat map. The whole game is where the dots land. Two crops of the same cat should be neighbours; a cat and a car should be strangers on opposite sides of town. That map is called an embedding space, and each dot is an embedding (also called a representation).

Keep the map in mind — every symbol below is a tool for either placing a dot or measuring the distance between two dots.


1. A vector: the dot's address

To say where a dot is, we need coordinates.

The parent writes . Read that as: " is a vector — a point — that lives in () the space of all lists of 128 real numbers." is just the shorthand name for "all ordinary numbers" (the Reals: , , , ...). The little superscript counts how many coordinates.

Recall What does

mean in plain words? is a point whose address is a list of 128 ordinary numbers.


2. A function: the machine that makes the dot

Something has to turn a photo into that list of numbers. That something is a function.

In the parent there are two such boxes stacked: (the encoder, e.g. a ViT or ResNet) then (the small projection head). Composition just means "run one box, feed its output into the next": .


3. The dot product: measuring alignment

Now we have two dots. We need a number that says how much they point the same way. That is the dot product.

Figure — Self-supervised and contrastive learning (SimCLR, CLIP)

The little (read "transpose") is bookkeeping notation that flips a column list into a row so the multiplication lines up. For our purposes just means "dot product of and ."


4. Length of a vector, and cosine similarity

The raw dot product has a flaw: a longer arrow gives a bigger number even if it points the same way. We only care about direction, not how long the arrow is. So we divide out the lengths.

Figure — Self-supervised and contrastive learning (SimCLR, CLIP)
Recall If two embeddings point in exactly the same direction, what is their cosine similarity?

(the maximum).


5. Exp and log: turning scores into probabilities

We now have a similarity score per pair. To train, we want to phrase things as a probability: "how likely is this the correct match?" Two functions convert scores↔probabilities: and .

Figure — Self-supervised and contrastive learning (SimCLR, CLIP)

6. Sum (), softmax, and temperature

Now stack the tools. Take similarities, run each through , and divide each by the total. Every result is positive and they all add to — that's a probability distribution. This recipe is softmax.

Putting it together, the parent's InfoNCE loss for anchor with positive and negatives is just "negative log of the softmax probability that the positive is the right answer": Read left to right with our toolbox: measure alignment () → sharpen () → make positive () → convert to a share (the fraction) → make it a pain meter (). Nothing mysterious remains.


7. Two more words the parent leans on

These connect outward to Transfer learning and fine-tuning (reuse the learned map), Zero-shot and few-shot learning (CLIP classifies unseen categories), Multi-modal learning (images + text share one map), and Attention mechanisms and transformers (the encoders themselves). Training stability tricks live in Batch normalization and training techniques.


Prerequisite map

Vector = dot address

Dot product = alignment

Length of a vector

Cosine similarity

Function = encoder box

Softmax

Exp makes scores positive

Sum over all options

Temperature tau sharpens

Contrastive InfoNCE loss

Neg log = pain meter

Augmentation makes positive pairs

SimCLR and CLIP


Equipment checklist

Test yourself — answer before revealing.

What is an embedding, in one sentence?
A list of numbers (a point on a map) standing in for a complex object, placed so similar objects land nearby.
What does mean?
The space of all lists of 128 ordinary (real) numbers; a -dimensional map.
What does the dot product tell you?
One number for how much two arrows point the same way — big positive = aligned, zero = perpendicular, negative = opposite.
Why divide the dot product by ?
To cancel out arrow lengths so only direction remains; the result equals , bounded in .
What is the range of cosine similarity?
From (opposite) to (identical direction).
Why apply to similarity scores?
To make them positive and to amplify gaps so the best match dominates in the softmax.
Why does a loss use ?
It is when the probability (perfect) and grows without bound as (a natural pain meter).
What does temperature control?
How sharp the softmax is — small = picky spotlight on the best match, large = forgiving floodlight.
What is a positive pair vs a negative pair?
Positive = two views that should be neighbours (same image, or image + true caption); negative = two that should stay strangers.