Multimodal pre-trained models
Multimodal pre-trained models (Multimodal Pre-trained Models) refer to models that can simultaneously process and understandmultiple data modalities(such as text, images, audio, etc.). Unlike traditional single-modality models, these models learn the associations and correspondences between different modalities through large-scale pre-training.
Core advantages of multimodal learning
- Information complementarity: different modalities can provide complementary information (e.g., images provide visual information, text provides semantic information)
- Enhanced robustness: when one modality's data is missing or of poor quality, other modalities can provide support
- Expanded application scenarios: support richer cross-modal tasks (such as image-text retrieval and image caption generation)
CLIP: A milestone in image-text contrastive learning
Basic concepts
CLIP (Contrastive Language-Image Pre-training) is a multimodal model proposed by OpenAI in 2021 that establishes the association between images and text through contrastive learning.
CLIP consists of two core components:
- Image Encoder: converts an image into a feature vector (e.g., using Vision Transformer or ResNet).
- Text Encoder: converts a text description into a feature vector (e.g., using Transformer).
Workflow:
- Input:
- Encoding:
- Contrastive learning:
The feature vectors output by both are mapped into the same semantic space, aligning the image and text representations through contrastive learning.

Explanation of key parts in the figure
Table part: contrastive learning matrix
The table shows the similarity computation of image-text pairs (assuming there are N texts and 4 images):
- Rows (images):
I1, I2, I3, I4represent different image features. - Columns (texts):
T1, T2, ..., TNrepresent different text features. - Cell value(such as
I1-T1): imageI1and textT1cosine similarity of the feature vectors of .
Goals:
Maximize the similarity on the diagonal (correct pairs, e.g. I1-T1), minimize the off-diagonal similarity (incorrect pairs, e.g. I1-T2). This is the core idea of contrastive learning.
Example section
- Image examples:
- "Pepper the aussie pup" (a photo of an Australian Shepherd dog).
- "Planer car dog" (possibly noise or a mislabel; it should actually be template text of the form "A photo of a (object)").
- Text template:
- "A photo of a (object)" is a text prompt template commonly used during CLIP pre-training to generalize across different categories (e.g., "a photo of a dog").
Model architecture
- Dual-encoder structure:
- Contrastive learning objective:
Training process
Example
Pseudocode showing the core training logic of CLIP
image_features
=
image_encoder
(
image_batch
)
Image feature extraction
text_features
=
text_encoder
(
text_batch
)
Text feature extraction
Compute the similarity matrix
logits
=
torch.
matmul
(
image_features
,
text_features.
T
)
- temperature
labels
=
torch.
arange
(
batch_size
)
The diagonal represents positive samples
Symmetric contrastive loss
loss_img
=
cross_entropy
(
logits
,
labels
)
loss_txt
=
cross_entropy
(
logits.
T
,
labels
)
total_loss
=
(
loss_img + loss_txt
)
/
2
Application scenarios
- Zero-shot image classification: Classify new categories without fine-tuning
- Image-text retrieval: Enable efficient text-to-image or image-to-text search
- Content moderation: Identify image content that does not match the text description
DALL-E: The magic of text-to-image generation
Basic concepts
DALL-E is a text-to-image generation model developed by OpenAI, capable of generating high-quality images from natural language descriptions.
Technical features
-
Two-stage training:
-
Key innovations:
Example of the generation process
Example
Pseudocode showing the DALL-E generation pipeline
text
=
"A Shiba Inu in a spacesuit playing video games on a space station"
text_tokens
=
tokenizer
(
text
)
Text encoding
image_tokens
=
transformer.
generate
(
text_tokens
)
Generate visual tokens
image
=
dvae.
decode
(
image_tokens
)
Decode into an image
Model evolution
| Version | Major improvements | Generation capability |
|---|---|---|
| DALL-E 1 | Base architecture | 256x256 resolution |
| DALL-E 2 | Diffusion model | 1024x1024 resolution, more accurate |
| DALL-E 3 | Integration with ChatGPT | More sophisticated prompt understanding |
Other important multimodal models
ALIGN (Google)
- Trained on noisy web data
- Demonstrated the effectiveness of large-scale weakly supervised data
Flamingo (DeepMind)
- Handle interleaved multimodal sequences (e.g., alternating image and text)
- Support few-shot learning
BEiT-3 (Microsoft)
- A unified multimodal pretraining framework
- Excels across image, text, and vision-language tasks
Application challenges of multimodal models
- Data requirements: Require massive high-quality multimodal aligned data
- Computational cost: Training these models requires enormous computing resources
- Evaluation difficulties: Lack of unified evaluation standards for multimodal tasks
- Bias issues: May amplify social biases in training data
Hands-on exercise: Zero-shot classification with CLIP
Example
import
clip
import
torch
from
PIL
import
Image
Load the model and preprocessing
device
=
"cuda"
if
torch.
cuda
.
is_available
(
)
else
"cpu"
model
,
preprocess
=
clip.
load
(
"ViT-B/32"
,
device
=
device
)
Prepare the input
image
=
preprocess
(
Image.
open
(
"dog.jpg"
)
)
.
unsqueeze
(
0
)
.
to
(
device
)
text_inputs
=
clip.
tokenize
(
[
"a dog"
,
"a cat"
,
"a bird"
]
)
.
to
(
device
)
Compute features
with
torch.
no_grad
(
)
:
image_features
=
model.
encode_image
(
image
)
text_features
=
model.
encode_text
(
text_inputs
)
Compute similarity
logits
=
(
image_features
@
text_features.
T
)
.
softmax
(
dim
=
1
)
(
"Prediction probability:"
,
logits.
cpu
(
)
.
numpy
(
)
)
Future directions
- More efficient architectures: Reduce computational cost and increase inference speed
- Fusion of more modalities: Add more modalities such as audio and video
- Causal understanding capability: Enhance the model's deep understanding of multimodal content
- Controllable generation: Improve precise control and editability of generated content
Multimodal pretrained models are reshaping human-computer interaction; from CLIP's cross-modal understanding to DALL-E's creative generation, these technologies open up entirely new possibilities for AI applications.