---
title: 'LXMERT: Vision-Language Transformer'
url: https://www.emergentmind.com/topics/lxmert
type: topic
---

# LXMERT: Vision-Language Transformer

LXMERT, short for *Learning Cross-Modality Encoder Representations from Transformers*, is a vision-and-language pre-training framework introduced to learn visual concepts, language semantics, and the alignment and relationships between the two modalities. Its defining design is a decomposition into an object-relationship encoder, a language encoder, and a cross-modality encoder, trained jointly on approximately \(9.2\) million image–sentence pairs using five pre-training objectives: masked language modeling, masked object prediction via feature regression and label classification, cross-modality matching, and image question answering. After fine-tuning, the model reported state-of-the-art results on VQA and GQA and improved the previous best result on NLVR\(^2\) from \(54\%\) to \(76\%\) absolute, making it a central reference point in subsequent vision-and-language research [1908.07490].

## 1. Conceptual motivation and problem formulation

LXMERT was proposed for vision-and-language reasoning tasks in which success depends not only on recognizing objects and parsing text, but also on learning correspondences between linguistic units and visual regions, together with higher-order relations internal to each modality. The original formulation therefore treats intra-modality structure and cross-modality alignment as distinct but coupled problems: visual features must exchange contextual information with other visual features, text tokens must exchange contextual information with other tokens, and both streams must subsequently interact through dedicated cross-attention layers [1908.07490].

This design places LXMERT within the family of region-based multimodal Transformers that use object proposals from a frozen detector rather than raw pixels. On the vision side, Faster-R-CNN supplies up to \(36\) region proposals in later analyses, each represented by pooled CNN features and bounding-box information; on the language side, the input is a tokenized sentence or question with standard BERT-style embeddings [2012.12352]. A plausible implication is that LXMERT’s reasoning behavior is conditioned by the granularity and biases of the detector: whatever is not surfaced as a region feature is difficult for the model to align, count, or compare.

The model was designed for discriminative multimodal tasks rather than generation. Its original downstream demonstrations focused on visual question answering and visual reasoning, and the paper explicitly noted that it does not generate language or localize text spans, but instead produces joint representations for classification-style heads [1908.07490].

## 2. Encoder architecture and cross-modal fusion

LXMERT consists of three Transformer-based components. The language encoder applies \(N_L\) layers of self-attention and feed-forward sublayers to the token sequence. The object-relationship encoder applies \(N_R\) analogous layers to region embeddings so that object features exchange contextual information. The cross-modality encoder then stacks \(N_X\) layers, each containing bidirectional cross-attention, modality-specific self-attention, and feed-forward layers with residual connections and LayerNorm as in *Attention is All You Need* [1908.07490].

In the original configuration, the language encoder has \(9\) layers, the object-relationship encoder has \(5\) layers, and the cross-modality encoder has \(5\) layers; later probing work describes the same architecture as a two-stream Transformer with a \(9\)-layer text encoder, a \(5\)-layer visual encoder, and a \(5\)-layer cross-modality encoder [2005.07310].

| Component | Depth | Function |
|---|---:|---|
| Language encoder | 9 layers | Self-attention over token embeddings |
| Object-relationship encoder | 5 layers | Self-attention over region embeddings |
| Cross-modality encoder | 5 layers | Bidirectional cross-attention plus self-attention |

The language input embeds each token \(w_i\) with WordPiece and positional embeddings:
\[
\hat w_i = \mathrm{WordEmbed}(w_i),\quad
\hat u_i = \mathrm{PosEmbed}(i),\quad
h_i^0=\mathrm{LayerNorm}(\hat w_i+\hat u_i).
\]

The vision input begins with Faster-R-CNN region-of-interest features \(f_j\in\mathbb R^{2048}\) and bounding-box coordinates \(p_j\in\mathbb R^4\), projected into a position-aware embedding:
\[
\hat f_j=\mathrm{LayerNorm}(W_f\,f_j+b_f),\quad
\hat p_j=\mathrm{LayerNorm}(W_p\,p_j+b_p),\quad
v_j^0=\tfrac12(\hat f_j+\hat p_j).
\]

Each cross-modality layer performs bidirectional attention:
\[
\widetilde h_i^k
=\mathrm{CrossAtt}_{v\to h}(h_i^{k-1},\{v_j^{k-1}\}_{j=1}^m),\quad
\widetilde v_j^k
=\mathrm{CrossAtt}_{h\to v}(v_j^{k-1},\{h_i^{k-1}\}_{i=1}^n).
\]

The final joint representation of an image–sentence pair is the hidden state of a prepended \([{\rm CLS}]\) token, while the model also exposes token-level and region-level hidden states for auxiliary heads and downstream adaptation [1908.07490].

Later analyses emphasize that this architecture enforces explicit cross-modal interaction. VALUE reported that a subset of cross-modality heads specializes in bridging the two streams and that the learned attention matrices exhibit region–word alignment structure coherent with latent correspondences in the data [2005.07310].

## 3. Pre-training objectives and optimization regime

LXMERT is pre-trained on approximately \(9.2\) million image–sentence pairs drawn from MS COCO, Visual Genome captions, VQA, GQA, and VG-QA. The pre-training objective is the sum of five losses, each designed to target either intra-modality structure or cross-modality association [1908.07490].

The masked language modeling objective masks each input token with probability \(0.15\):
\[
\mathcal L_{\rm MLM}
= -\sum_{i\in\mathcal M_L}
\log P\bigl(w_i=w_i^*\mid h_i^{N_X}\bigr).
\]

Masked object prediction is split into feature regression and label classification. For feature regression, the model zeros out the RoI embeddings for \(15\%\) of objects and reconstructs the original \(2048\)-dimensional features:
\[
\mathcal L_{\rm MOP}^{\rm feat}
= \sum_{j\in\mathcal M_V}
\bigl\lVert\,f_j^* - \hat f_j\bigr\rVert_2^2.
\]

For object-label classification:
\[
\mathcal L_{\rm MOP}^{\rm cls}
= -\sum_{j\in\mathcal M_V}
\log P\bigl(y_j=y_j^*\mid v_j^{N_X}\bigr).
\]

Cross-modality matching corrupts \(50\%\) of image–sentence pairs by replacing the sentence and trains a binary match–mismatch decision on \(h_{\rm CLS}\):
\[
\mathcal L_{\rm Match}
= -\bigl[
\mathbbm1_{\rm match}\log p_{\rm match}
+ (1-\mathbbm1_{\rm match})\log(1-p_{\rm match})
\bigr],
\]
where \(p_{\rm match}=\sigma(w^\top h_{\rm CLS}+b)\).

On the one-third of pre-training examples drawn from VQA, GQA, and VG-QA, LXMERT also predicts an answer from a joint vocabulary of approximately \(9500\) answers:
\[
\mathcal L_{\rm QA}
= -\sum_{k=1}^{K}\mathbbm1[a^*=k]\,
\log P(a=k\mid h_{\rm CLS}).
\]

The full loss is
\[
\mathcal L
=
\mathcal L_{\rm MLM}
+
\mathcal L_{\rm MOP}^{\rm feat}
+
\mathcal L_{\rm MOP}^{\rm cls}
+
\mathcal L_{\rm Match}
+
\mathcal L_{\rm QA},
\]
with all weights set to \(1\) in the original paper [1908.07490].

This pre-training recipe is central to LXMERT’s identity. Subsequent probing work characterizes the same scheme in slightly different notation, but consistently preserves the four major functional groups—MLM, masked object prediction, image–text matching, and VQA—and treats their joint optimization as the mechanism by which contextualized multimodal representations acquire both alignment structure and task-relevant priors [2005.07310].

## 4. Fine-tuning protocols, benchmark results, and ablations

After pre-training, LXMERT transfers all Transformer and embedding parameters while keeping the Faster-R-CNN frozen. Fine-tuning is task-specific but remains lightweight relative to pre-training, typically adding only a small classifier or MLP on top of \(h_{\rm CLS}\) [1908.07490].

| Benchmark | Fine-tuning setup | Reported result |
|---|---|---|
| VQA v2.0 | Linear classifier to 3129 answers | 72.5% test-standard |
| GQA (balanced) | Linear classifier to 1834 answers | 60.3% test-standard |
| NLVR\(^2\) | Encode \((I_0,s)\) and \((I_1,s)\), concatenate, 2-layer MLP | 76.2% accuracy, 42.1% consistency |

For VQA v2.0, the model is fine-tuned for \(L=4\) epochs with batch size \(32\) and learning rate in \(\{1e{-}5,5e{-}5\}\), reaching \(72.5\%\) overall accuracy on test-standard versus \(70.4\%\) prior state of the art. For GQA, using the same protocol and training on train+val while validating on test-dev, it reaches \(60.3\%\) test-standard versus \(57.1\%\) prior state of the art. For NLVR\(^2\), each example contains two images and a statement; LXMERT encodes \((I_0,s)\) and \((I_1,s)\) separately to obtain \(x_0,x_1\), concatenates them, and applies a two-layer MLP with GeLU+LayerNorm, yielding \(76.2\%\) accuracy and \(42.1\%\) consistency on the unreleased test set, compared with \(54\%/12\%\) prior results [1908.07490].

The ablation studies clarify which components matter. Replacing cross-modal pre-training with a \(9\)-layer slice of BERT plus cross-attention layers yields only approximately \(65\)–\(66\%\) VQA accuracy, whereas pre-training LXMERT from scratch yields approximately \(69.9\%\) on VQA dev and initializing from BERT gives \(68.8\%\). Removing both masked-object tasks drops VQA to \(66.3\%\), while keeping only feature regression or only label classification recovers approximately \(69.2\)–\(69.5\%\). Pre-training \(20\) epochs without QA tasks yields \(68.9\%\) VQA, whereas \(10\) epochs of standard tasks plus \(10\) epochs with QA yields \(69.9\%\). Without pre-training, increasing cross-attention depth improves VQA only up to approximately \(66.5\%\) before plateauing; the full \(5\)-layer cross-modal pre-training is required to reach the reported \(72.5\%\) level [1908.07490].

These results support a narrow but important conclusion: LXMERT’s performance is not reducible to importing BERT into a multimodal pipeline. The dedicated cross-modality pre-training tasks contribute substantially beyond unimodal language initialization.

## 5. Attention structure, interpretability, and representational content

The original paper visualized cross-attention patterns showing that nouns in the question attend strongly to corresponding RoIs, pronouns such as “it” and “them” reuse the attended region for coreference, and even small function words can operate as hubs focusing on globally salient objects. In the reverse direction, vision-to-language attention often highlights the noun that best describes a region, such as a pizza region attending to “pizza” and a table region attending to “table” [1908.07490].

Later probing work made these observations more systematic. VALUE found that a small subset of heads in LXMERT’s cross-modality encoder devote more than \(50\%\) of their mass to cross-attention, with head \((2\!-\!8)\) in layer \(2\) attending vision\(\to\)text on more than \(90\%\) of examples. On Flickr30k Entities, head \((3\!-\!4)\) in layer \(3\) achieved a V\(\to\)T mean attention of \(0.235\) for “animals,” compared with approximately \(0.075\) random. On Visual Genome relation probes, the relation “wearing” attained \(0.230\) in the two-stream architecture versus \(0.055\) random, indicating that the fusion layers also register purely visual relations [2005.07310].

The same study reported that LXMERT’s first \(9\) text self-attention layers encode nontrivial linguistic structure, reaching \(83.8\%\) on SubjNum and \(75.6\%\) on Tense in SentEval, although both numbers remain below UNITER and BERT. At the same time, modality-importance probing showed that the \([{\rm CLS}]\) token attends approximately \(75\%\) to text versus \(25\%\) to image on average, and mismatched image–text pairs can corrupt visual relation reasoning through cross-attention [2005.07310].

This combination of findings suggests a characteristic representational profile: LXMERT learns interpretable region–phrase alignments and some scene-graph-like structure, but its final decision process remains text-heavy. Strong cross-modal attention is therefore not equivalent to balanced multimodal use.

## 6. Limitations, failure modes, and targeted probes

The original work already identified several practical limitations: pre-training cost of approximately \(10\) days on \(4\) GPUs, dependence on a frozen R-CNN detector, a fixed set of \(36\) RoI tokens that may miss small or non-object cues such as textures or scene-level information, and the absence of generative language or span localization capabilities [1908.07490].

Subsequent targeted evaluations exposed sharper failure modes. On image–text discrimination, LXMERT performs strongly in zero-shot settings, reaching \(85.5\%\) accuracy on MSCOCO with precision\(_+\) \(=71.5\%\) and precision\(_-\) \(=99.6\%\), but on counting it performs poorly. Using the image–text alignment head in declarative format, it reaches only \(54.7\%\) overall accuracy on a standard split and \(52.3\%\) on a hard balanced split; with the VQA head fine-tuned on VQA v2.0, counting accuracy is \(53.9\%\) on the standard split and \(41.8\%\) on the hard split. In an interpolated split that trains on even counts and tests on odd counts, pairwise accuracy falls to approximately \(17\%\), far below chance [2012.12352].

The same counting study attributes these results to several factors: evidence of catastrophic forgetting on image–text matching after VQA fine-tuning, heavy reliance on dataset bias, and failure to individuate entities in the visual input. Although LXMERT avoids the classical attention bottleneck through its dual-stream and co-attention design, the use of up to \(36\) pooled object proposals prevents faithful counting of large or overlapping sets [2012.12352].

A related challenge concerns positional information. A dedicated case study showed that positional information is present in LXMERT’s representations and recoverable by probes: with no positional input, probe accuracy is \(80\%\); adding \((x,y)\) centers raises it to approximately \(88.5\%\); full boxes \((x_1,y_1,x_2,y_2)\) yield approximately \(88.7\%\); and adding depth reaches approximately \(89.7\%\). Yet improved positional probing translates only weakly to downstream GQA, where top-1 accuracy shifts by only approximately \(0.5\)–\(1\%\), and the model is not capable of leveraging positional information for image–text matching on a challenge set where only position differs [2305.10046].

Taken together, these studies distinguish representational availability from functional use. Information may be linearly decodable from hidden states without being reliably exploited during cross-modal reasoning.

## 7. Variants, simplifications, and later adaptations

LXMERT became a substrate for multiple lines of subsequent work. One direction simplified the model. LXMERT-S removes both the language encoder and the object-relationship encoder and feeds text and region embeddings directly into a \(5\)-layer cross-modality encoder, reducing the parameter count from approximately \(183.5\)M to approximately \(84.3\)M, or \(45.9\%\) of the original. Combined with Multi-stage Pre-training (MSP), this smaller model uses only \(1.08\)M pre-training pairs, or \(11.76\%\) of the original data, yet reports \(72.30\) VQA-V2 test-std, \(60.10\) GQA test-std, and \(75.10\) NLVR2 test-p, while also outperforming the original model on zero-shot Flickr30K retrieval [2107.14596].

A second direction extended LXMERT toward generation. X-LXMERT replaces continuous visual regression with discrete visual token prediction, adopts uniform masking over image tokens, and aligns objectives with datasets. On COCO caption-conditioned image generation, it reports Inception Score \(22.7\) versus \(1.6\) for a grid-based LXMERT baseline, FID \(37.4\) versus \(316.7\), and R-Precision-hard \(25.1\) versus \(6.6\). On discriminative tasks it remains comparable rather than identical to LXMERT, reaching \(68.7\%\) on VQA2.0 test-std compared with \(72.4\%\) for the original region-based model [2009.11278].

A third line adapted LXMERT to conversational multimodal coreference. In the SIMMC 2.0 challenge, a shallower variant with \(5\) language layers, \(3\) vision-relationship layers, and \(3\) cross-modality layers, together with object descriptions derived from Detectron2 outputs, reached \(57.4\%\) object F1 on devtest and \(57.3\%\) on hidden test-std. Ablations showed that removing the user utterance reduced F1 from \(60.83\%\) to \(33.72\%\), removing natural-language descriptions reduced it to \(54.50\%\), and removing RoI features reduced it to \(57.44\%\), indicating that language dominates and that descriptions help more than pure vision in that setting [2202.12645].

These later developments show both the flexibility and the constraints of the original design. LXMERT can be compressed, staged, or repurposed for generative and dialog settings, but many of the most successful modifications either reduce dependence on the original region pipeline or add objectives tailored to phenomena that the original pre-training distribution underemphasized.

Source: https://www.emergentmind.com/topics/lxmert