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.
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.
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.
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.
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).
6. https://www.salesforce.com/ca/products/einstein/ai-research/the-wikitext-dependency-language-modeling-dataset/
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).
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 thelr_find utility, which tests a range of learning rates and selects the point where the loss decreases fastest, indicated by the smallest loss gradient.
Transfer Learning for Natural Language Processing ebook for free