Concept · Chapter 8: The Rise of Large Language Models
Pretrain, Then Fine-Tune
Train one model on a huge amount of unlabelled text first, then adapt it to each task with a small labelled dataset; around 2018 this replaced training every NLP model from scratch.
The problem
Every language task (sentiment, question answering, entailment) needed its own labelled dataset and its own model, and labels are expensive.
The solution
Learn general knowledge of language from raw text with a self-supervised objective, then fine-tune the whole pretrained network on the task.
The consequence
Small labelled datasets became enough, benchmark scores jumped across NLP, and the pretrained model became the valuable asset.
You should understand first
- Text as Data
- Probability and Distributions
- Conditional Probability and Bayes' Theorem
- Probability of Sequences
- Language Modeling
- Vectors
- Dot Product
- Embeddings
- Attention
- Softmax
- Self-Attention
- Multi-Head Attention
- Causal Masking
- Positional Encoding
- Residual Connections
- Layer Normalization
- Feed-Forward Sublayer (MLP)
- The Transformer Block
- Encoder, Decoder & Encoder–Decoder
- Pretrain, Then Fine-Tune
The idea
Before 2018, a sentiment classifier and a question-answering system were separate models, each trained from (nearly) scratch on its own labelled data. Word vectors from word2vec helped a little, but everything above the first layer was learned anew every time.
The new recipe borrowed from vision's ImageNet pretraining:
Pretrain
Train a large network on raw text with a task the text supplies itself: predict the next word, or fill in hidden words. No labels needed, so the data can be enormous.Fine-tune
Add a small output layer and keep training the whole network on a few thousand labelled examples of the actual task.
2018, the breakthrough year
- ELMo took contextual word vectors from a pretrained bidirectional LSTM language model Established, so "bank" got a different vector by a river than in finance.
- ULMFiT showed that fine-tuning an entire pretrained LSTM language model works well for text classification Established.
- GPT-1 pretrained a 12-layer Transformer decoder on next-token prediction over more than 7,000 unpublished books, then fine-tuned it, improving the state of the art on 9 of 12 tasks Established.
- BERT pretrained a Transformer encoder by predicting randomly masked words (15% of tokens) and set new results on eleven NLP tasks Established.
BERT's encoder dominated benchmarks for the next two years. The decoder route, next-token prediction, looked like the weaker cousin. The rest of this chapter is the story of how that changed.
What to remember
- Stage 1, pretrain on unlabelled text (cheap data, expensive compute). Stage 2, fine-tune on a small labelled set.
- 2018: ELMo (contextual vectors), ULMFiT (fine-tune a language model), GPT-1 (Transformer decoder), BERT (Transformer encoder).
- BERT pretrains by filling in masked words; GPT by predicting the next token.
- Vision had done this since ImageNet; 2018 was NLP's version.
Key papers
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
Jacob Devlin, Ming-Wei Chang et al. · 2018 · NAACL 2019
Made 'pretrain once, fine-tune everywhere' the default in NLP, using an encoder-only Transformer that reads context in both directions.
Deep contextualized word representations
Matthew E. Peters, Mark Neumann et al. · 2018 · NAACL 2018
ELMo: word vectors that change with the sentence, taken from a pretrained bidirectional LSTM language model. 'Bank' by a river and 'bank' with an account finally got different vectors.
Universal Language Model Fine-tuning for Text Classification
Jeremy Howard, Sebastian Ruder · 2018 · ACL 2018
ULMFiT showed that 'pretrain a language model, then fine-tune the whole thing' works for NLP the way ImageNet pretraining worked for vision.
Improving Language Understanding by Generative Pre-Training
Alec Radford, Karthik Narasimhan et al. · 2018 · OpenAI technical report
GPT-1: a 12-layer decoder-only Transformer pretrained to predict the next token on over 7,000 unpublished books, then fine-tuned. It improved the state of the art on 9 of 12 tasks and set the template for every GPT since.