Skip to content

Learning from noisy web pairs: ALBEF, BLIP and CoCa

Web captions are often wrong. ALBEF aligns before fusing and softens its targets with a momentum teacher, BLIP writes and filters its own captions, and CoCa trains retrieval and captioning in one model.

Advanced ~15 min8 steps

What runs in CodeSplash

You will be able to

  • Explain "align before fuse" and why hard negatives come from the contrastive scores
  • Compute a momentum-distilled soft target
  • Describe BLIP's caption bootstrapping and its risks
  • Say how CoCa serves both retrieval and captioning

Read first

01

Captions you can't trust

Read

Web alt-text often describes something else: the file name, the page, the photographer, a joke. A model trained to treat every pair as a perfect match is punished for disagreeing with captions that were wrong to begin with.

Three answers from 2021–2022: soften the targets so a confident model can disagree (ALBEF), rewrite and filter the captions (BLIP), or let the model learn from both matching and writing captions (CoCa).

02

ALBEF: align before fuse

Read
Reference · MM009 · Explained hereALBEFAligns image and text embeddings before fusing them and uses a momentum teacher to provide soft training targets.

ALBEF first trains its image and text encoders with a contrastive loss, so their outputs already line up, and only then feeds them to a fusion encoder trained with image–text matchingImage–text matching (ITM)A pretraining task where the model says whether an image and a caption belong together, usually trained with hard negatives. and masked words. The contrastive similarities also pick hard negatives for matching: captions that look right for an image but aren't.

Its momentum distillation keeps a slowly updated copy of the model (a momentum encoderMomentum encoderA copy of the encoder whose weights trail the trained one as a slow moving average; it gives stable targets or keys.) whose soft predictions are mixed into the targets. In the program, a one-hot target mixed 40% with the teacher becomes 0.880, 0.0800 and 0.0400; the student's cross-entropy against it is 0.601.

03

Why soften the target?

Predict

Predict first

Why mix the teacher's soft predictions into the one-hot target?

It speeds up trainingA wrong caption costs less when the teacher also doubts itIt removes the need for negatives
Reveal

A wrong caption costs less when the teacher also doubts it. If the teacher thinks another caption fits better, the target spreads some weight there, so the student isn't pushed hard toward a noisy label. It is knowledge distillationKnowledge distillationTraining a new model (the student) to copy another model's predictions, usually so a small model can stand in for a big one. from the model's own averaged past.

04

BLIP: write better captions

Read
Reference · MM010 · Explained hereBLIPCombines visual-language understanding and generation with a bootstrapping process that generates candidate captions and filters noisy image-text pairs.

BLIP trains one model with three faces: unimodal encoders for contrastive matching, an image-grounded encoder for match or no-match, and an image-grounded decoder that writes captions. Then caption bootstrappingCaption bootstrapping (CapFilt)Writing new captions for web images with a captioner and dropping pairs a matching model scores low, then retraining. (CapFilt) cleans the data: the captioner writes a new caption for each web image, the matching model scores both original and new captions, and pairs below a threshold are dropped. The model is retrained on what's left.

In the program, three candidate captions for one dog photo are filtered at a set score: "dog on grass" and "dog on field" are kept, "cat on grass" is dropped.

05

The filter's blind spots

Read

Bootstrapping helps when the captioner and filter are better than the web text. But they are models with habits: unusual but correct captions can be filtered out, and the captioner's favorite phrasings spread through the data. The threshold decides the trade-off between noise and diversity, and it should be chosen on held-out human-labeled pairs, not on the model's own scores.

06

CoCa: contrast and caption in one

Read
Reference · MM018 · Explained hereCoCa: Contrastive CaptionerJointly learns image-text contrastive alignment and image-conditioned captioning in one encoder-decoder system. It makes the relationship between discriminative retrieval features and generative language outputs…

CoCa splits its text decoder in two. The first half sees only text (no cross-attentionCross-attentionAttention whose queries come from one sequence and keys and values from another, such as text reading image features. to the image) and yields a text embedding for a contrastive loss, as in a dual encoderDual encoderTwo separate networks map images and texts into one embedding space, compared by cosine similarity; neither sees the other.. The second half cross-attends to image features and predicts the caption word by word. One forward pass trains both.

In the program the unimodal text vector, normalized for retrieval, is (0.832, 0.555), while the multimodal feature that also carries the image is (0.700, 0.800). The program fuses by addition; real CoCa uses attention.

07

Check: noisy pairs

Checkpoint

Check yourself

What does "align before fuse" mean in ALBEF?

Show the answer

Answer: a

Aligned inputs make the fusion encoder's job easier, and the contrastive scores supply hard negatives for matching.

Check yourself

A one-hot target (1, 0) is mixed 50% with a teacher's prediction (0.6, 0.4). What is the first entry of the soft target?

Show the answer

Answer: 0.8

0.5 × 1 + 0.5 × 0.6 = 0.8. The second entry is 0.5 × 0 + 0.5 × 0.4 = 0.2.

Check yourself

Where do ALBEF's hard negatives for image–text matching come from?

Show the answer

Answer: a

Similar-looking wrong captions teach the matching head more than easy, unrelated ones.

Check yourself

Put BLIP's caption bootstrapping in order.

  1. 1The filter scores original and new captions and drops low-scoring pairs
  2. 2Retrain on the cleaned pairs
  3. 3Train the model on the noisy web pairs
  4. 4The captioner writes a new caption for each web image

Show the answer

The order:

  1. Train the model on the noisy web pairs
  2. The captioner writes a new caption for each web image
  3. The filter scores original and new captions and drops low-scoring pairs
  4. Retrain on the cleaned pairs

The cleaned data then trains a better model, which can bootstrap again.

Check yourself

What is the main risk of a very strict caption filter?

Show the answer

Answer: b

A filter is a model; its blind spots become the dataset's. Choose the threshold on held-out human-labeled pairs.

Check yourself

How does CoCa get both a retrieval embedding and a captioner from one decoder?

Show the answer

Answer: a

Leaving cross-attention out of the first half keeps that text embedding unimodal, as retrieval needs.

Check yourself

Which tasks can one CoCa model serve?

Show the answer

Answer: a

The contrastive half behaves like CLIP; the captioning half generates text about the image.

08

Recap

Recap
  • Web captions are noisy; treating each pair as a perfect match punishes correct disagreement.
  • ALBEF aligns encoders before fusing, mines hard negatives from contrastive scores and softens targets with a momentum teacher.
  • BLIP's CapFilt writes and filters captions; the filter's threshold and blind spots shape the data.
  • CoCa trains a unimodal text half for retrieval and a cross-attending half for captions in one pass.

Concepts in this lesson