liveBook · Manning

Multimodal

As explained in Hugging Face in Action

A multimodal model is a machine learning model that jointly processes or relates inputs from multiple data modalities, such as images and text.

A multimodal model processes and combines multiple information types, such as images, text, audio, video, or structured data. Combining modalities supports richer representations and tasks that require information from more than one source. section 6.2

Common multimodal applications include:

  • Generating image captions from visual content. section 6.2
  • Answering questions by reasoning across an image and written question. section 6.2
  • Combining speech, text, facial expressions, camera data, lidar, and GPS for specialized systems. section 6.2

CLIP connects image understanding with natural-language descriptions. It uses separate text and image encoders, aligns related image-text pairs during training, and can classify images with user-provided labels without task-specific fine-tuning. section 6.2.2

Listing 6.12 Using a multimodal model to simultaneously process visual and textual data
from transformers import CLIPProcessor, CLIPModel

model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")  #1
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")

labels = ["cat", "dog", "tiger", "train"]             
inputs = processor(text = labels,  #2
                   images = image,
                   return_tensors = "pt",
                   padding=True)

model.eval()

with torch.no_grad():
    outputs = model(**inputs)  #3

logits_per_image = outputs.logits_per_image  #4

probs = logits_per_image.softmax(dim=1)  #5
most_likely_index = torch.argmax(probs, dim=1).item()  #6
most_likely_object = labels[most_likely_index]

print(f"The most likely object is: {most_likely_object}")

Load a pretrained CLIP model and processor, provide an image with candidate text labels, then select the label with the highest probability. section 6.2.2

Classifying an image with text labels

Given the labels “cat,” “dog,” “tiger,” and “train” and an image of a dog, the CLIP pipeline returns “dog” as the most likely object. section 6.2.2

How Hugging Face in Action covers it

How deep it goes
Explains modality integration and CLIP’s encoders, alignment, and inference workflow without deriving training mathematics.
Examples
Uses CLIP to classify a dog image from the text labels cat, dog, tiger, and train.
What it assumes
Builds from the contrast between single-modal processing and combined image-text inputs.
What you can do after
Apply it via Hugging Face Transformers to classify images using natural-language labels without task-specific fine-tuning.
How it connects
Connects single-modal models, natural language processing, computer vision, image classification, and pretrained models.

Also explained in

Compare how 11 books explain multimodal →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Hugging Face in Action. The section links point to the parts of the book it draws on.