Search

Search papers and lessons

BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language

Junnan Li, Dongxu Li, Caiming Xiong et al. · 2022

BLIP is one vision-language model that both understands and generates text, pre-trained on web pairs whose captions were rewritten and filtered by CapFilt.

On this page

  • Colour = topic mix
  • Neural network basics
  • Calculus
  • Architectures
  • Discrete math
  • Linear algebra
  • Probability
  • ReadReady to readNot yet

TL;DR

BLIP is a vision-language model that can both understand and generate text. Most earlier models did one job well: encoder-only models suit retrieval, and encoder-decoder models suit captioning. BLIP uses one architecture that switches between three modes, and it is pre-trained on web image-text pairs that were cleaned by a method called CapFilt. Across retrieval, captioning and question answering it reports state-of-the-art results at the time of publication.

Builds on: Vision-Language Model, Transformer, Contrastive Learning, Autoregressive Model · Leads to: BLIP-2, a follow-up by the same first author

Why it mattered

BLIP helped popularise two ideas in vision-language work. The first is one model for both kinds of task. The paper reports results on image-text retrieval, image captioning, visual question answering, visual reasoning and visual dialog, and it also reports zero-shot transfer to two video-language tasks. The second is that web text can be improved before training. Earlier systems such as CLIP and ALBEF trained on web pairs as they were, and BLIP showed a measurable gain from rewriting and filtering them.

The code, models and the bootstrapped dataset were released, so the method can be inspected and reused.

The problem

Vision-language pre-training teaches a model how pictures and words relate. Human-written captions are expensive, so most large systems use alt text scraped from web pages. The paper states the problem directly: even with simple rule-based filters, "noise is still prevalent in the web texts", and the harm of that noise was hidden by the gains from simply using more data.

There was also an architectural split. Encoder-based models, such as CLIP and ALBEF, embed the image and the text separately or together and score them, which suits retrieval. They are harder to use for generating text, such as captions. Encoder-decoder models can generate text, but the paper notes they had not been adopted successfully for retrieval. A single model that covers both would need one design and one set of pre-training objectives.

How it works

  1. Input: two kinds of data. There is a small human-annotated set {(Ih,Th)}\{(I_h, T_h)\}, such as COCO, and a large web set {(Iw,Tw)}\{(I_w, T_w)\} of image and alt-text pairs. The web texts are noisy.

  2. Build one pre-trained model, MED. BLIP's architecture is a multimodal mixture of encoder-decoder. One network can run as a unimodal encoder, which embeds the image or the text alone; as an image-grounded text encoder, which adds a cross-attention layer so the text can look at the image; or as an image-grounded text decoder, which writes text one word at a time. Most layers are shared, and only the self-attention layers differ between the encoder and decoder modes.

  3. Pre-train MED with three objectives. The image-text contrastive loss (ITC) pulls matched image and text embeddings together. The image-text matching loss (ITM) is a yes-or-no classification of whether a pair matches. The language modeling loss (LM) trains the decoder to produce the caption. All three are optimized together.

  4. Finetune the captioner and the filter. Both start from the same pre-trained MED and are finetuned separately on the small human set. The captioner is the decoder, trained with LM. The filter is the encoder, trained with ITC and ITM.

  5. Bootstrap the web data with CapFilt. The captioner writes one synthetic caption TsT_s for each web image, using nucleus sampling with threshold 0.9. The filter then removes every text, original or synthetic, that its ITM head judges as not matching its image. This is the step that CapFilt names.

  6. Pre-train a new model on the cleaned data. The kept web pairs and the human pairs form the new dataset, and a fresh MED is pre-trained on it. The paper's ablations show that continuing to train the old model on this data does not help, so the new model starts from scratch.

  7. Finetune for each task. Retrieval uses the ITC and ITM heads, captioning and question answering use the decoder, and the same pre-trained weights serve all of them.

flowchart TD
  H["Human-annotated pairs (COCO)"] --> FT["Finetune captioner and filter from one MED"]
  W["Web pairs (noisy alt text)"] --> CAP["Captioner writes synthetic captions"]
  FT --> CAP
  FT --> FIL["Filter removes non-matching texts"]
  CAP --> FIL
  W --> FIL
  FIL --> NEW["Cleaned pairs plus human pairs"]
  H --> NEW
  NEW --> PRE["Pre-train a new MED: ITC, ITM, LM"]
  PRE --> TASKS["Finetune: retrieval, captioning, VQA"]

A tiny trace. Take the four web pairs from the CapFilt lesson: a dog on a beach with alt text "IMG_2041.jpg", a red bicycle with a good caption, a bowl of soup with "click here to buy now", and a cat on a sofa with a good caption. The captioner adds four synthetic texts. The filter rejects the two useless alt texts. The new MED then sees six clean pairs from these four images, plus the human pairs, during its pre-training. This example is invented for illustration; the paper's experiments use millions of pairs.

The math

Image-text contrastive loss. For a batch of NN image-text pairs, let s(Ii,Tj)s(I_i, T_j) be the similarity between the embedding of image ii and text jj. A simplified form that captures the idea is

Litc=−1N∑i=1Nlog⁡exp⁡(s(Ii,Ti))∑j=1Nexp⁡(s(Ii,Tj))\mathcal{L}_{\text{itc}} = -\frac{1}{N}\sum_{i=1}^{N} \log \frac{\exp\big(s(I_i, T_i)\big)}{\sum_{j=1}^{N} \exp\big(s(I_i, T_j)\big)}

The matched text TiT_i should score higher than the other texts in the batch. The paper's version adds a momentum encoder and soft targets, which handle pairs that are positive but not exact matches; this simplified form leaves those out.

Image-text matching loss. The ITM head outputs a probability pmatchp_{\text{match}} that the pair is matched, and the label yy is 1 for a matched pair and 0 otherwise. The loss is the binary cross-entropy

Litm=−[ ylog⁡pmatch+(1−y)log⁡(1−pmatch) ]\mathcal{L}_{\text{itm}} = -\big[\, y \log p_{\text{match}} + (1 - y) \log (1 - p_{\text{match}}) \,\big]

averaged over the pairs. The paper selects hard negatives, that is, mismatched pairs with high similarity, to make the task harder.

Language modeling loss. For a caption with words t1,…,tLt_1, \dots, t_L given image II,

Llm=−∑i=1Llog⁡pθ(ti∣I,t<i)\mathcal{L}_{\text{lm}} = -\sum_{i=1}^{L} \log p_\theta(t_i \mid I, t_{\lt i})

where pθp_\theta is the model and t<it_{\lt i} means the earlier words. The paper applies label smoothing of 0.1 when computing this loss.

Consistency with CapFilt. The filter's yes-or-no decision is the ITM prediction, so the rule "keep a pair when pmatchp_{\text{match}} says it matches" is exactly the one in the CapFilt lesson.

Results

All numbers below are copied from the paper's tables. Recall at 1 (R@1) is the share of queries whose correct match ranks first.

Image-text retrieval on COCO (5K test set, finetuned). With the same 14 million pre-training images, BLIP reaches text-retrieval R@1 of 80.6 and image-retrieval R@1 of 63.1. ALBEF, the previous best with that data, reaches 77.6 and 60.7. The paper's text gives the average gain over ALBEF as +2.7 percent in average recall at 1 on COCO. The 129-million-image model reaches 81.9 and 64.3.

Zero-shot retrieval on Flickr30K. Without finetuning on Flickr30K, BLIP with 14 million images reaches text-retrieval R@1 of 94.8, against 94.1 for ALBEF with the same data.

Image captioning. On the COCO Karpathy test split, measured by CIDEr, BLIP with 14 million images scores 129.7, and the 129-million-image model with the CapFilt-L captioner and filter scores 133.3. The second value equals the 133.3 of LEMON-base trained on 200 million images, a model that uses a heavier object detector and higher-resolution inputs. BLIP uses 384 by 384 inputs. On NoCaps overall, CIDEr is 105.1 for the 14-million model and 109.6 for the CapFilt-L model.

Visual question answering. On VQA test-dev, BLIP with 14 million images scores 77.54, against 75.84 for ALBEF with the same data. The 129-million-image model scores 78.24.

Headline claims in the abstract. The paper states gains of +2.7 percent in average recall at 1 for retrieval, +2.8 percent in CIDEr for captioning and +1.6 percent in VQA score over the previous state of the art.

Limits. The authors omit SNLI-VE because its test data has been reported as noisy. The captioning comparison with LEMON is not like for like, since LEMON uses an object detector and higher-resolution inputs. The bootstrapped data is not perfect, and the paper does not measure exactly which texts the filter gets wrong. The ablations show the gain depends on training a new model rather than continuing an old one.

Reading guide

Check yourself

QuestionWhat are the three modes of the MED architecture, and which one does the captioner use?Show answer

MED can run as a unimodal encoder that embeds the image or the text alone, as an image-grounded text encoder that adds cross-attention so the text can look at the image, and as an image-grounded text decoder that writes text one word at a time. The captioner uses the image-grounded text decoder, trained with the LM loss.

QuestionIn the paper's 14-million-image setting, BLIP's text-retrieval R@1 on COCO is 80.6 and ALBEF's is 77.6. What is the difference in points?Show answer

The difference is 80.6−77.6=3.080.6 - 77.6 = 3.0 points.

QuestionWhy does the paper train a new model on the bootstrapped data rather than continuing to train the old one?Show answer

The ablations in the paper show that continued training from the previous pre-trained model does not help. The paper ties this to knowledge distillation, where the student model cannot be initialised from the teacher. The new model learns from the cleaned data without inheriting the old model's errors.

QuestionWhy is the captioning comparison with LEMON not like for like?Show answer

LEMON uses a computationally heavy pre-trained object detector and higher-resolution inputs (800 by 1333), while BLIP uses a detector-free design with 384 by 384 inputs. The paper points out that this makes LEMON's inference substantially slower, so the comparison should account for the difference in cost as well as the scores.

Sources

Read the full paper

Junnan Li, Dongxu Li, Caiming Xiong et al., 2022. arXiv:2201.12086