BERT

BERT

A deeply bidirectional transformer encoder, pretrained to predict masked tokens, then fine-tuned for any understanding task with a small layer. On release it achieved the best results on 11 tasks, and became the basis for hundreds of models, including most Arabic models.

2018Encoder-onlyPublished weights
DeveloperGoogle AI Language
Year of publication2018
Number of parametersBase 110 million, Large 340 million
LayersBase 12 layers (768 dimensions, 12 heads); Large 24 layers (1024, 16 heads)
Context length512 tokens
Training dataBooksCorpus (800 million words) + English Wikipedia (2,500 million words)
Training objectiveMasked language modeling (MLM) + next sentence prediction (NSP)
LicenceApache 2.0
ArabicThe multilingual mBERT version includes Arabic; the strongest Arabic models were built on its architecture (AraBERT, CAMeLBERT, ARBERT/MARBERT).
Page contents
  1. Contribution
  2. Results
  3. Use today

Contribution

Before BERT, contextual representations were either unidirectional (GPT) or shallowly bidirectional (ELMo). The masked language modeling task made it possible to train a transformer that sees context from both sides in every layer without "seeing" the target word. With NSP, it learned relations between sentences.

Results

BERT-Large raised the GLUE score to 80.5 (an absolute improvement of 7.7 points at the time), achieved an F1 of 93.2 on SQuAD v1.1, exceeding the recorded human performance on that benchmark, and an F1 of 83.1 on SQuAD v2.0. (Figures as reported in the paper.)

Use today

BERT encoders and their descendants are still the most efficient choice for classification, tagging and retrieval in production when size and speed matter, while large models are used when flexibility and generation are needed.

Encoder-only model (BERT family) Encoder-only (BERT family)
[CLS]T0ذهبT1[MASK]T2إلىT3المدرسةT4[SEP]T5Token + Segment + Position embeddingsN× encoder blocksbidirectional self-attention: every token sees every tokenMLM: the student?classifier

Every token sees the whole context in both directions. In pre-training some tokens are masked and the model predicts them (MLM); in fine-tuning the [CLS] representation or the token representations are used.

Key contributions

  • Context from both directions in every layer, thanks to masking.
  • A unified fine-tuning recipe for classification, tagging and extractive question answering.
  • Multilingual versions, multiple sizes and mature tooling.

Limitations and caveats

  • It does not naturally generate long text (encoder only).
  • A 512-token window, and a mismatch between [MASK] in training and its absence in fine-tuning.
  • It was "undertrained", as RoBERTa showed.

Original references

  1. Devlin, J., Chang, M.-W., Lee, K. & Toutanova, K. (2019). BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. NAACL arxiv.org/abs/1810.04805

The figures are taken from the papers and official cards cited in the references. When the developer does not disclose a figure we write "not disclosed" and do not estimate it. Check the model card before any commercial use, because license terms may change.