Search

Search papers and lessons

ViLBERT: Pretraining Task-Agnostic Visiolinguistic Representations

Jiasen Lu, Dhruv Batra, Devi Parikh et al. · 2019

ViLBERT pretrains two BERT-style streams, one for image regions and one for words, that exchange information through co-attention, then fine-tunes the same model on four vision-and-language tasks.

On this page

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

TL;DR

ViLBERT is a model that learns from pairs of pictures and sentences. It has two parallel transformer streams, one that reads the image as a set of object regions and one that reads the words, and the two streams exchange information through a special attention layer called co-attention. It is pretrained on about 3.3 million image-caption pairs with two tasks: guessing masked words and regions, and deciding whether a caption matches its image. The same pretrained model is then fine-tuned on four tasks with only a small new output layer each, and it set state-of-the-art results on all four.

Builds on: BERT: Pre-training of Deep Bidirectional Transformers, Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks, Transformer, Multi-Head Attention, Masked Language Modeling · Leads to: later vision-and-language models that pretrain one joint model on paired image and text data

Why it mattered

Before ViLBERT, a system that answered questions about pictures usually had a vision model and a language model, trained separately and joined by a task-specific design. The paper showed that one pretrained model could be reused across tasks that look quite different: answering questions about images, reasoning about movie scenes, pointing to the object a phrase refers to, and retrieving an image from a caption.

The paper's reported gains are large. On visual commonsense reasoning, the holistic Q to AR score rises from 43.1 for the earlier state-of-the-art R2C model to 54.04 for ViLBERT. On the Flickr30k image-retrieval task, recall at 1 rises from 48.60 for SCAN to 58.20. The paper reports that it sets state-of-the-art on VCR, RefCOCO+ and image retrieval by 7 to 10 percentage points.

By late 2026 the paper had about 5,100 citations on OpenAlex. Its idea of a joint pretrained model with a separate stream per modality is a standard reference point for vision-language pretraining.

The problem

A transformer that reads a sentence uses attention over word positions. An image has no natural order of pieces, and its useful units are regions with features, not pixels. The paper frames two difficulties with the simplest way to join the two.

The simplest way is to cluster image features into a vocabulary of visual tokens and feed them to BERT as if they were words. The paper names three drawbacks. Clustering throws away detail. The two kinds of input are treated identically, although an image region usually carries less context than a word and visual features are already the output of a deep network. And forcing one set of pretrained weights to handle both kinds of input can hurt the language side.

The paper's answer is to keep two streams with different depths and let them talk only at chosen layers.

How it works

Take a tiny example with one attention head and vectors of length 1 or 2. An image has two region features and the sentence has two words, "dog" and "runs". The question is what the visual region "sees" in the words.

  1. Start with separate streams. The image regions form a visual stream. Each region has a feature vector, plus a spatial code made from its normalized box corners and the fraction of the image it covers. The words form a linguistic stream, with word embeddings, position codes and a special classification token.
  2. Build the queries, keys and values as usual. Each stream computes its own queries, keys and values from its own representations, just as in a standard Transformer block. Visual queries come from the regions; text keys and values come from the words.
  3. Swap keys and values for co-attention. This is the new step. The visual stream uses its own queries but the text keys and values. Say the query for region 1 is q=1q = 1, and the text keys are kdog=1k_{\text{dog}} = 1 and kruns=0k_{\text{runs}} = 0. The scores are 11 and 00.
  4. Turn scores into weights. A softmax gives weights e1/(e1+e0)≈0.731e^1 / (e^1 + e^0) \approx 0.731 for "dog" and 0.2690.269 for "runs". Check: the two weights sum to 1.
  5. Mix the text values. Let the text values be vdog=(2,0)v_{\text{dog}} = (2, 0) and vruns=(0,4)v_{\text{runs}} = (0, 4). The attended vector for region 1 is 0.731⋅(2,0)+0.269⋅(0,4)≈(1.46,1.08)0.731 \cdot (2, 0) + 0.269 \cdot (0, 4) \approx (1.46, 1.08). Region 1 now carries a mix of word information, weighted by how relevant each word is to it.
  6. Do the same in the other direction. The text stream uses its own queries with the visual keys and values, so each word picks up information from the regions. Both streams then add their results back to their own input, the residual connection, and continue.
  7. Repeat at chosen depths. The two streams can be different depths, and co-attention sits at a few chosen depths, not at every layer. Each stream therefore does its own processing and only meets the other at designated points.
flowchart TB
  subgraph V[Visual stream]
    direction TB
    v1[region features plus spatial code] --> v2[transformer blocks]
    v2 --> vc[co-attention layer: queries from regions, keys and values from words]
    vc --> v3[more transformer blocks]
  end
  subgraph W[Linguistic stream]
    direction TB
    w1[word embeddings plus positions] --> w2[12 transformer blocks]
    w2 --> wc[co-attention layer: queries from words, keys and values from regions]
    wc --> w3[more transformer blocks]
  end
  vc -. keys and values .-> wc
  wc -. keys and values .-> vc

The image representation is the output at a special IMG token, which stands for the whole image. The text representation is the output at the CLS token. Both are used in the pretraining and fine-tuning steps below.

The math

The paper writes the co-attention step in the usual transformer notation. For the visual stream at layer ii, with visual input HV(i)H_V^{(i)} and text input HW(j)H_W^{(j)}:

QV=HV(i)WQV,KW=HW(j)WKW,VW=HW(j)WVW,Q_V = H_V^{(i)} W_Q^V, \qquad K_W = H_W^{(j)} W_K^W, \qquad V_W = H_W^{(j)} W_V^W, Attn(QV,KW,VW)=softmax ⁣(QVKWTd)VW,\text{Attn}(Q_V, K_W, V_W) = \text{softmax}\!\left(\frac{Q_V K_W^T}{\sqrt{d}}\right) V_W,

where WQVW_Q^V, WKWW_K^W and WVWW_V^W are learned projection matrices, dd is the key dimension, and the softmax is taken over the words. The text stream does the same with the roles swapped.

Step 3 in symbols: the scores

The score matrix QVKWT/dQ_V K_W^T / \sqrt{d} has one row per region and one column per word. Dividing by d\sqrt{d} keeps the scores from growing with the dimension. In the tiny example, d=1d = 1 and the score for region 1 with "dog" is 1⋅1/1=11 \cdot 1 / 1 = 1.

Step 4 in symbols: the weights

The softmax of a row (s1,…,sT)(s_1, \dots, s_T) is est/∑uesue^{s_t} / \sum_{u} e^{s_u}, so each row of weights sums to 1. In the example the row is (1,0)(1, 0), and the weights are e/(e+1)≈0.731e / (e + 1) \approx 0.731 and 1/(e+1)≈0.2691 / (e + 1) \approx 0.269.

Step 5 in symbols: the mixed value

The attended output for region ii is ∑tαitvt\sum_t \alpha_{it} v_t, where αit\alpha_{it} is the weight of word tt for region ii and vtv_t is that word's value vector. In the example this is 0.731(2,0)+0.269(0,4)=(1.462,1.076)0.731 (2, 0) + 0.269 (0, 4) = (1.462, 1.076), rounded to (1.46,1.08)(1.46, 1.08).

The pretraining objectives

The first task, masked multi-modal modelling, masks about 15 percent of the words and of the image regions. A masked word is handled as in BERT and predicted from its context with Cross-Entropy Loss. A masked region has its features zeroed 90 percent of the time and is left alone 10 percent of the time. The model predicts a distribution over object classes for that region, and the target is the class distribution from the detector that produced the features. The loss is the Kullback–Leibler Divergence between the detector's distribution and the model's.

The second task, multi-modal alignment prediction, takes an image and a caption and predicts whether they match. The paper multiplies the two holistic vectors element-wise and applies a linear layer with a binary loss. Conceptual Captions contains only matching pairs, so the paper makes negatives by swapping the image or the caption with a random one. The two losses have equal weight.

Results

The paper fine-tunes ViLBERT on four tasks, each with a small new output head and end-to-end training. The main numbers from its Table 1 are below.

  • VQA 2.0 (test-dev): ViLBERT 70.55, against 70.22 for DFAF, the previous best. The single-stream baseline with pretraining reaches 68.85.
  • VCR (Q to A, QA to R, Q to AR): ViLBERT 72.42, 74.47 and 54.04, against R2C's 63.8, 67.2 and 43.1 on validation.
  • RefCOCO+ (val / testA / testB): ViLBERT 72.34, 78.52 and 62.61, against MAttNet's 65.33, 71.62 and 56.02.
  • Caption-based image retrieval on Flickr30k (R1 / R5 / R10): ViLBERT 58.20, 84.90 and 91.52, against SCAN's 48.60, 77.70 and 85.20.
  • Zero-shot retrieval, no fine-tuning (R1 / R5 / R10): 31.86, 61.12 and 72.80. This shows that the alignment head alone carries some grounding.

The ablations are as informative as the headline numbers. Removing pretraining (the model labeled ViLBERT with a dagger in the paper) costs between 2 and 13 percent across tasks. A single-stream model that shares one transformer for both modalities is consistently behind the two-stream version. The depth study shows that different tasks prefer different numbers of co-attention blocks: VQA improves from 69.92 with 2 layers to 70.55 with 6, while RefCOCO+ testA is best with 2 layers, at 78.61.

The limits are important. The visual features come from a detector trained on Visual Genome, so the model inherits that detector's vocabulary and its blind spots. The pretraining data is noisy: Conceptual Captions is scraped automatically from alt-text, and its captions are sometimes not human-like or short on detail. The fine-tuning tasks are benchmarks with their own annotation biases. The retrieval numbers come from one split of Flickr30k, so they measure one setting. And a gap such as 70.22 against 70.55 is small enough that training noise could account for it.

Reading guide

Check yourself

QuestionIn co-attention, which modality supplies the queries and which supplies the keys and values for the visual stream?Show answer
The visual stream uses its own queries and takes its keys and values from the text stream, so each region attends over the words.
QuestionIn the tiny example, the region query is 1 and the two word keys are 1 and 0. What are the attention weights, to three decimals?Show answer
The weights are e divided by (e + 1), about 0.731 for the word with key 1, and 1 divided by (e + 1), about 0.269 for the word with key 0. They sum to 1.
QuestionWhy does ViLBERT use a KL divergence for masked image regions instead of regressing the masked feature values directly?Show answer
Language usually names only the high-level semantics of an image region, so the model predicts a class distribution and matches the detector's distribution. Regressing exact feature values would ask it to recover detail the text does not specify.
QuestionA model with 12 text layers and co-attention at only a few depths is compared with one that shares a single stream for both modalities. Which design lets the two modalities keep different amounts of processing, and why does that matter here?Show answer
The two-stream design lets each modality have its own depth and meet the other only at chosen layers. Image regions already come from a deep detector, so they need less extra processing than words, and a single stream forces identical processing for both, which the paper argues is a poor fit.
QuestionViLBERT reaches 58.20 R1 on Flickr30k retrieval against SCAN's 48.60. Name one reason this comparison alone does not prove that ViLBERT grounds text better than all alternatives.Show answer
The retrieval numbers come from one Flickr30k split and one reported number per system, so the gain may depend on that setup rather than showing grounding in general.

Sources

  • Lu, Batra, Parikh, Lee, "ViLBERT: Pretraining Task-Agnostic Visiolinguistic Representations for Vision-and-Language Tasks," arXiv:1908.02265 (2019). https://arxiv.org/abs/1908.02265
  • Devlin et al., "BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding," arXiv:1810.04805 (2018). https://arxiv.org/abs/1810.04805

Read the full paper

Jiasen Lu, Dhruv Batra, Devi Parikh et al., 2019. arXiv:1908.02265