Vision-Language Inputs and Shared Representations
About 36 min
Goal
By the end of this lesson, you can explain how image and text representations can be compared in a shared space, how contrastive learning shapes retrieval, and why semantic similarity does not establish truth, identity, or authority.
How can an image and a sentence be compared when they are different kinds of data?
Start with a tiny thought experiment. Imagine three simple pictures:
- a striped triangle;
- a round badge;
- a square tile.
Now imagine the captions “a striped triangle,” “a round badge,” and “a square tile.” Before naming any training method, decide what you want a useful representation system to do.
Predict
Different inputs can become comparable vectors
An image encoder can turn pixels into a vector. A text encoder can turn words into a vector. If the two encoders are trained so that their outputs use a compatible representation space, the vectors can be compared with a similarity measure.
image
-> image encoder
-> vector ----┐
| similarity
text |
-> text encoder
-> vector ----┘
The image and sentence are still different raw data types. The comparison happens after each one has been transformed into a representation vector.
This reuses the embedding idea from earlier levels. The new step is that two different modalities are deliberately mapped into a space where their relationships can be compared.
Predict
Shared image-text space: similarity changes retrieval
A deterministic 2D teaching fixture stands in for learned image and text representations. Move one image representation and watch pair similarity and retrieval rank change.
[0.98, 0.18]Compare the image vector with each text vector → cosine similarity → retrieval ranking.
Training target: make the matched pair more similar than mismatched alternatives.
The caption points stay fixed. The filled image point moves in this 2D teaching space, and the ranking below is recomputed from the same coordinates.
| Rank | Caption | Pair | Similarity |
|---|---|---|---|
| 1 | a striped triangle | matched | 0.999 |
| 2 | a round badge | mismatched | 0.355 |
| 3 | a square tile | mismatched | -0.678 |
Authority boundary: synthetic similarity between an “admin badge screenshot” representation and the text “authorized administrator” is 0.999. Trusted principal user-17 has roles viewer, so authorization is not established. The similarity score is not an input to the permission check.
Move the triangle representation all the way toward the badge region. Its pixels did not literally become a badge; this is a teaching fixture showing what happens when the representation changes. The ranking can flip because retrieval uses the learned representation, not the human-readable label. When that happens, the visual marks the top result as a retrieval error because the highest-ranked caption is a known non-match in this fixture.
Matching pairs pull together; non-matching pairs push apart
Suppose a training batch contains several image-caption pairs. For the striped-triangle image:
- “a striped triangle” is a matching pair;
- “a round badge” is a non-matching pair;
- “a square tile” is another non-matching pair.
Training should make the matching image/text representations more similar and make incorrect pairings less similar. That matching-versus-non-matching training idea is called contrastive learning.
The exact objective can be written mathematically, but the durable intuition comes first:
matched pair -> similarity should rise
non-matching pair -> similarity should fall
A larger batch gives the model more alternatives to distinguish. Real systems also have choices about normalization, temperature, sampling, hard negatives, and data quality. Those details matter in practice, but they do not change the central question: which items should the representation space place near each other?
CLIP is an important concrete example
CLIP is a well-known example of this dual-encoder pattern. It trained an image encoder and a text encoder from image-text pairs so that related images and text could be compared in a shared representation space.
CLIP is useful here as a concrete reference, not as the only design. The broader idea is model-independent:
- encode each modality;
- produce comparable representations;
- score similarity;
- use the scores for retrieval, ranking, or classification-like decisions.
Shared spaces make retrieval and zero-shot classification possible
Once image and text representations are comparable, several workflows become possible.
For text-to-image retrieval, encode the text query and rank stored image vectors by similarity.
For image-to-text retrieval, encode an image and rank candidate captions or labels.
For a classification-like workflow, represent candidate class descriptions such as:
"a photo of a striped triangle"
"a photo of a round badge"
"a photo of a square tile"
Then compare the image representation with each text representation and choose or inspect the ranking.
This is not the same thing as a classifier that was trained with a fixed output head for exactly those three classes. The text descriptions themselves participate in the comparison.
Similarity is useful evidence, not truth
A shared embedding space compresses information for a similarity task. It does not guarantee that every nearby item is factually correct.
A screenshot of an ADMIN badge could be highly similar to the text “authorized administrator.” That does not prove the person is an administrator, that the badge is genuine, or that the current user may reset an account.
The same rule applies to ordinary retrieval. A semantically close caption may describe the wrong quantity, identity, date, or cause. Similarity answers a narrow question such as “which representation is nearby under this model?” It does not answer “is this claim true?” or “is this action allowed?”
Dual-encoder similarity is not multimodal generation
A dual-encoder similarity system can stop after producing vectors and scores:
image -> image encoder -> vector --┐
├-> similarity / ranking
text -> text encoder -> vector --┘
A multimodal generative assistant has a different job. It must bring visual information into a model that can continue reasoning or generate text, and it may later request tools or actions.
Those systems can reuse representation-learning ideas, but retrieving the closest text and generating an answer from multimodal context are not the same operation.
Keep this distinction in mind for the rest of Level 10:
- shared representations help compare or retrieve;
- a multimodal model can reason or generate from multiple input types;
- application code still owns validation, permissions, and action authority.
Keep representation similarity separate from evidence evaluation
This lesson stops at the representation-and-retrieval boundary. A shared-space score can tell you which learned representation is nearby, but a deployed multimodal system still needs separate checks for what an image actually supports.
L10.11, Multimodal Evaluation, takes that next step. It handles visual observations versus unsupported conclusions, preprocessing history, text inside images as untrusted input, region-level evidence, perception-versus-reasoning failures, and absence claims. Keeping those concerns in the evaluation lesson avoids mixing two different learning jobs here.
Run the local Lab
python labs/notebooks/level-10/l10-09-shared-representations.py
The Lab uses deterministic synthetic vectors plus trusted principal records. It does not call a live model or image service.
- Run the command. The striped-triangle image should retrieve “a striped triangle” first. Inspect the matched and mismatched cosine similarities.
- Change
MOVE_TRIANGLE_TOWARD_BADGE = 0.0to1.0and rerun. The image representation moves into the badge region and the retrieval ranking flips. This is a representation change, not a pixel-level image edit. - Inspect the authority boundary. The synthetic badge vector is highly similar to “authorized administrator,” but
CURRENT_PRINCIPAL = "user-17"has only the trustedviewerrole, so authorization is not established. - Change only
CURRENT_PRINCIPALto"admin-02"and rerun. Authorization becomes granted because the principal record contains theadministratorrole. The similarity score does not change. - Now change
CURRENT_PRINCIPALto"guest-99", which is not present inprincipal_records. The Lab should still run normally, print an empty trusted-role list, and report authorization as not established. Unknown principals fail closed instead of crashing or inheriting authority. - Restore the original principal and explain the boundary in code: similarity/ranking reads embedding vectors; authorization reads trusted principal records. Neither calculation substitutes for the other.
Loading lab…
Quick Check
Key Takeaways
- Different modalities can be encoded into comparable vectors in a shared embedding space.
- Contrastive learning rewards matching image-text pairs for becoming more similar than non-matching pairs.
- CLIP is an important dual-encoder example, but the shared-representation idea is broader than one model.
- Shared embeddings support retrieval and classification-like ranking; they do not guarantee factual correctness, identity, or authorization.
- Dual-encoder similarity and multimodal generation are different system behaviors.
- Vision evidence quality, preprocessing, and untrusted-content checks are evaluated separately in L10.11 rather than being folded into the shared-space lesson.
Next Lesson
Next, study audio and speech inputs. After that, L10.11 brings image, audio, retrieval, evidence, and security checks together under multimodal evaluation.
References
Completion is stored locally on this device.