Skip to content

Fusion encoders: VisualBERT, ViLBERT, LXMERT, UNITER and OSCAR

Models that let words and image regions attend to each other: one shared stream or two streams with co-attention, pretraining task mixtures, word–region alignment by optimal transport, and object tags as anchors.

Advanced ~17 min10 steps

What runs in CodeSplash

You will be able to

  • Contrast single-stream and two-stream fusion encoders
  • Trace co-attention between a text stream and a visual stream
  • List the pretraining tasks fusion encoders combine and why their weights matter
  • Explain how optimal transport and object tags align words with regions

Read first

01

Let the two sides talk

Read

A dual encoder compares an image and a text only as two finished vectors. A fusion encoderFusion encoderA Transformer that lets text tokens and image regions attend to each other, in one stream or two streams with co-attention. lets every word attend to every image region inside one Transformer, so it can check that "the red cup" refers to the cup that is red, not to some red thing and some cup.

Between 2019 and 2020 a family of such models appeared. Most read the image as region featuresRegion featuresImage features taken from an object detector's boxes and used as visual tokens, often with the detected class names.: the boxes and feature vectors of a pretrained object detector, so the detector's vocabulary and mistakes come along.

Attention weights, masks and heads, the mechanism the two sides talk through.

DExplorable · Attention: scores, masks and heads

Where does each word look, and what do the scaling and the masks change?

With this mask, how much of each word's attention lands on <pad>?

How sure?
6
2

How many of the positions are <pad>.

Width d

Heads

Mask

Without masks or positions the output rows shuffle the same way.

.51.22.16.11.00.00.27.55.07.10.00.00.02.10.59.28.00.00.26.71.02.01.00.00.09.09.69.13.00.00.42.54.03.01.00.00thecatsaton<pad><pad>thecatsaton<pad><pad>
  • Little weight
  • Most weight
  • Masked: score set to −∞

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

02

One stream: VisualBERT

Read
Reference · MM004 · Explained hereVisualBERTUses one transformer stack to jointly process text tokens and image-region representations. It is a useful baseline for understanding early fusion and transfer from image-caption pretraining to visual question answering…

VisualBERT puts word tokens and region features into one sequence and runs a BERT-style Transformer over it. Plain self-attentionSelf-attentionEach token builds its next value as a weighted mix of all tokens, with weights from how well their keys match its query. then mixes the two modalities from the first layer: early fusion.

In the program, two word tokens and two region tokens attend to all four. The first word's output becomes the mix 0.654 and 0.346 of the two feature directions: it has drawn on the region that resembles it. Pretraining used captions with masked words and image–caption matching.

03

Two streams: ViLBERT

Read
Reference · MM005 · Explained hereViLBERTProcesses image regions and text in separate streams that communicate through co-attention. This distinguishes modality-specific representation learning from the cross-modal exchange and supports transfer to retrieval,…

ViLBERT keeps a text stream and a visual stream, each with its own layers, and connects them with co-attention: in those layers each stream's queries attend to the other stream's keys and values, a form of cross-attentionCross-attentionAttention whose queries come from one sequence and keys and values from another, such as text reading image features..

In the program, three visual tokens read two words. The middle visual token resembles both words equally, so it splits its attention 0.500 and 0.500; the outer ones lean toward their look-alike word, 0.587 against 0.413. Separate streams let each modality keep its own depth before mixing.

05

LXMERT: a mixture of tasks

Read
Reference · MM006 · Explained hereLXMERTLearns within-modality and cross-modality relationships through multiple pretraining tasks. It explicitly separates a language encoder, an object-relationship encoder and a cross-modal encoder, making its task mixture…

LXMERT has three encoders: language, objects, and a cross-modal one with co-attention. It pretrained on five tasks at once: masked words, masked region features (regress them), masked region classes (predict the detector's label), image–text matching, and visual question answering.

The program lists five task losses and combines them with weights into 3.35. Those weights are design choices, not facts: change them and the model learns different things. Report them when comparing models.

06

UNITER: align words and regions

Read
Reference · MM007 · Explained hereUNITERBuilds a shared image-text representation using conditional masking and both global and fine-grained alignment. Its word-region alignment objective uses optimal transport to connect language tokens with visual regions.

UNITER is single-stream like VisualBERT, with two changes. It masks only one modality at a time, so a masked word is always predicted from the complete image. And it adds word–region alignment by optimal transport: find the cheapest plan that moves the words' "mass" onto the regions, and train to lower that cost for matching pairs.

In the program two words and two regions have a cost matrix favoring the diagonal; the best plan sends half the mass along each diagonal pair, at transport cost 0.15.

07

OSCAR: object tags as anchors

Read
Reference · MM008 · Explained hereOSCARUses detected object tags as semantic anchors between image regions and language. Rather than relying entirely on unstructured joint attention to discover correspondence, it supplies a lexical link derived from object…

Words and region features live in different spaces, so aligning them is hard to learn. OSCAR adds a third input: the detector's object tags written as words ("dog", "bicycle"). A caption word and a tag are both text, so they align easily, and the tag points at its region.

In the program the caption "a dog beside a bicycle" is checked against the tags dog, bicycle and person: the second and fifth words each match one tag, and "person" matches nothing. Real models learn softer matches than string equality, but the anchor idea is the same, and so is the limit: an object the detector didn't tag gets no anchor.

08

What runs here

Read
09

Check: fusion encoders

Checkpoint

Check yourself

How does VisualBERT combine text and image?

Show the answer

Answer: a

That's single-stream, early fusion. Every layer can relate any word to any region.

Check yourself

VisualBERT reads images as region features from a pretrained detector. What follows?

Show the answer

Answer: a

The detector's vocabulary and errors become the fusion model's. Later models moved to patch features to avoid this.

Check yourself

In ViLBERT's co-attention layers, where do the text stream's keys and values come from?

Show the answer

Answer: b

Each stream asks questions of the other: that's co-attention, two cross-attentions in opposite directions.

Check yourself

What does a two-stream design like ViLBERT allow that a single stream doesn't?

Show the answer

Answer: a

Region features and words have very different statistics; separate streams let each be processed in its own way.

Check yourself

Which of these was NOT one of LXMERT's pretraining tasks?

Show the answer

Answer: d

LXMERT is an encoder: it predicts words, regions, matches and answers, but doesn't generate images.

Check yourself

Two papers pretrain the same architecture with the same five tasks but different task weights. What should you expect?

Show the answer

Answer: b

A task mixture's weights decide what the shared encoder prioritizes. Without them, results can't be compared fairly.

Check yourself

What does UNITER's word–region alignment loss compute?

Show the answer

Answer: a

A low transport cost means words and regions pair up cheaply, which training encourages for matching image–text pairs.

Check yourself

Why does UNITER mask only one modality at a time during pretraining?

Show the answer

Answer: a

If words and regions were masked together, the model might lose the very evidence that would let it use the other modality.

Check yourself

What role do object tags play in OSCAR?

Show the answer

Answer: a

A word and a tag share the text space, so they align easily; the tag then points at its region.

Check yourself

A caption mentions a "kite", but the detector found no kite. What does OSCAR's anchor mechanism provide for that word?

Show the answer

Answer: b

Anchors only help for objects the detector tags. Missing tags are a quiet source of error.

10

Recap

Recap
  • Fusion encoders let words and regions attend to each other; they check details dual encoders blur, at one forward pass per pair.
  • Single stream (VisualBERT, UNITER, OSCAR) mixes everything early; two streams (ViLBERT, LXMERT) exchange information by co-attention.
  • Pretraining mixes tasks (masked words and regions, matching, QA); the task weights are design choices.
  • UNITER aligns words and regions by optimal transport; OSCAR anchors them with detector tags, which inherit the detector's blind spots.

Concepts in this lesson