Same Transformer idea — predict next unit over patches, frames, or latents
| Modality | Input unit | Predicts | Example | Key metric |
|---|---|---|---|---|
| Text (LLM) | Token | Next text token | GPT-4, Llama | Perplexity, MMLU |
| Vision (LVM) | Image patch | Class / mask token | ViT, SAM | Top-1 acc, IoU |
| Image gen | Latent noise | Less noisy latent | Stable Diffusion | FID, CLIP score |
| ASR | Audio frames | Text token | Whisper | WER |
| TTS | Text token | Mel / waveform | ChatTTS, ElevenLabs | MOS, SIM |
| Multimodal LLM | Fused tokens | Text (+ optional gen) | GPT-4o, LLaVA | MMMU, VQA acc |
from transformers import AutoImageProcessor, AutoModelForImageClassification
from PIL import Image
processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224")
model = AutoModelForImageClassification.from_pretrained("google/vit-base-patch16-224")
image = Image.open("cat.jpg")
inputs = processor(images=image, return_tensors="pt")
logits = model(**inputs).logits
label = model.config.id2label[logits.argmax(-1).item()]
print(label) # e.g. "Egyptian cat"
Eval: ImageNet top-1 / top-5 accuracy. Fine-tune on your dataset if domain shift (medical, industrial).
# pip install segment-anything
from segment_anything import sam_model_registry, SamPredictor
import numpy as np
sam = sam_model_registry["vit_h"](checkpoint="sam_vit_h.pth")
predictor = SamPredictor(sam)
predictor.set_image(image_rgb)
# Click prompt (x, y) on object
masks, scores, _ = predictor.predict(
point_coords=np.array([[520, 375]]),
point_labels=np.array([1]),
multimask_output=True,
)
best_mask = masks[scores.argmax()] # pixel-level segmentation
Eval: IoU (Intersection over Union) on held-out objects; zero-shot on new categories.
from diffusers import StableDiffusionPipeline
import torch
pipe = StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
pipe = pipe.to("cuda")
image = pipe(
prompt="a cat sitting on the moon, watercolor",
num_inference_steps=30,
guidance_scale=7.5,
).images[0]
Eval: FID (distribution vs real images), CLIP score (text-image alignment), human preference A/B.
import whisper
model = whisper.load_model("base") # tiny/base/small/medium/large
result = model.transcribe("meeting.wav", language="en")
print(result["text"])
# With word timestamps
for seg in result["segments"]:
print(seg["start"], seg["end"], seg["text"])
$$\text{WER} = \frac{S + D + I}{N}$$
S = substitutions, D = deletions, I = insertions, N = words in reference transcript.
import jiwer
reference = "the cat sat on the mat"
hypothesis = "the cat sit on mat"
wer = jiwer.wer(reference, hypothesis)
print(f"WER = {wer:.2%}") # lower is better; <5% = strong ASR
# OpenAI TTS API (simplest production path)
from openai import OpenAI
client = OpenAI()
response = client.audio.speech.create(
model="tts-1-hd",
voice="nova",
input="Hello, welcome to the multimodal course.",
)
response.stream_to_file("welcome.mp3")
# Open-source: ChatTTS / Coqui TTS / edge-tts for local dev
| Stage | Output |
|---|---|
| Text encoder | Phoneme / token embeddings |
| Acoustic model | Mel spectrogram frames |
| Vocoder (HiFi-GAN) | Raw waveform |
Eval: MOS 1–5 (human listeners), speaker similarity (SIM), character error rate for intelligibility tests.
Fuse image encoder + LLM via projection layer. User sends image + text; model predicts text tokens.
from openai import OpenAI
import base64
client = OpenAI()
with open("chart.png", "rb") as f:
b64 = base64.standard_b64encode(f.read()).decode()
response = client.chat.completions.create(
model="gpt-4o",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "What trend does this chart show?"},
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{b64}"}},
],
}],
)
print(response.choices[0].message.content)
| Task | Metric | Good target | Tool |
|---|---|---|---|
| Classification | Top-1 accuracy | >90% in-domain | sklearn, torchmetrics |
| Segmentation | IoU / mIoU | >0.7 | pycocotools |
| Image gen | FID, CLIP score | Lower FID | clean-fid |
| ASR | WER | <5% clean speech | jiwer |
| TTS | MOS | >4.0 | Human study |
| VLM | VQA accuracy, MMMU | Benchmark-specific | lmms-eval |
Cross-course eval matrix: Evaluation Guide.
pip install openai-whisper jiwer transformers diffusers pillow openai