Overview

9 ULMFiT and knowledge distillation adaptation strategies

In this chapter, the focus is on making transfer learning more efficient by adapting pretrained NLP models with as few extra parameters and as little performance loss as possible. The discussion frames this as a practical need for smaller, easier-to-deploy models, especially when working with large pretrained architectures such as ELMo, BERT, GPT, and recurrent language models. Two main strategies are emphasized: ULMFiT-style fine-tuning methods and knowledge distillation.

The first half of the chapter revisits ULMFiT and shows how its techniques improve adaptation to new tasks and domains. Discriminative fine-tuning assigns different learning rates to different layers, while gradual unfreezing progressively unlocks more layers during training to reduce overfitting and improve generalization. Using a fake news detection example, the chapter walks through fine-tuning a pretrained language model, finding a good learning rate, training the classifier head, and then progressively unfreezing lower layers. The result is a clear performance gain, showing that careful fine-tuning can substantially improve transfer effectiveness compared with simpler approaches.

The second half introduces knowledge distillation as a compression approach in which a smaller student model learns to imitate a larger teacher model. The chapter highlights how this can dramatically reduce parameter count and inference time while preserving most of the original performance. Using DistilBERT as the example, it shows how a distilled multilingual checkpoint can be adapted to monolingual Twi data with Hugging Face tools. The distilled model is smaller and faster than its teacher, yet still performs strongly, demonstrating that smart adaptation strategies can make pretrained language models more practical without sacrificing much accuracy.

(Duplicated from Chapter 6) Suggested slanted triangular ULMFiT rate schedule for the case of 10,000 total iterations. The rate increases linearly for 10% of the total number of iterations (i.e., 1,000) up to a maximum of 0.01 and then decreases linearly afterward to 0.
06_08
The result of the optimal learning rate-finding procedure from the fast.ai library for the language model fine-tuning step on the fake news detection example. Several learning rates are iterated through, and the optimal one is selected as the point where the loss is dropping fastest on the curve.
09_01
The result of the optimal learning rate-finding procedure from the fast.ai library for the target task classifier fine-tuning step on the fake news detection example. Several learning rates are iterated through, and the optimal one is selected as the point where the loss is dropping fastest on the curve.
09_02
An illustration of the general process of knowledge distillation. “Soft” labels produced by the teacher model are used to encourage the student model to behave similarly via the distillation loss. At the same time, the student loss is trained to behave similarly to ground truth via the student loss.
09_03

Summary

  • ULMFiT strategies of slanted triangular learning rates, discriminative fine-tuning, and gradual unfreezing can lead to noticeably more effective transfer.
  • Executing knowledge distillation of a larger teacher BERT model yields a significantly smaller student BERT model with minimal sacrifice of performance.

2. V. Sanh et al., “DistilBERT, a Distilled Version of BERT: Smaller, Faster, Cheaper and Lighter,” EMC^2: 5th Edition Co-located with NeurIPS (2019).

4. S. Merity et al., “Regularizing and Optimizing LSTM Language Models,” ICLR (2018).

7. L. Smith et al., “A Disciplined Approach to Neural Network Hyper-Parameters: Part 1—Learning Rate, Batch Size, Momentum, and Weight Decay,” arXiv (2018).

8. R. Tang et al., “Distilling Task-Specific Knowledge from BERT into Simple Neural Networks,” arXiv (2018).

9. X. Jiao et al., “TinyBERT: Distilling BERT for Natural Language Understanding,” arXiv (2020).

10. V. Sanh et al., “DistilBERT, a Distilled Version of BERT: Smaller, Faster, Cheaper and Lighter,” EMC^2: 5th Edition Co-located with NeurIPS (2019).

FAQ

What is the main goal of the adaptation strategies covered in Chapter 9?To make pretrained NLP models more efficient to transfer to new tasks, with a focus on parameter efficiency: getting strong performance while using fewer parameters, less storage, and less computation.
What are discriminative fine-tuning and gradual unfreezing in ULMFiT?Discriminative fine-tuning uses different learning rates for different layers, while gradual unfreezing progressively unfreezes more layers during training so the model adapts step by step instead of all at once.
Why does the chapter use ULMFiT with an RNN-based language model?The book uses an RNN-based language model for consistency with the original ULMFiT method and source material, even though the adaptation ideas themselves are architecture-agnostic and could also apply to transformers.
What is a slanted triangular learning rate schedule?It is a learning rate schedule that increases quickly at the start of training to a maximum value and then decreases gradually afterward. The chapter uses this schedule to help fine-tuning work more effectively.
How is the optimal learning rate chosen in fast.ai?The chapter uses the lr_find utility, which tests a range of learning rates and selects the point where the loss decreases fastest, indicated by the smallest loss gradient.
What results were obtained when fine-tuning the language model in the fake news example?After fine-tuning the pretrained language model with the selected learning rate, the chapter reports an accuracy of about 0.334. Using discriminative fine-tuning improved it to about 0.353.
How does gradual unfreezing improve classifier performance in the fake news example?By unfreezing layers one at a time and fine-tuning them progressively, the classifier achieved much higher accuracy, reaching about 99.8% at the first step and 100% after the top two layers were unfrozen.
What is knowledge distillation?Knowledge distillation is a model compression strategy where a smaller student model learns to imitate the outputs of a larger teacher model. The student is trained using both the teacher’s soft outputs and the true labels.
What is DistilBERT and why is it important?DistilBERT is a smaller version of BERT created through knowledge distillation. It keeps much of BERT’s performance while reducing the number of parameters and inference time, making it more practical to deploy.
What did the DistilmBERT Twi example demonstrate?It showed how to fine-tune a DistilBERT-based masked language model on monolingual Twi text using the pretrained multilingual checkpoint. The chapter reports that it used fewer parameters, trained faster than the teacher model, and produced plausible masked-word predictions.

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