Transformers were originally built for language, but their self-attention mechanism generalizes well beyond text. The multimodal Transformers discussed in the previous post remains its Transformer architecture when processing multimodal data, such as texts and images, where image region representations are typically generated through the following methods:
This post walks through how the Transformer Encoder has been adapted to process images directly. It starts with the Vision Transformers (ViT), the breakthrough model that treats an image as a sequence of patches and learns visual representations through a Transformer encoder with minimal modifications. It then extends to Vision-Language Transformers such as ViLT, ALBEF, and VLC, which use ViT to encode images into visual tokens and fuse them with word tokens within a shared Transformer architecture. Finally, it covers Video Transformers such as VideoBERT and ActBERT, which directly process sequences of frames rather than ViT-based image patches.
Convolutions and self-attention share one strength: both can be computed in parallel across positions, unlike recurrent models. But they trade off different weaknesses. A convolution uses a small, static kernel, so capturing long-range dependencies requires stacking many layers. Self-attention instead lets every position dynamically weight every other position in a single layer, which gives it long-range context immediately, but it has no inductive bias toward locality the way a convolutional kernel does.
The inductive biases of locality and weight sharing in CNNs assume that useful visual features are local and translation invariant, allowing the same/fixed convolutional filters to be applied across the entire image.
Self-attention can be formulated as a form of convolution. For each target pixel, its query is compared against the keys of its neighboring pixels to see how well they match, and the resulting softmax attention weights act as dynamic convolution kernel weights, combining the corresponding values of its neighboring pixels into a contextualized output.
However, without extra information, attention has no sense of where each neighbor sits relative to the query. The standard fix is a 2D relative position embedding that gets added directly into the computation, so attention scores reflect both content similarity and spatial offset.
Vision Transformer (ViT) removes standard convolutions entirely and instead relies on self-attention as dynamic convolution kernels to contextualize each pixel with all the other pixels dynamically. It first splits an image into fixed-size patches (e.g., 16×16). Each patch is flattened and linearly projected into an embedding vector, to which a learnable position embedding is added. Similar to BERT’s [class] token, a learnable [class] token is prepended to the sequence, and the whole sequence is then processed by a standard Transformer encoder. Finally, the output representation of the [class] token is passed to an MLP head for image classification.

According to the paper, early experiments with ViT showed that, without large-scale pre-training and only trained on mid-sized datasets such as ImageNet, it lagged behind comparably-sized ResNets by a few percentage points in accuracy. The authors attributed this gap to the lack of inductive biases inherent to CNN, such as translation invariance and locality. ViT outperformed ResNets only after being pretrained or trained on large-scale datasets (14M - 300M images).

Interpretability studies of trained ViT models show a few consistent patterns:
Masked Autoencoders (MAE) applies a BERT-style masking objective to ViT. A large random subset of patches (e.g., 75%) is masked, and only the remaining small set of visible patches is passed into the ViT encoder. A lightweight transformer decoder, used only during pretraining, takes the full set of encoded patches and the masked tokens as input and reconstructs the original image. The model is trained using a reconstruction loss over the entire image.
According to the authors' experiments, the pretrained encoder exhibits the following behavior on downstream tasks as the masking ratio varies:
Because so few patches are visible during pretraining, the encoder is forced to learn genuinely holistic representations rather than relying on nearby pixels.

Vision-Language Transformers must decide how to represent images before fusing them with text. This section introduces some models that use ViT to encode images into visual tokens before combining them with word tokens.
ViLT (≈ BERT + ViT) encodes an input image into visual patch tokens using ViT and processes them together with word tokens in a shared Transformer Encoder architecture. Its pretraining objectives include image-text matching, masked language modeling, and word-patch alignment via optimal transport, which encourages individual words to align with the image regions they describe.

ALBEF (≈ BERT + ViT + Contrastive Learning) consists of 2 unimodal Transformer encoders and 1 multimodal Transformer encoder. The visual encoder is ViT, while the text encoder is a typical Transformer encoder. The visual and word tokens are fused via cross-modal attention in the multimodal Transformer encoder.
It has 3 pre-training objectives:
In addition, since the image-text pairs used for pre-training are often noisy, such that positive-pairs are usually weakly-correlated, a Momentum Distillation (MoD) model is proposed and used to generate pseudo-targets for both original image and text inputs. Momentum Distillation (MoD) is a momentum version of the base model (2 unimodal Transformer encoders + 1 cross-modal Transformer model ) by taking the moving-average of its parameters. During training, the unimodal encoders from the base model learn to match the pseudo outputs generated by those of the momentum model, providing more reliable supervision despite the noisy image-text pairs.

Vision-Language from Captions (VLC) extends Masked Autoencoders (MAE) to learn multi-modal representations. It first randomly masks image and word tokens, then concatenates them before feeding them into a shared multimodal Transformer encoder with 3 task-specific decoder heads. The model is pretrained using three objectives:

Processing sequences of frames in a video, however, runs into a problem: large-scale, precisely-labeled video-text pairs are far scarcer than image captions. The solution used across this line of work is to lean on weakly-paired data instead, such as instructional videos with automatically generated subtitles.
VideoBERT extends BERT to the video domain by representing a sequence of video frames as a sequence of visual words. For each video, it first samples frames at 20 fps to partitions the video into a sequence of non-overlapping 30-frame video clips. Each 30-frame video clip is fed into a pretrained separable 3D CNN (S3D), a video convolution network, to extract a 1024-dimensional feature vector. Hierarchical k-means is then applied to tokenize/cluster all the 1024-dimensional feature vectors into 20,736 discrete clusters, each of which represents a visual token.
These visual tokens are then concatenated with text tokens to form a single input sequence, and the resulting sequence is passed through a pretrained embedding layer to get a sequence of spoken words and visual words, which are then processed by a shared BERT model. The model is pretrained using the following BERT-style objectives:
[CLS] token.
ActBERT builds on VideoBERT by explicitly modeling actions as a separate token type. Its input sequence consists of 3 kinds of token embeddings: word token embedding, action token embeddings, and visual token embeddings.
To obtain action embeddings, the model first extracts verbs from its corresponding text descriptions for all video clips to build an action vocabulary bank. It then pretrains a 3D CNN to classify each video clip based on the actions shown in the corresponding descriptions. Action embeddings are extracted from video clips using the pretrained 3D CNN.
For visual embeddings, ActBERT uses a pretrained Faster R-CNN to generate region proposals. For each region, its normalized bounding-box coordinates are assembled into a vector and passed through an embedding layer to produce a spatial position embedding, which is then added to the corresponding region feature vector to form the visual embedding. Finally, for word embeddings, ActBERT embeds the text descriptions using WordPiece embeddings.
ActBERT uses the proposed TaNgled Transformer (TNT), which consists of 3 Transformers. The 3 Transformers separately process the word, action, and visual token embeddings respectively, while every pair of Transformers is connected through cross-modal interaction, enabling information to be exchanged across them.
There are 4 pretraining objectives for ActBERT :
[CLS] token.
Self-attention can be formulated as convolution with dynamic-weight kernels.
However, replacing convolutions with self-attention drops the translation invariant convolutions naturally have.
ViT's patch embedding and MAE's aggressive (~70%) masked reconstruction technique both show that treating an image as a sequence of tokens and then pretraining on large-scale datasets can produce representations that transfer well and scale with compute.
Whether combining images and texts (ViLT, ALBEF, VLC) or videos and text descriptions (VideoBERT, ActBERT), the recurring pattern is to first represent inputs as a sequence of token embeddings, feed token embeddings to Transformer model, and pretrain with BERT-style objectives.