# BLIP-2: Bootstrapping Language-Image Pre-training with Frozen Image Encoders and Large Language Models

Junnan Li, Dongxu Li, Silvio Savarese, Steven Hoi · arXiv · 2023-1-30

- **Problem** Reusing frozen image encoders and frozen LLMs for vision-language pre-training is hard because an LLM never saw images and a generation loss alone does not align them, so BLIP-2 trains a small Querying Transformer as the only updated bridge.
- **Method** Trains a lightweight Querying Transformer in two stages between a frozen image encoder and a frozen LLM: three image-text objectives first, then a generative loss through a projection layer.
- **Results** Reached 65.0 VQA accuracy on VQAv2 test-dev zero-shot with ViT-g and FlanT5XXL, and the paper reports an 8.7% gain over Flamingo80B with 54x fewer trainable parameters.

![Figure 2: (Left) Model architecture of Q-Former and BLIP-2’s first-stage vision-language representation learning objectives. We jointly optimize three objectiv…](https://refivu.com/papers/3bd907be-414a-4e3b-b195-d25379e2be77/figures/figure-644246a534d43a954dce16ebaddcc5d7.png?thumb=512)

**Figure 2** . (Left) Model architecture of Q-Former and BLIP-2’s first-stage vision-language representation learning objectives. We jointly optimize three objectives which enforce the queries (a set of learnable embeddings) to extract visual representation most relevant to the text. (Right) The self-attention masking strategy for each objective to control query-text interaction.

[Original paper](https://arxiv.org/abs/2301.12597v3) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Junnan Li, Dongxu Li, Silvio Savarese, Steven Hoi · BLIP-2: Bootstrapping Language-Image Pre-training with Frozen Image Encoders and Large Language Models · Original paper figure · Extracted the figure area from page 3 of the original PDF.

## Why both pretrained models stay frozen

End-to-end vision-language pre-training trains large models on large image-text data, so the compute cost grows with model size. Reusing pretrained vision models and LLMs avoids much of that cost, and keeping them fixed also protects what the LLM already knows from being overwritten. The difficulty is alignment: an LLM never saw images during its text-only training, so nothing in a frozen LLM links visual features to its word space.

Earlier frozen-LLM systems such as Frozen and Flamingo train with an image-to-text generation loss, which the authors argue is not enough to close the modality gap. BLIP-2 instead places a Querying Transformer between a frozen image encoder and a frozen LLM and updates only that module during pre-training. Acting as an information bottleneck, the module passes on the visual information the LLM needs and leaves out the rest.

## How the Querying Transformer is built

The Querying Transformer, Q-Former, has two transformer submodules that share self-attention layers: an image transformer that talks to the frozen image encoder, and a text transformer that can serve as a text encoder or a text decoder. A fixed set of learnable query embeddings feeds the image transformer. The queries exchange information through self-attention, read the frozen image features through cross-attention layers inserted in every other transformer block, and can attend to the text through the same self-attention layers.

Which attention mask governs query-text interaction depends on the pre-training objective, as Figure 2 illustrates.

The Q-Former starts from BERT base weights, while its cross-attention layers start from random values. The module has 188M parameters, with 32 queries of dimension 768, matching its hidden size. The output Z is therefore 32×768, much smaller than the 257×1024 features of ViT-L/14, which pushes the queries to keep only the visual information that matters for the text.

The queries are learned parameters, so their content is fixed after training, while the image features they read change with each input image.

## First stage: query-text alignment objectives

The first stage attaches the Q-Former to the frozen image encoder and trains it on image-text pairs with three jointly optimized objectives that share inputs and parameters but use different attention masks. Image-Text Contrastive Learning compares each query output with the text \[CLS\] embedding, takes the highest pairwise similarity as the image-text score, and uses a unimodal mask so that queries and text cannot see each other.

Because the frozen encoder lets more samples fit on each GPU, this objective uses in-batch negatives in place of the momentum queue used in BLIP.

Image-grounded Text Generation trains the Q-Former to generate the text from the image. Text cannot reach the image directly, so everything the decoder needs must pass through the queries. A multimodal causal mask lets the queries attend to each other but not to the text, while each text token sees all queries and the earlier text tokens.

A \[DEC\] token replaces \[CLS\] as the first text token.

Image-Text Matching is a binary task that predicts whether an image-text pair is matched, and it uses a bi-directional mask so that queries and text attend to each other. Each query output goes into a two-class linear classifier, and the per-query logits are averaged into a single matching score. Negative pairs are built with the hard negative mining strategy from Li et al.

(2021; 2022).

## Second stage: connecting the queries to a frozen LLM

In the second stage, the pre-trained Q-Former is attached to a frozen LLM through a fully-connected layer that projects the output query embeddings Z to the LLM's text embedding dimension. The projected queries are placed in front of the text embeddings, where they steer the LLM as visual soft prompts. Since the Q-Former already keeps language-relevant visual content, the LLM has less alignment work to do, which the authors link to mitigating catastrophic forgetting.

Decoder-based LLMs such as OPT are trained with the language modeling loss, generating the text conditioned on the query prompts. Encoder-decoder LLMs such as FlanT5 are trained with a prefix language modeling loss: the text is split, the prefix goes to the encoder together with the visual representation, and the suffix is the decoder's generation target.

The LLM weights stay fixed, and training adjusts the Q-Former so that its output can be read by the LLM.

## Pre-training data and budget

The pre-training set is the same as BLIP's, with 129M images in total, including COCO, Visual Genome, CC3M, CC12M, SBU and 115M images from LAION400M. CapFilt creates synthetic captions: the BLIPlarge captioning model generates 10 captions per web image, and these are ranked with the original caption by CLIP ViT-L/14 image-text similarity.

The top two captions per image are kept, and one is sampled at random at each pre-training step.

The frozen image encoders are ViT-L/14 from CLIP and ViT-g/14 from EVA-CLIP, with the last layer removed and the second-last layer's output used as image features. The frozen LLMs are the unsupervised-trained OPT family for decoder-based models and the instruction-trained FlanT5 family for encoder-decoder models. The first stage runs for 250k steps and the second for 80k steps, with batch sizes of 2320/1680 for ViT-L/ViT-g in the first stage and 1920/1520 for OPT/FlanT5 in the second.

The frozen ViT and LLM parameters are converted to FP16, except FlanT5, which uses BFloat16; the authors found no degradation compared with 32-bit models. Images are 224×224 with random resized cropping and horizontal flipping, and the largest model with ViT-g and FlanT5-XXL needs under 6 days for the first stage and under 3 days for the second on a single 16-A100(40G) machine.

## Zero-shot VQA against Flamingo

Zero-shot VQA appends a prompt to the frozen LLM: 'Question: {} Answer:' for OPT and 'Question: {} Short answer:' for FlanT5. Decoding uses beam search with beam width 5 and a length penalty of -1, which favours shorter answers.

The paper reports an 8.7% gain over Flamingo80B on zero-shot VQAv2, achieved with 54x fewer trainable parameters. In Table 2, ViT-g with FlanT5XXL reaches 65.2 on VQAv2 val and 65.0 on test-dev, against 56.3 for Flamingo80B on test-dev. On OK-VQA test the same configuration scores 45.9, below the 50.6 of Flamingo80B. The authors hypothesize that OK-VQA rewards open-world knowledge more than visual understanding, and that the 70B Chinchilla language model in Flamingo80B holds more knowledge than the 11B FlanT5XXL.

With OPT2.7B, ViT-g reaches 53.5 on VQAv2 val against 50.1 for ViT-L, and ViT-g also beats ViT-L with FlanT5. Within each LLM family, the larger model scores higher, and FlanT5, which is instruction-tuned, outperforms OPT on VQA in these results. The authors read these trends as evidence that a stronger image encoder or a stronger LLM improves the result.

Among the GQA rows of Table 2, the next highest entry is FewVLM at 29.3 on test-dev, against 44.7 for ViT-g with FlanT5XXL.

## Captioning and retrieval results

For captioning, the Q-Former and the image encoder are finetuned on COCO while the LLM stays frozen, and generation starts from the prompt 'a photo of'. Evaluation covers the COCO test split and zero-shot transfer to the NoCaps validation set, where the overall CIDEr of the ViT-g with FlanT5XL model is 121.6 and its SPICE is 15.8. BLIP reaches 113.2 CIDEr and 14.8 SPICE on the same NoCaps overall column.

For retrieval, the image encoder and the Q-Former are finetuned on COCO with ITC, ITM and ITG, and the LLM is not used. At inference, the top k=128 candidates from feature similarity are reranked with pairwise ITM scores. After COCO finetuning on the 5K test set, ViT-g reaches 85.4 image-to-text R@1 and 68.3 text-to-image R@1.

The authors read this as the generation loss pushing the queries toward language-relevant visual features.

## Effect of the first stage on generative learning

This comparison removes the first stage, so the Q-Former must bridge the modality gap through the generative loss alone, which the authors compare with the Perceiver Resampler in Flamingo. Zero-shot VQAv2 accuracy is tracked over 16k to 80k iterations for ViT-g with OPT6.7B and with FlanT5-XL, with and without representation learning.

Without representation learning, both LLM types score substantially lower on zero-shot VQA. With OPT, the authors observe catastrophic forgetting, where accuracy drops as training proceeds, and they attribute this to the loss of pre-trained language ability. The text gives no end-point values for these curves, so the comparison here is qualitative.

## Finetuning for VQA

VQA finetuning updates the Q-Former and the image encoder while the LLM stays frozen. The LLM receives the Q-Former output together with the question and is trained with an open-ended answer generation loss. The question tokens also enter the Q-Former and interact with the queries through self-attention, so the cross-attention layers can focus on image regions that matter for the question.

The VQA training data combines the VQAv2 training and validation splits with training samples from Visual Genome, following BLIP.

Among the open-ended generation models in Table 4, ViT-g with OPT6.7B has the highest VQAv2 test-dev score, 82.19, against 82.00 for Flamingo80B and 82.00 for OFA. ViT-g with FlanT5XL reaches 81.55 on test-dev, and the closed-ended classifiers, such as BEIT-3 at 84.19 test-dev, fall outside this comparison.

## Instructed zero-shot generation examples

The text prompt is appended after the visual prompt, so the LLM receives both the image representation and the instruction. Figure 4 shows examples with ViT-g and FlanT5XXL that cover visual knowledge reasoning, visual commonsense reasoning, visual conversation, storytelling and personalized generation. These are qualitative examples, and no score is attached to them in the paper.

The authors call these capabilities emerging, because the model keeps following text instructions after the visual input is added.

## Limitations

Recent LLMs can learn in context from few-shot examples, but in these experiments adding in-context VQA examples did not raise BLIP-2's VQA performance. The authors attribute this to the pre-training data, which has a single image-text pair per sample, so the LLM cannot learn correlations across several pairs in one sequence. Flamingo's interleaved M3W data has several pairs per sequence, and the authors plan a similar dataset for future work.

Image-to-text outputs can be wrong because of inaccurate knowledge from the LLM, an incorrect reasoning path, or out-of-date image content. Because the LLM is frozen, BLIP-2 inherits its risks, such as offensive language, social bias and leaking private information. The authors suggest instructions to guide generation or training on a dataset with harmful content removed as remedies.

The study explores two frozen image encoders, ViT-L/14 and ViT-g/14, and two LLM families, OPT and FlanT5. The OK-VQA gap to Flamingo80B is left as a hypothesis, and no experiment tests the open-world knowledge explanation.

## Paper info

- **Authors**: Junnan Li, Dongxu Li, Silvio Savarese, Steven Hoi
- **Venue**: arXiv · Preprint
- **First published**: 2023-1-30
- **Added**: 2026-10-20
- **Updated**: 2023-6-15
- **Version**: v3
- **arXiv**: 2301.12597
- **Category**: cs.CV
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

[Original paper ↗](https://arxiv.org/abs/2301.12597v3) · [PDF ↗](https://arxiv.org/pdf/2301.12597v3)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Abstract

The cost of vision-and-language pre-training has become increasingly prohibitive due to end-to-end training of large-scale models. This paper proposes BLIP-2, a generic and efficient pre-training strategy that bootstraps vision-language pre-training from off-the-shelf frozen pre-trained image encoders and frozen large language models. BLIP-2 bridges the modality gap with a lightweight Querying Transformer, which is pre-trained in two stages. The first stage bootstraps vision-language representation learning from a frozen image encoder. The second stage bootstraps vision-to-language generative learning from a frozen language model. BLIP-2 achieves state-of-the-art performance on various vision-language tasks, despite having significantly fewer trainable parameters than existing methods. For example, our model outperforms Flamingo80B by 8.7% on zero-shot VQAv2 with 54x fewer trainable parameters. We also demonstrate the model's emerging capabilities of zero-shot image-to-text generation that can follow natural language instructions.

## Quote from the paper

Junnan Li, Dongxu Li, Silvio Savarese, Steven Hoi (2023). BLIP-2: Bootstrapping Language-Image Pre-training with Frozen Image Encoders and Large Language Models. arXiv:2301.12597v3. https://arxiv.org/abs/2301.12597v3

**BibTeX**

```
@misc{li2023blip,
  title = {{BLIP-2: Bootstrapping Language-Image Pre-training with Frozen Image Encoders and Large Language Models}},
  author = {Junnan Li and Dongxu Li and Silvio Savarese and Steven Hoi},
  year = {2023},
  eprint = {2301.12597},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2301.12597v3}
}
```

## Other paper commentary

- [Visual Instruction Tuning](https://refivu.com/en/papers/760eaf17-9dbc-40d5-afee-d36c375c59e3-visual-instruction-tuning.md)
- [Qwen2.5 Technical Report](https://refivu.com/en/papers/bbe09642-acbf-4c8a-ac5f-c376606e8d8b-qwen2-5-technical-report.md)
- [Evaluating Large Language Models Trained on Code](https://refivu.com/en/papers/10d79a8a-e539-4768-b215-b5af91ac2dbf-evaluating-large-language-models-trained-on-code.md)
- [Flamingo: a Visual Language Model for Few-Shot Learning](https://refivu.com/en/papers/0ee82fc2-fa2e-482f-ac81-6d339f94b5fd-flamingo-a-visual-language-model-for-few-shot.md)
- [Toolformer: Language Models Can Teach Themselves to Use Tools](https://refivu.com/en/papers/f48b7ceb-5adf-433c-91ec-a0e24795c172-toolformer-language-models-can-teach-themselves-to-use.md)
- [DeBERTa: Decoding-enhanced BERT with Disentangled Attention](https://refivu.com/en/papers/b1eee697-1c6e-4274-956c-048abc93c07c-deberta-decoding-enhanced-bert-with-disentangled-attention.md)
- [Segment Anything](https://refivu.com/en/papers/da97e79e-c51b-4305-9514-76a2433c46a4-segment-anything.md)
- [WaveNet: A Generative Model for Raw Audio](https://refivu.com/en/papers/df60bc5e-602b-494d-b90e-87e94d1fe90d-wavenet-a-generative-model-for-raw-audio.md)
- [Diffusion Models Beat GANs on Image Synthesis](https://refivu.com/en/papers/c4296a34-b538-4422-b11f-4a805621a24f-diffusion-models-beat-gans-on-image-synthesis.md)
- [Robust Speech Recognition via Large-Scale Weak Supervision](https://refivu.com/en/papers/52603b17-2b8d-42a8-916e-6c06910f2ca7-robust-speech-recognition-via-large-scale-weak-supervision.md)
- [Neural Discrete Representation Learning](https://refivu.com/en/papers/111a9c5f-9d7d-4bff-bbad-a962285094a3-neural-discrete-representation-learning.md)
- [Momentum Contrast for Unsupervised Visual Representation Learning](https://refivu.com/en/papers/4093c4bb-ce8b-4d26-bded-60ec02bc0fac-momentum-contrast-for-unsupervised-visual-representation.md)

## Terms in this paper

- [COCO](https://refivu.com/en/terms/41f3215c4f4a-coco)
- [BERT](https://refivu.com/en/terms/45b639a1d317-bert)
- [CIDEr](https://refivu.com/en/terms/bd6b0acc54ba-cider)
- [catastrophic forgetting](https://refivu.com/en/terms/0039a430b4e3-catastrophic-forgetting)
- [Flickr30K](https://refivu.com/en/terms/3460b37ae772-flickr30k)
- [Image Captioning](https://refivu.com/en/terms/9597f1623624-image-captioning)
- [Hard Negative Mining](https://refivu.com/en/terms/fa1aacdee448-hard-negative-mining)
- [in-context learning](https://refivu.com/en/terms/d53d2af6b551-in-context-learning)
- [GQA](https://refivu.com/en/terms/912d41ed8914-gqa)
- [LLM](https://refivu.com/en/terms/c8783141d968-llm)
- [in-batch negatives](https://refivu.com/en/terms/a4ee4e02506f-in-batch-negatives)
- [BLIP-2](https://refivu.com/en/terms/d03727ce12f7-blip-2)
- [Image-Text Retrieval](https://refivu.com/en/terms/c720c3ef0248-image-text-retrieval)
- [NoCaps](https://refivu.com/en/terms/3886816aaa7f-nocaps)
- [information bottleneck](https://refivu.com/en/terms/a3cb119534db-information-bottleneck)
- [Q-Former](https://refivu.com/en/terms/6e04ea66057b-q-former)
- [VQAv2](https://refivu.com/en/terms/e4f208a17818-vqav2)
- [BLIP](https://refivu.com/en/terms/cff5bc108cd3-blip)
- [CapFilt](https://refivu.com/en/terms/c329d84a0972-capfilt)
- [FlanT5](https://refivu.com/en/terms/e9dacbb4d854-flant5)
- [OK-VQA](https://refivu.com/en/terms/92836bc21dab-ok-vqa)
- [Prefix language modeling](https://refivu.com/en/terms/e2964fefd966-prefix-language-modeling)
- [ViT-g/14](https://refivu.com/en/terms/d09c6f74067e-vit-g-14)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/3bd907be-414a-4e3b-b195-d25379e2be77-blip-2-bootstrapping-language-image-pre-training-with)
