Overview

8 Deep transfer learning for NLP with BERT and multilingual BERT

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.
08_01
BERT input transformation visualization
08_02

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.

1. A. Vaswani et al., “Attention Is All You Need,” NeurIPS (2017).

2. A. Radford et al., “Improving Language Understanding by Generative Pre-Training,” arXiv (2018).

3. M. E. Peters et al., “BERT: Pre-Training of Deep Bidirectional Transformers for Language Understanding,” Proc. of NAACL-HLT (2019): 4171-86.

6. P. Rajpurkar et al., “SQuAD: 100,000+ Questions for Machine Comprehension of Text,” arXiv (2016).

FAQ

What is the main focus of Chapter 8 in “Transfer Learning for Natural Language Processing”?The chapter focuses on deep transfer learning for NLP using BERT and multilingual BERT (mBERT). It explains how to use pretrained BERT models for tasks like question answering, fill-in-the-blanks, and next-sentence prediction, and then shows how mBERT can support cross-lingual transfer learning.
Why is BERT considered bidirectional, and why is that important?BERT is bidirectional because it uses transformer encoders so each token can attend to all other tokens on both sides at the same time. This gives BERT a deeper understanding of context than unidirectional models, which helps it perform well on many NLP tasks.
What training objectives were used to pretrain BERT?BERT was pretrained with masked language modeling (MLM) and next-sentence prediction (NSP). MLM trains the model to predict masked tokens in a sentence, while NSP trains it to determine whether one sentence is a plausible follow-up to another.
What is the purpose of the [CLS] token in BERT?The [CLS] token is added at the beginning of every input example. Its final hidden state is used as a pooled representation of the whole sequence, especially for classification tasks such as sentiment analysis or entailment.
What are input IDs, input masks, and segment IDs in BERT?Input IDs are the integer token IDs from the vocabulary. Input masks indicate which positions are real tokens and which are padding. Segment IDs show whether each token belongs to sentence A or sentence B in paired-input tasks such as NSP.
How is BERT used for extractive question answering in the chapter?The chapter uses a pretrained BERT model through the transformers pipelines API to answer questions from a given context paragraph. For extractive QA, the model predicts the start and end positions of the answer span directly in the context.
What is masked language modeling, and how is it demonstrated in the chapter?Masked language modeling is a fill-in-the-blank task where some tokens are replaced with [MASK], and the model predicts the missing words. The chapter demonstrates this with a sentence about COVID-19, where BERT predicts words like “deaths” for a masked position.
How does next-sentence prediction work in the chapter?The model receives two sentences and predicts whether the second sentence is a plausible continuation of the first. The chapter shows that BERT assigns a high probability to related sentence pairs and a lower probability to random, unrelated ones.
What is multilingual BERT (mBERT), and why is it useful for cross-lingual transfer?mBERT is BERT pretrained on over 100 languages at the same time. It is useful for cross-lingual transfer because it can capture language-agnostic patterns that may generalize to low-resource languages not explicitly included in the original training set.
What does the Twi experiment show about transfer learning with mBERT?The Twi experiment shows that transferring pretrained mBERT weights to Twi performs better than training a BERT model from scratch on Twi data. The pretrained version achieved a much lower loss and trained more efficiently, demonstrating the value of multilingual transfer learning.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Transfer Learning for Natural Language Processing Transfer Learning for Natural Language Processing ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Transfer Learning for Natural Language Processing Transfer Learning for Natural Language Processing ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Transfer Learning for Natural Language Processing Transfer Learning for Natural Language Processing ebook for free