Image-language and multimodal models · Image-language and multimodal models · MM001 · Model
CLIP
Learns compatible image and text embeddings from paired examples, enabling text-based retrieval and classification with class descriptions.
In CodeSplash
A CodeSplash method runs this entry in Python and R. Set it up from the method's page. The methods that run it are Experimental.
Do it in CodeSplash Run it on your own data. It's in the Experimental lane in the app.
- Availability
- Runs in CodeSplash (Experimental)
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's run and the reference's record
- CodeSplash's run
- The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Learns compatible image and text embeddings from paired examples, enabling text-based retrieval and classification with class descriptions. It is a discriminative embedding model, not an image generator or a conversational reasoner.
Question / objective
Can matched image/text pairs be distinguished from mismatched pairs, and can that alignment transfer to new categories described in language? The learning target replaces a null/alternative hypothesis formulation; benchmark evaluation is a separate statistical task.
Method type and supervision
Model/system family. Image-language or broader multimodal learning using the paired, generated or task-specific supervision described below. This is not a classical significance test.
Architecture / computational structure
Separate image and text encoders project into a shared normalized embedding space; a learned logit scale controls contrastive similarities. Class text can replace a fitted classification head during zero-shot evaluation.
Assumptions
Paired descriptions must provide useful visual supervision. A caption can omit objects or refer to invisible context; treating all off-diagonal pairs as negatives can penalize semantically valid matches. Dataset overlap and prompt selection can inflate apparent zero-shot transfer.
Formula / computational definition
; . Unit vectors represent paired image/text items; is temperature and diagonal labels identify matches. This captures the central mechanism; consult the primary source for all masks, stages, normalizations and loss terms.
Parameters and notation
Learned/estimated quantities: Image/text encoder and projection weights and logit scale are learned. Token IDs, pixels and normalized embeddings are inputs/intermediate representations; class names are supplied evaluation choices. Hyperparameters and design choices: Image resolution, text truncation, batch composition, temperature handling, prompt templates and candidate classes change results. Compare the same class vocabulary and preprocessing.
Fitting, fine-tuning, and adaptation
Fit a frozen-feature probe first. For domain adaptation, tune projections or supported attention adapters before unfreezing whole encoders. LoRA is useful only in compatible linear layers; retain broad retrieval/zero-shot evaluation to detect forgetting. Save the exact trainable-module selection, data split, loss, optimizer and processor configuration; distinguish parameter adaptation from inference-time prompt tuning.
How to use and calibrate
Choose a specific model/processor and task protocol, validate preprocessing on known examples, tune only on a held-out development set and freeze the final evaluation. Report both retrieval directions, classification accuracy by subgroup, prompt sensitivity and hard compositional negatives. Similarity is not a calibrated probability of factual correctness.
Example application
Search an image collection using natural-language descriptions or classify images using written class prompts.
Interpretation / pitfalls
Watch out
Reported capability is conditional on available visual evidence, data coverage and the chosen task. Report both retrieval directions, classification accuracy by subgroup, prompt sensitivity and hard compositional negatives. Similarity is not a calibrated probability of factual correctness. A successful numeric component example is not evidence that a complete system achieves a published benchmark score.
Python and R code examples
Component: Symmetric contrastive cross-entropy on a paired similarity matrix. Dependencies: shared NumPy/base-R setup above. Python: executed successfully. R: unexecuted. Complete model training/inference: not run.
Full implementation routes: Python: use the authors’ CLIP encoder/tokenizer with its exact preprocessing; R: bridge those encoders with reticulate and compute similarity/probe analysis natively. Full neural inference was not run here.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — Symmetric contrastive cross-entropy on a paired similarity matrix.
Shared setup for this chapter
import numpy as np
def softmax(x):
z = np.asarray(x, dtype=float)
e = np.exp(z-z.max())
return e/e.sum()
scores=np.array([[2.,.1],[.3,1.8]])
image_loss=np.mean([-np.log(softmax(scores[i])[i]) for i in range(2)])
text_loss=np.mean([-np.log(softmax(scores[:,i])[i]) for i in range(2)])
print((image_loss+text_loss)/2)
Component demo, not a trained model — Symmetric contrastive cross-entropy on a paired similarity matrix.
Shared setup for this chapter
softmax <- function(x) {
e <- exp(x-max(x))
e/sum(e)
}
scores <- rbind(c(2,.1),c(.3,1.8))
image_loss <- mean(sapply(1:2,function(i)-log(softmax(scores[i,])[i])))
text_loss <- mean(sapply(1:2,function(i)-log(softmax(scores[,i])[i])))
print((image_loss+text_loss)/2)
Sources
- Primary source 1arxiv.org
From the CodeSplash reference, entry MM001.