Foundations — Multimodal models (vision-language)
This page is the toolbox. The parent note freely uses vectors, dimensions, dot products, cosine, softmax, logarithms and temperature. If any of those made you pause, start here. We define each symbol in plain words, draw its picture, and say why the topic needs it — in an order where each brick rests on the one before.
1. What is a vector? (the arrow)
Before anything, we need to know what an arrow in space is, because the whole topic lives on arrows.

Look at the figure. The pair is not "two separate numbers" — it is one arrow: go 3 right, 1 up, draw from origin to there. The red arrow is that vector.
Why the topic needs this. The parent note writes and . Read that as: "the image becomes one arrow, the sentence becomes another arrow." An image of a cat and the word "cat" are just two arrows we hope point the same direction.
means "is a member of". So reads: " is one of the arrows in the -number space."
2. Length of a vector (how long the arrow is)
Now that we have an arrow, we ask: how long is it? We need this because cosine similarity later divides by lengths.
The general rule: square every component, add them, take the square root.
Why the topic needs it. The parent's cosine formula has in the denominator. That division is what makes the model care about direction only, not how long the arrows happen to be — a short "cat" arrow and a long "cat" arrow should still count as the same concept.
3. The dot product (do two arrows agree?)
This is the heart of the whole comparison. We need a single number that says "do these two arrows point the same way?"
Here is the magic picture behind it:

The dot product secretly equals , where (the Greek letter "theta") is the angle between the two arrows. So the sign of the dot product tells you the geometry:
- Arrows point the same way (small angle) → dot product large and positive.
- Arrows are perpendicular (90°) → dot product exactly zero.
- Arrows point opposite (angle over 90°) → dot product negative.
Why the topic needs it. "Matching image and text should be close" literally means "their arrows should have a large positive dot product / small angle." The dot product is the raw agreement score; cosine (next) just cleans it up.
4. Cosine similarity (agreement, size removed)
The raw dot product mixes two things: the angle AND the lengths. We want angle alone. So we divide the lengths out.
Because we divided out both lengths, all that survives is — a number that depends only on the angle .

The figure shows the cosine of the angle as it sweeps from to :
- → → identical direction (same concept).
- → → unrelated.
- → → opposite.
That is exactly the ", +1 = same, 0 = orthogonal, −1 = opposite" table in the parent note. Now you know why those numbers appear: they are cosines of angles between arrows.
5. Exponential and logarithm (turning scores into confidence)
The training loss uses and . These are two tools that undo each other, and each earns its place.
Why the topic needs it. Similarities can be negative or zero, but a probability must be positive. Feeding a similarity through guarantees a positive number — and because grows so fast, a slightly higher similarity becomes a much higher value. That is why the parent's example turned vs into near-certainty : amplifies the winner.
Why the topic needs it. The loss is . If the model is confident (probability near 1), of it is near 0, so the loss is near 0 — "you did well, nothing to fix." If the probability is tiny, is a big negative number, and the minus sign makes the loss big — "you were wrong, fix a lot." The turns confidence into penalty. This is the cross-entropy loss in disguise.
6. Softmax (turning scores into a probability list)
The parent asks the model to pick the correct caption out of a batch. Softmax is the tool that converts a row of similarity scores into a list of probabilities that sum to 1.
Read the pieces you now know:
- — make each score positive (Section 5).
- — the big Greek "S" (, sigma) means "add up over all from 1 to ", so the denominator is the total.
- Dividing each top by the total → every lands in and they all add to 1: a real probability distribution.
Why the topic needs it. Contrastive training treats "which of the captions matches this image?" as a multiple-choice question. Softmax turns the similarity scores into the probability the model assigns to each choice. Then of the probability on the correct choice is the loss.
Picture two knobs on the same dial: turn down for a decisive model, up for a hesitant one.
7. Batch, sum, and matrix notation (the bookkeeping)
- Batch size — how many (image, text) pairs we process together in one step. In the parent example .
- Similarity matrix — a grid where entry (row , column ) is : image 's arrow against caption 's arrow. The diagonal (row , column ) holds the correct matches; everything off the diagonal is a wrong pairing we want to push apart.
- Subscripts like , , — just labels ("the -th one"), not multiplication.
- — projection matrices, learned tables of numbers that reshape an encoder's output arrow into the shared -dimensional space. Think of them as adapters plugging two different cables into one common socket. (See transfer learning for why we reuse pre-trained encoders and only learn these small adapters.)
Prerequisite map
The two encoders (image and text) sit on transformer architecture and Vision Transformers, learn via self-supervised learning on paired data, and rest on the idea of word embeddings — words as arrows — extended so that pictures become arrows too. The comparison machinery leans on attention inside the encoders and feeds forward to text-to-image generation.
Worked micro-check
Let and .
- Dot product: .
- Lengths: , .
- Cosine: .
An angle whose cosine is is about — the arrows nearly agree, so this image and text would be scored a strong match.
Equipment checklist
Cover the right side; can you answer before revealing?
A vector in is
means
The dot product geometrically equals
Cosine similarity strips out
is used because
is small when
Softmax converts
Temperature controls
The diagonal of the similarity matrix holds
and are
Recall Self-test: why cosine and not raw dot product?
Because the raw dot product mixes angle and lengths. We only want to know if two concepts point the same way, so we divide the lengths out and keep alone.