Image as a Foreign Language: BEiT Pretraining for All Vision and Vision-Language Tasks
- Publication
- CVPR 2023Conference
- First submitted to arXiv
- arXiv:2208.10442
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{multimodalitybeitv32022,
title = {{Image as a Foreign Language: BEiT Pretraining for All Vision and Vision-Language Tasks}},
author = {Wenhui Wang and Hangbo Bao and Li Dong and Johan Bjorck and Zhiliang Peng and Qiang Liu and Kriti Aggarwal and Owais Khan Mohammed and Saksham Singhal and Subhojit Som and Furu Wei},
year = {2022},
eprint = {2208.10442},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2208.10442}
}
Everyone knows that BEiT’s signature feature is the "discrete coding."
So, upon encountering this paper, we instinctively expect BEiT-3 to introduce some novel "discrete coding" techniques.
However, BEiT-3 uses discrete visual targets from BEiT v2 instead of inventing a new tokenizer. Its main question is: How can we pretrain on text, images, and image–text pairs under one objective?
That said, reminiscing about past successes is only natural—let’s not dwell too much on it.
Defining the Problem
The idea of "pretraining images and text together" is no longer groundbreaking.
Earlier methods often used several pretraining objectives at once, such as image–text contrastive learning, image–text matching, language modeling, or masking. Retrieval itself is a downstream task in this comparison.
If it doesn’t ring a bell, let’s revisit the BLIP framework we studied earlier:
This image is BLIP's Figure 2, included for comparison. Its image and text branches learn cross-modal relationships through ITC, ITM, and LM. This works, but managing several objectives and modes becomes more involved as models and data grow.
Since images can be split into patches and text can be tokenized, why not use one masked-prediction framework? Treating images as another “language” is the author's metaphor; image patches remain a distinct input modality.
Previous researchers have undoubtedly considered this. However, the lack of an effective framework suggests that there are inherent challenges.
The authors believe that we should address this issue with a "multi-path architecture."
Problem Solving
Model Architecture
The multi-path architecture follows VLMo's Mixture-of-Modality-Experts idea: share self-attention but use modality-specific feed-forward networks. VLMo applied this design to multimodal pretraining before BEiT-3.
Thus, BEiT-3's architecture directly references VLMo's Multiway Transformers.
Each Multiway Transformer module consists of shared self-attention and modality-specific feed-forward networks (FFNs). The input modality and chosen model configuration determine the expert path; this is not Switch Transformer's learned token-by-token routing.
In the authors' implementation, each layer includes a vision expert and a language expert; in addition, the top three layers are configured with vision-language experts for the fusion encoders.
Using a set of modality experts allows the model to capture more information specific to each modality. The shared self-attention module learns the alignment between different modalities and performs deep fusion in multimodal tasks (such as vision-language).
Multimodal Adaptation
As shown in the figure above, the authors demonstrate BEiT-3's "shared Multiway Transformer" architecture, which can "flexibly switch" or "combine" into the required model form for different downstream tasks.
- (a) Vision Encoder: Used for visual tasks that require only image feature representations, such as image classification, object detection, instance segmentation, and semantic segmentation.
- (b) Language Encoder: Exposes the text-only route; the paper's diagram illustrates masked language modeling, not measured text-classification or dialogue results.
- (c) Fusion Encoder: Used for tasks that require deep interaction between images and text, such as Visual Question Answering (VQA), Visual Reasoning (NLVR2), image-text reasoning, where both image and text need to be "seen" simultaneously for integrated understanding.
- (d) Dual Encoder: Used for efficient image–text retrieval, representing candidates separately. The contrastive loss drawn here belongs to retrieval fine-tuning, not the masked pretraining stage.
- (e) Sequence-to-Sequence Learning: Used for image captioning. During fine-tuning, an attention mask lets caption text see the image and preceding text while predicting masked caption tokens; at inference it generates words in order.
Whether the task needs image encoding, text encoding, fusion, retrieval, or generation, the backbone can be configured for it. Task-specific heads and fine-tuning still differ: VQA, for example, uses a classifier over the 3,129 most frequent training answers.
Pre-training Tasks
During the pre-training process of BEiT-3, the model randomly masks some of the text tokens or image patches and trains the model to recover these masked tokens. This method helps the model learn the representations of text and images while also capturing the correspondence between them.
During training, SentencePiece tokenizes text. The image input is patch embeddings; a BEiT v2 tokenizer supplies discrete visual prediction targets for masked patches. The authors mask 15% of text-only tokens, 50% of text tokens in image–text pairs, and 40% of image patches with blockwise masking.
BEiT-3 uses a pretraining batch of 6,144, smaller than the paper's cited contrastive-model batches of 65k for CoCa, 32k for CLIP, and 24k for Florence. These are different model configurations.
Model and Training Data
BEiT-3 has about 1.9 billion (1.9B) parameters: 692 million in vision FFNs, 692 million in language FFNs, 52 million in vision–language FFNs, and 317 million in shared attention. The architecture draws from ViT-giant. A vision-only pass activates roughly 1B vision-related parameters, although the full model still contains all routes.
The model consists of 40 layers of Multiway Transformer. Each layer has a hidden dimension of 1408, an intermediate layer dimension of 6144, and 16 attention heads. Each layer contains both a "vision expert" and a "language expert." Additionally, the top three layers of the Multiway Transformer incorporate "vision-language experts" for deeper cross-modal fusion.
BEiT-3 uses both "unimodal" and "multimodal" data for pre-training. Unimodal data refers to data containing only "pure images" or "pure text," while multimodal data refers to "image + text" pairs.
Multimodal data sources: There are about 15 million images and 21 million image-text pairs from five public datasets: Conceptual 12M (CC12M), Conceptual Captions (CC3M), SBU Captions (SBU), COCO, and Visual Genome (VG).
Unimodal data includes 14 million images from ImageNet-21K and 160GB of text data, sourced from English Wikipedia, BookCorpus, OpenWebText, CC-News, and Stories.
Training Strategy
BEiT-3 pre-training lasts for 1 million steps. Each training batch consists of 6144 samples, including: 2048 images, 2048 text samples, and 2048 image-text pairs.
Images use 14×14-pixel patches at 224×224 resolution during pretraining. The image augmentation follows BEiT, including random resized cropping, horizontal flipping, and color jitter.
The text tokenizer used is SentencePiece, with a vocabulary size of 64k.
Other hyperparameters include:
- AdamW optimizer, with hyperparameters: .
- Learning rate schedule uses cosine annealing, with a maximum learning rate of 1e-3, reaching this peak learning rate after 10,000 steps.
- Weight decay is set to 0.05.
- Random depth technique is applied with a probability of 0.1 to reduce overfitting and enhance model generalization.
Discussion
Comparison with Other Models
The authors performed extensive evaluations of BEiT-3 on various public benchmarks for vision-language and vision tasks.
BEiT-3 exceeds selected earlier results on several of the charted vision and vision–language benchmarks. The radar axes use different metrics and scales; the enclosed area is not a single overall score. Model, data, and fine-tuning conditions also vary across the cited comparisons. The detailed table is below:
Table 1 reports ADE20K mIoU 62.8, COCO box AP 63.7 and mask AP 54.8, ImageNet top-1 89.6, VQAv2 84.0, NLVR2 92.6, COCO caption CIDEr 147.6, and retrieval average R@1. The ImageNet † comparison is limited to public resources; the captioning ‡ result does not use CIDEr optimization. Retrieval R@1 averages image-to-text and text-to-image directions. The retrieval headline also includes intermediate contrastive fine-tuning, a stage after masked pretraining.
For COCO 5K retrieval, Table 5 reports 84.8 / 67.2 R@1 in the two directions, averaging 76.0. Appendix Table 10 shows 82.7 / 65.1 after direct downstream fine-tuning and 84.8 / 67.2 after the added intermediate stage. Flickr30K “zero-shot” means no Flickr30K labels, but that intermediate fine-tuning on the pretraining image–text pairs has already occurred. So the one masked pretraining objective and the later retrieval loss should be counted separately.
Module Contribution Analysis
The paper does not separately ablate data scale, Multiway experts, and the masked objective to measure each one's contribution. Appendix Table 10 does compare retrieval with and without intermediate contrastive fine-tuning. That still leaves us unable to rank all of the components, so the following is my qualitative reading:
-
Is the "large amount of data" the core contribution?
BEiT-3 pre-trains on a large-scale unimodal and multimodal dataset, including 14M ImageNet-21K images, 160GB of text data, and 15M image/21M image-text pairs.
Large datasets can matter for large-model performance, but this paper does not isolate their contribution. The authors emphasize using academically accessible data rather than proprietary collections. Some listed scores exceed earlier models using private data, but the comparisons also differ in model size and fine-tuning.
The vast data provides a foundation, but it is not the only innovation. The true focus of the paper is on "the unity and effectiveness of the method."
-
The Expert Model Architecture
Every Transformer layer has vision and language FFNs; only the top three also have a vision–language FFN. The layers share self-attention.
This is modality-based FFN selection, rather than Switch Transformer's learned router. Multiway lets the same backbone take a vision route, a text route, or a fusion route. That is useful engineering design, but the table does not isolate its numerical benefit.
However, this "multi-path architecture" design originates from VLMo's innovation, so it is not considered a key contribution of BEiT-3.
-
Unified Training Objective Function
The authors replace several pretraining losses with the masked data modeling family of objectives across image-only, text-only, and paired samples. Paired samples let the model learn cross-modal representations within that shared setting.
The mask-then-predict idea is not new—BERT and earlier BEiT models used related objectives—but many multimodal predecessors combined explicit contrastive, ITM, and other losses. BEiT-3's pretraining uses only the masked-prediction family. Its three data types still enter in a fixed batch composition, and retrieval later uses contrastive fine-tuning. This is a simpler pretraining objective, not a claim that all downstream training uses one loss.
Simplifying pretraining is one of the paper's core messages. The benchmark table validates the complete recipe on several tasks.
-
Discrete Image Encoding Based on BEiT
Earlier BEiT models use discrete visual tokens, analogous to a vocabulary, as targets for masked image modeling. BEiT-3 still feeds the network continuous image-patch embeddings.
This technology itself comes from earlier BEiT versions (v1, v2), not BEiT-3. However, this paper further proves the feasibility of treating "images like another language." By discretizing image encoding, the model can process both text and images using the same BERT-like pre-training mechanism.
Discretization changes the target representation for masked patches; it does not replace BEiT-3's patch embeddings. The tokenizer is inherited from BEiT v2, so its innovation mainly belongs to earlier work.
Large-scale data and discrete visual targets support the recipe. If we had to pick what is most distinctive, I would point to the combination of Multiway routing and a unified masked pretraining objective. The paper does not provide a controlled ablation that separates those two contributions.
The results show that simplified pretraining and flexible expert paths can support several downstream applications at scale. Data volume, model size, and task-specific fine-tuning also affect the reported scores.
Conclusion
In this paper, the authors propose a general multimodal foundational model: BEiT-3.
By treating images as a form of "foreign language," the authors were able to apply the same masked "language modeling" method to train text, images, and image-text pairs, and use the Multiway Transformers architecture, allowing the model to switch flexibly between different modalities.
Compared with multimodal pipelines that juggle several pretraining losses, BEiT-3's masked pretraining objective is simpler to organize. That makes it an attractive design, though a 1.9B-parameter model, one million steps, and task-specific fine-tuning are still part of its practical cost.