BERT is a bidirectional transformer encoder that learns contextual text representations by restoring masked tokens. Unlike causal models, it can use words on both sides of an interior gap, making it useful for understanding text rather than generating it left to right. section 9.3 section 10.3.11
Build each input representation from several coordinated signals:
- Tokenize with WordPiece and begin every sequence with [CLS]. section 9.3.1
- Separate one or two sentences with [SEP] and assign sentence-A or sentence-B segment embeddings. section 9.3.1
- Add token, segment, and positional embeddings together before passing the sequence through stacked encoder layers. section 9.3.1 section 9.3.3
- Pretrain with masked language modeling and next sentence prediction, then fine-tune all parameters end to end for a target task. section 9.3.1 section 9.3.2
Masked-token understanding
For a sentence containing an unknown interior word, mask selected WordPiece tokens and train BERT to recover their original IDs using surrounding context. A question-answering system can then fine-tune BERT to select an answer span from a passage, as in SQuAD. section 9.3 section 9.3.2
Figure 9.11 Combining token semantics, context semantics, and token position information
Inspect how token semantics, sentence context, and token positions combine into BERT's input representation. section 9.3.1








