This chapter introduces BERT and multilingual BERT as major transformer-based models for deep transfer learning in NLP, focusing on how pretrained representations can be reused for powerful downstream tasks. It frames these models as especially important because they scale well on modern parallel hardware and have become central to state-of-the-art NLP practice. The chapter is split between understanding BERT more deeply and then extending the same ideas to cross-lingual transfer with mBERT.
BERT is presented as a bidirectionally trained encoder stack that differs from earlier models by processing context from both directions at once. Its pretraining objectives are masked language modeling, where the model predicts randomly hidden tokens, and next-sentence prediction, where it learns whether one sentence naturally follows another. The chapter explains BERT’s input structure, including input IDs, masks, segment IDs, and special tokens such as [CLS] and [SEP], and then shows how the pretrained model can be applied to extractive question answering as well as fill-in-the-blank prediction and sentence-pair plausibility judgments.
The second half of the chapter explores multilingual BERT as a route to cross-lingual transfer, using Twi as a low-resource example language. It describes how mBERT is pretrained on more than 100 languages and how this shared multilingual knowledge can help when adapting to a language not originally emphasized in training. The chapter compares transferring from pretrained mBERT to Twi against training a new tokenizer and model from scratch, showing that transfer yields much better performance and faster convergence, while also illustrating how pretrained multilingual models can still reflect dataset biases and why further adaptation may be needed for broader language coverage.
A high-level representation of the BERT architecture, showing stacked encoders, input embeddings, and positional encodings. The output from the top is used for both next-sentence prediction and fill-in-blanks masked language modeling objectives during training.
BERT input transformation visualization
Summary
- The transformer architecture uses self-attention to build bidirectional context for understanding text. This has enabled it to become a dominant language model in NLP recently.
- The transformer allows tokens in a sequence to be processed independently of each other. This achieves greater parallelizability than bi-LSTMs, which process tokens in order.
- The transformer is a good choice for translation applications.
- BERT is a transformer-based architecture that is a good choice for other tasks, such as classification.
- BERT can be trained on multiple languages at once, producing the multilingual model mBERT. This model captures knowledge transferable even to languages not originally included in the training.
3. M. E. Peters et al., “BERT: Pre-Training of Deep Bidirectional Transformers for Language Understanding,” Proc. of NAACL-HLT (2019): 4171-86.
5. https://www.weforum.org/agenda/2020/07/mask-mandates-and-other-lockdown-policies-reduced-the-spread-of-covid-19-in-the-us.
6. P. Rajpurkar et al., “SQuAD: 100,000+ Questions for Machine Comprehension of Text,” arXiv (2016).
Transfer Learning for Natural Language Processing ebook for free