BERT: Bidirectional Pretraining from Transformers


Paper: Devlin et al., BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding, NAACL 2019. arXiv:1810.04805

The problem BERT solved

The original Transformer was built for translation (encoder–decoder). GPT-style models are left-to-right: each token predicts the next, so a token can only attend to its left context. That is a real limitation for understanding tasks (classification, question answering, NER), where both directions matter. BERT asked: what if we pretrain a deep Transformer encoder to “understand” text in both directions at once, then fine-tune it on any downstream task?

Two pretraining objectives

Masked Language Modeling (MLM). Randomly mask 15% of input tokens and train the model to reconstruct them.

This forces the model to build a bidirectional representation: predicting a masked word uses both left and right context.

Next Sentence Prediction (NSP). Given sentence A and B, predict whether B actually follows A. This teaches inter-sentence relationships useful for QA and inference.

Architecture

BERT uses the Transformer encoder only:

Pretrained on BooksCorpus (800M words) + English Wikipedia (2,500M words) for 4 days on 4–16 TPUs.

Using it (Hugging Face)

from transformers import AutoTokenizer, AutoModel

tok = AutoTokenizer.from_pretrained("bert-base-uncased")
model = AutoModel.from_pretrained("bert-base-uncased")

text = "Deep learning shifted Jiawei from software to [MASK]."
out = model(**tok(text, return_tensors="pt"))
# out.last_hidden_state[:, 0, :] is the [CLS] pooler representation

The [CLS] token’s final hidden state is the standard sentence embedding for classification.

Key results

Why it matters

BERT established the dominant pretrain → fine-tune paradigm and proved that a single bidirectional pretrained model could be adapted to nearly any NLP task with a tiny task-specific head. It is the direct ancestor of every encoder model (RoBERTa, DeBERTa, ModernBERT) and of the “foundation model” idea that LLMs later pushed to its logical extreme.

References

© 2026 Jiawei    粤ICP备18035774号