ElemedexA pocket encyclopedia of AI architectures
No. 028

BERT

Bidirectional Encoder Representations from Transformers

Masked Model

It reads the whole sentence at once, forwards and backwards. It was trained by covering words with a mask and guessing what was underneath, so now it cannot see a gap without filling it. It doesn't talk: it understands (or so its trainers claim).

Height
12 (base) · 24 (large)
Weight
≈ 440 MB · 1.4 GB (fp32)
Parameters
110 M · 340 M
Context
512 tokens
Training data
BooksCorpus (800 M words) + English Wikipedia (2,500 M)
Year
2018
Generation
4 · Transformers
Creators
Devlin, Chang, Lee & Toutanova (Google AI Language)
Kind
Model

Base stats

Total
247

Approximate, ordinal scales meant for comparing species with each other; the hard numbers are in the data sheet.

Weaknesses

  • It does not generate fluent text: it was not trained to produce word-by-word continuations.
  • Short window (512 tokens): a whole academic paper does not fit.
  • It learns statistical shortcuts in datasets and can be right for the wrong reasons.
  • The [MASK] token appears in pretraining but never in actual use.

Habitat

It grew up on unpublished books (BooksCorpus) and the running text of English Wikipedia, with lists and tables stripped out. Today it lives inside search engines, spam filters, review classifiers and, in its Sentence-BERT form, in nearly every semantic search system.

Moves

Abilities

Bidirectionality
Every token attends to all the others, left and right: there is no causal mask.
[CLS] token
A special token at the start of the input whose final vector serves as a summary of the whole sequence for classification.
Transfer
Pretrained once, then cheaply fine-tuned for each new task by adding an output layer.

Anatomy

BERT-base: a stack of 12 encoder blocks. In pretraining, the output at the masked position predicts the hidden word; when fine-tuned, the [CLS] vector feeds a classifier.

Evolution chain

  • keeps only the encoder and learns to fill in blanks025 Transformer
  • bidirectional context, now with attention026 ELMo
028 BERT

BERT is a transformer encoder trained to represent text, not to write it. It takes a sequence of up to 512 tokens and returns, for each of them, a vector that depends on the whole sentence. Alammar & Grootendorst (2024) present it as the first great "representation model," as opposed to the generative models of the GPT family (2024, pp. 18–20).

How it works

The architecture is almost exactly the left half of the original transformer: a stack of self-attention and feedforward (MLP) block blocks, with residual connections and normalization (Devlin et al., 2019, p. 4173). The base version has 12 layers, 768-dimensional vectors and 12 attention heads (110 million parameters); large has 24 layers and 340 million.

The novelty lies in how it is trained. A classic language model predicts the next word, so it can only look to the left. BERT is instead pretrained on two tasks (Devlin et al., 2019, pp. 4174–4175):

  1. Masked language modeling (MLM): 15% of the tokens are chosen at random and hidden (usually replaced by a special [MASK] token); the model must reconstruct them from the context on both sides. The authors explicitly connect this with the cloze test from the psychology of reading (Taylor, 1953): the school exercise of filling in the gaps of a text.
  2. Next sentence prediction: given two sentences, decide whether the second one followed the first in the original text or was picked at random.

The result is a model that "knows" no task in particular but can be adapted to many. To classify reviews, for instance, one takes the vector of the special [CLS] token, adds an output layer, and runs a short fine-tuning on labeled examples (Alammar & Grootendorst, 2024, pp. 18–19). This recipe (pretrain once, fine-tune many times) is the transfer learning paradigm that dominated language processing from 2018 to 2020.

What changed

Compared with ELMo, which concatenated two LSTMs (one reading left-to-right, the other right-to-left), BERT is deeply bidirectional: at every layer, every word sees every other word. Compared with GPT-1, which uses the same kind of stack but with a causal mask, BERT gives up generation in exchange for better representations. In 2018 it set the state of the art on eleven understanding tasks, including the GLUE benchmark and the SQuAD question-answering dataset (Devlin et al., 2019, p. 4171).

Forms and offspring

Like some Pokémon, BERT has regional forms: RoBERTa (more data, no next-sentence prediction), DistilBERT (a smaller, distilled version), and multilingual variants. Its most widely used evolution today is Sentence-BERT, which produces one vector per sentence for semantic search.

The family grew again just when text generation seemed to have taken all the attention. ModernBERT brings recent models' improvements to the encoder and is trained on 2 trillion tokens with a native window of 8,192 (Warner et al., 2025); mmBERT extends the recipe to more than 1,800 languages (Marone et al., 2025). The Ettin suite trains pairs of encoders and decoders on the same data with the same recipe, from 17 million to 1 billion parameters: encoders win at classification and retrieval, decoders at generation, and retraining one on the other's objective does not close the gap. A 400 M encoder beats a 1 B decoder at inference (MNLI) (Weller et al., 2025).

Limits

The 512-token window is short, and the [MASK] token creates a mismatch: it appears in training but never when the model is used (Devlin et al., 2019, p. 4174). More serious, from an epistemic point of view, is that its benchmark success turned out to be partly illusory: several studies showed that it exploited superficial regularities in the data (see the professor's note).

Sources

  • Alammar, J., & Grootendorst, M. (2024). Hands-on large language models: Language understanding and generation. O’Reilly Media. §
  • Bender, E. M., & Koller, A. (2020). Climbing towards NLU: On meaning, form, and understanding in the age of data. In D. Jurafsky, J. Chai, N. Schluter, & J. Tetreault (Eds.), Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics (pp. 5185–5198). Association for Computational Linguistics. https://doi.org/10.18653/v1/2020.acl-main.463 §
  • Devlin, J., Chang, M.-W., Lee, K., & Toutanova, K. (2019). BERT: Pre-training of deep bidirectional transformers for language understanding. In J. Burstein, C. Doran, & T. Solorio (Eds.), Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers) (pp. 4171–4186). Association for Computational Linguistics. https://doi.org/10.18653/v1/N19-1423 §
  • Liu, Y., Ott, M., Goyal, N., Du, J., Joshi, M., Chen, D., Levy, O., Lewis, M., Zettlemoyer, L., & Stoyanov, V. (2019). RoBERTa: A robustly optimized BERT pretraining approach (arXiv:1907.11692). arXiv. https://doi.org/10.48550/arXiv.1907.11692 §
  • Marone, M., Weller, O., Fleshman, W., Yang, E., Lawrie, D., & Van Durme, B. (2025). mmBERT: A modern multilingual encoder with annealed language learning (arXiv:2509.06888). arXiv. https://doi.org/10.48550/arXiv.2509.06888 §
  • McCoy, R. T., Pavlick, E., & Linzen, T. (2019). Right for the wrong reasons: Diagnosing syntactic heuristics in natural language inference. In A. Korhonen, D. Traum, & L. Màrquez (Eds.), Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics (pp. 3428–3448). Association for Computational Linguistics. https://doi.org/10.18653/v1/P19-1334 §
  • Niven, T., & Kao, H.-Y. (2019). Probing neural network comprehension of natural language arguments. In A. Korhonen, D. Traum, & L. Màrquez (Eds.), Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics (pp. 4658–4664). Association for Computational Linguistics. https://doi.org/10.18653/v1/P19-1459 §
  • Taylor, W. L. (1953). “Cloze procedure”: A new tool for measuring readability. Journalism Quarterly, 30(4), 415–433. https://doi.org/10.1177/107769905303000401 §
  • Warner, B., Chaffin, A., Clavié, B., Weller, O., Hallström, O., Taghadouini, S., Gallagher, A., Biswas, R., Ladhak, F., Aarsen, T., Adams, G. T., Howard, J., & Poli, I. (2025). Smarter, better, faster, longer: A modern bidirectional encoder for fast, memory efficient, and long context finetuning and inference. In W. Che, J. Nabende, E. Shutova, & M. T. Pilehvar (Eds.), Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) (pp. 2526–2547). Association for Computational Linguistics. https://doi.org/10.18653/v1/2025.acl-long.127 §
  • Weller, O., Ricci, K., Marone, M., Chaffin, A., Lawrie, D., & Van Durme, B. (2025). Seq vs seq: An open suite of paired encoders and decoders (arXiv:2507.11412). arXiv. https://doi.org/10.48550/arXiv.2507.11412 §