Skip to main content

1. What are Multimodal Models?

Multimodal models can work with more than one type of data, such as:
  • Text
  • Images
  • Audio
  • Video
For example:
A model can receive an image and text together and understand the relationship between them. Example:
The model can determine whether the image and text are related.

2. Image + Text Models

Image-text models learn a relationship between visual information and language. One popular example is CLIP. CLIP stands for: Contrastive Language-Image Pre-training It learns to map images and text into a shared vector space.
If the image and text have similar meanings, their embeddings should have a high similarity score.

3. What is an Embedding?

An embedding converts data into numbers called a vector. For example:
Text is also converted into a vector:
The model can then compare these vectors.

4. Image-Text Similarity

We can use cosine similarity to measure how similar the image and text embeddings are. Formula: Similarity=ABABSimilarity = \frac{A \cdot B}{||A|| ||B||} The value is generally between:
For CLIP, a higher similarity means the text is more related to the image. Example:
The model would consider Text 1 more relevant.

5. CLIP Architecture

CLIP mainly contains two encoders:

Image Encoder

Converts an image into an embedding.

Text Encoder

Converts text into an embedding.
Both embeddings are designed to exist in the same representation space.

6. Why is CLIP Useful?

CLIP can be used for:
  • Image-text similarity
  • Zero-shot image classification
  • Image search
  • Text-based image retrieval
  • Image understanding
  • Content matching
For example, given an image and several labels:
CLIP can compare the image with each text description and select the most similar one.

7. Simple Image Captioning

Image captioning means generating a text description of an image. Example:
A typical image captioning system contains:
Example:

8. CLIP vs Image Captioning

Simple difference:

9. Code Challenge

Create:
The program will:
  1. Load a CLIP model.
  2. Load an image.
  3. Create several text descriptions.
  4. Encode the image.
  5. Encode the text.
  6. Calculate image-text similarity.
  7. Find the most similar caption.

10. Install Required Libraries


11. multimodal_demo.py


12. Output

image.jpg contains a dog playing outside. You may get:
The exact scores will vary depending on the image.

13. Important Concept in This Code

The important part is:
These represent the image and text as vectors. Then:
calculates how similar the image is to each text description. Finally:
selects the caption with the highest similarity.

14. Learning Flow

The main learning is:
Multimodal models connect different types of data, such as images and text, by representing them in a common feature space.

15. What Should Learn

For this topic,