4.5.16 · D1Generative Models

Foundations — Text-to-image conditioning (CLIP)

2,353 words11 min readBack to topic

Before you can read the parent note, you need to understand every piece of notation it throws at you. This page walks each symbol from absolute zero: what it means in plain words, what it looks like as a picture, and why CLIP needs it. Read top to bottom — each item leans on the one before.


1. A vector — an arrow with a list of numbers

Everything in CLIP is a vector. Forget the scary word: a vector is just an ordered list of numbers, and geometrically it is an arrow starting at the origin.

Figure — Text-to-image conditioning (CLIP)

In CLIP every image and every sentence becomes such an arrow. Two arrows pointing the same way = "these mean the same thing". Two arrows pointing different ways = "these mean different things". That single geometric idea is the whole engine.


2. — the space the arrows live in

The parent writes . Decode it piece by piece.

  • (blackboard R) means "all the real numbers" — every ordinary number like , , .
  • means "a list of real numbers", i.e. -dimensional space.
  • means "is an element of" / "lives inside".

So reads: "the image arrow is a list of 512 real numbers." We cannot draw 512 dimensions, so throughout we draw 2D or 3D and trust the same rules carry up.


3. The encoders and — the machines that make arrows

The subscripts are labels: I for image, T for text. Both machines are trained so their outputs land in the same , which is the only reason we are allowed to compare them later.

Why two separate machines? Images (grids of pixels) and text (sequences of words) are built completely differently, so each needs its own specialist reader. They rely on ideas from 4.4.7-Attention-mechanisms (how the text encoder reads a sentence) and image networks — but here we only care that each outputs an arrow.


4. The dot product — measuring agreement

To ask "do these two arrows point the same way?" we need one number that measures agreement. That number is the dot product.

Why this tool and not another? We want one number that is large and positive when arrows point the same way, zero when they are perpendicular (unrelated), and negative when they point opposite ways. The dot product does exactly this because it equals — it secretly hides the angle between the arrows.

Figure — Text-to-image conditioning (CLIP)

5. The norm — the length of an arrow

(double bars) means the length of the arrow, found with the Pythagorean theorem:

Picture the longest side of a right triangle whose other sides are the components. We need length because a long arrow and a short arrow can point the same direction — and for meaning we only care about direction, not length.


6. Cosine similarity — direction only

Now we combine the two: divide the dot product by both lengths.

Dividing by the lengths cancels magnitude, leaving pure direction. That is exactly why the parent says "we care about direction (semantic meaning), not magnitude." The superscripts and are just item numbers in a batch — image , text .


7. The subscript grid — the similarity matrix

With pairs in a batch, is the similarity of image to text . Arranging every combination in a square grid gives the similarity matrix .

Figure — Text-to-image conditioning (CLIP)

The diagonal () holds the correct matches — image with its own caption . Everything off the diagonal is a wrong pairing (a negative). CLIP's whole job: make the diagonal bright (high) and the rest dark (low). This idea comes straight from 4.3.8-Contrastive-learning.


8. Temperature — the sharpness dial (introduced first, because we need it next)

Before we can turn scores into probabilities, meet (Greek "tau"), a single positive number we divide every score by. It controls how decisive the final probabilities will be.

Figure — Text-to-image conditioning (CLIP)
  • Small (e.g. ): scores get divided into big numbers → the result will be peaky/confident.
  • Large : scores shrink → the result will be flat/uncertain.

Why a divide and not something else? Dividing scales all scores together, stretching or squashing the gaps between them without changing which is largest — a clean sharpness knob. CLIP even learns the best during training. Keep this in mind; it appears inside the formula in the very next section.


9. , softmax, and probability — turning scores into confidence

Softmax uses (and the temperature from section 8) to turn a row of scores into probabilities that add to :

  • reads "probability that text is the match, given image " — the bar means "given".
  • (capital sigma) means "add up over all from to " — here, summing across every text in the row so the denominator is the total.
  • is each score divided by the temperature you just met.

Dividing each score by the sum guarantees the outputs are all positive and sum to exactly — a genuine probability distribution. We want : image is confident its own caption is the match.


10. Cross-entropy loss — the "how wrong are we" number

The minus sign flips (which is negative for probabilities under ) into a positive penalty. is the number training tries to shrink; shrinking it pushes correct pairs together and wrong pairs apart.

Why the loss must be symmetric (both directions)

So far asks, for each image, "which text matches me?" — that is the image→text loss:

But we can equally read down each column of the matrix and ask, for each text, "which image matches me?" — the text→image loss:

Note the denominator now sums over the column (all images for a fixed text ). CLIP averages the two so both encoders get equal pressure:


11. Conditioning symbols: , , (and the diffusion notation around them)

These appear when CLIP steers a diffusion model. First, the diffusion notation the parent borrows (built fully in 4.5.14-Diffusion-models):

Now the three steering symbols:

  • = the text embedding fed in as a condition — the "instruction".
  • (empty set) = no condition — "generate anything".
  • = the guidance scale, a knob for how hard to obey the text (typically ).

Putting it together, the difference

is an arrow pointing from "any image" toward "an image matching the prompt": it is the guessed-noise-with-the-prompt minus the guessed-noise-with-no-prompt. Multiplying by stretches that arrow so the picture obeys the words more strongly. This is the exact bridge into 4.5.15-Classifier-free-guidance.


Prerequisite map

Vectors as arrows

Norm - arrow length

Dot product - agreement

Cosine similarity

Similarity matrix s_ij

Encoders f_I and f_T

Temperature tau

Softmax probability

Exponential exp

Cross-entropy loss

Symmetric loss both directions

CLIP training

Guidance c w and null

Diffusion z_t t epsilon

Text-to-image conditioning CLIP

Each foundation feeds upward: arrows and lengths make cosine similarity, similarity fills the matrix, softmax and temperature turn it into probabilities, cross-entropy scores it in both directions, and the trained result unlocks guided generation. See also 4.2.12-Transfer-learning and 4.5.17-Multimodal-learning for where this leads.


Equipment checklist

Test yourself — cover the right side and answer before revealing.

What does the acronym CLIP stand for?
Contrastive Language–Image Pre-training.
What is a vector, in one phrase?
An ordered list of numbers, drawn as an arrow from the origin.
What does mean?
The space of all lists of real numbers (-dimensional space).
What do the encoders and output?
Vectors (arrows) living in the same .
How do you compute a dot product?
Multiply matching entries of two vectors and sum them into one number.
What does the dot product secretly encode?
The angle between the arrows, via .
What is ?
The length of the arrow, .
Why divide the dot product by both norms?
To cancel magnitude and measure direction (meaning) alone; gives cosine similarity in .
In the matrix , where are the correct matches?
On the diagonal ().
What does temperature do, and when is it introduced?
It divides every score to sharpen (small ) or flatten (large ) softmax; it must be defined before the softmax formula uses it.
Why use inside softmax?
It is always positive and grows fast, cleanly turning scores into a valid probability distribution.
When is cross-entropy loss zero?
When the model assigns probability to the correct pair.
What does the gradient point toward?
The direction of fastest increase; training moves opposite to it to shrink the loss.
Why is the CLIP loss symmetric?
It averages image→text and text→image losses so both encoders are trained equally.
What do , , and mean?
The noisy image at step , the noise-level step number, and the network that guesses the noise to remove.
What do , , and mean in guidance?
Text condition, null (no) condition, and guidance strength.