BEiT (BERT Pre-Training of Image Transformers) is a BERT-style self-supervised pre-training method for ViT: part of an image's patches are masked, and the model predicts the "visual tokens" (the image expressed as a sequence of discrete symbols) at the masked positions, in the same spirit as BERT. It was published in 2021 by Bao et al. at Microsoft Research and Harbin Institute of Technology and accepted at ICLR 2022. The paper names this task "masked image modeling (MIM)."
ViT needs more labeled data than CNNs. Pre-training on unlabeled images can ease this problem. In language, BERT had been highly successful with pre-training that masks some words in a sentence and predicts them, but transferring this directly to images faced two obstacles.
- Image patches have no vocabulary: for words, a softmax can predict "which entry in the dictionary" a word is, but image patches have no fixed list of candidates.
- Predicting raw pixels wastes capacity on details: when masked patches are restored by regressing their pixels, the model spends its capacity on short-range pixel dependencies and fine textures (high-frequency components), and is less inclined to capture the semantics of objects.
BEiT uses a pre-trained image tokenizer (the discrete VAE from DALL-E) to convert each image into 14×14 visual tokens (codes from 8,192 classes), and uses these as targets in place of the "masked words." The input remains pixel patches; the output is a classification over visual token codes.
A ViT-B pre-trained on ImageNet-1K without labels reaches 83.2% after fine-tuning (84.6% at 384×384), outperforming DeiT-B trained from scratch (81.8%) as well as contemporary self-supervised methods DINO and MoCo v3. After BEiT, MAE, which reconstructs the pixels of masked patches directly, was proposed, and masked image modeling became one of the main approaches to pre-training image Transformers.

![BEiT pre-training. On the left, the image is split into patches, blocks of patches are masked and replaced with [M], and the result passes through the BEiT encoder and the MIM head; in parallel, the same image is converted into visual tokens by the tokenizer, and the two paths meet in a cross-entropy loss at the masked positions. On the right, block-wise masking on a 14×14 patch grid (about 40%) and the positions used as targets](/note/images/articles/architectures/beit.en.png)