Context changes meaning: ELMo and ULMFiT
A static word vector gives "bank" one meaning. ELMo mixes the layers of a bidirectional language model into vectors that depend on the sentence; ULMFiT showed how to fine-tune a pretrained language model without wrecking it.
What runs in CodeSplash
- LNG008ELMo Explained here
- LNG009ULMFiT Partly runs in CodeSplash
- Text encoder (MiniLM + linear head) Not verified yet
You will be able to
- Explain the difference between static and contextual word vectors
- Describe ELMo's learned mixture of language-model layers
- Name ULMFiT's three schedule ideas and what each protects against
- Set up a ULMFiT-style fine-tuning schedule in CodeSplash and label it correctly
One vector per word is not enough
ReadWord2vec gives "bank" one vector, averaged over river banks and savings banks. Downstream models then have to undo that blur from the surrounding words.
A contextual embeddingContextual embeddingA vector computed for each occurrence of a word from its whole sentence, so the same word gets different vectors in different contexts. is computed for each occurrence, from the whole sentence. "bank" in "we fished from the bank" and in "the bank raised rates" gets two different vectors. The idea needs a model that reads the sentence first: a language model.
ELMo: mix the layers of a language model
ReadELMo trains two LSTM language models on a large corpus, one reading left to right and one right to left. For each token it collects the representations from every layer, then lets each downstream task learn how to mix them:
Lower layers tend to carry syntax, higher ones meaning in context. In the reference program, three layer scores become mixing weights 0.288, 0.475 and 0.236, and the scale γ stretches the mixed vector.
ULMFiT: fine-tune gently
ReadULMFiT (2018) made transfer the normal way to train text classifiers. Pretrain a language model on general text, fine-tune it as a language model on your domain's text, then fine-tune it as a classifier. Three schedule ideas keep the last stage from erasing what pretraining learned:
- Discriminative learning rates. Lower layers hold general features, so they get smaller steps. The reference program divides the rate by 2.6 per layer going down: 0.010 at the top, 0.0038 below it and 0.0015 below that.
- Gradual unfreezing. Train the top layer first, then unfreeze one more layer each epoch.
- Slanted triangular rates. A short rise, then a long linear fall.
What happens without them?
PredictPredict first
You fine-tune every layer of a pretrained encoder on 200 labeled texts with one large learning rate from the first step. What is the risk?
Reveal
Large early updates driven by a few labeled examples can overwrite the general features in the lower layers, a form of catastrophic forgettingCatastrophic forgettingA network trained further on new data losing what it learned from its old data.. The schedules move lower layers less and later.
The schedules in CodeSplash
ReadIn Text encoder, set Training to Fine-tune the top layers and turn on the ULMFiT-style options: Layer learning-rate decay, Gradual unfreezing and Slanted triangular learning rate. One test case fine-tunes the top two layers for 3 epochs, updating 3,549,316 weights, and reaches cross-validated ROC AUC 0.869 on a small review set.
Call this a ULMFiT-style schedule, not ULMFiT. The encoder is a pretrained Transformer (MiniLM or another of the learner's encoders), not an LSTM language model, and there is no language-model fine-tuning stage. ELMo itself is explained here only.
Where it stands in CodeSplash
Read| Entry | In CodeSplash |
|---|---|
| ELMo (LNG008) | Explained here |
| ULMFiT (LNG009) | Partly runs in CodeSplash: ULMFiT-style schedules in Text encoder fine-tuning; no LSTM language-model stage |
Check: contextual vectors and gentle fine-tuning
CheckpointCheck yourself
How does ELMo give "bank" different vectors in "river bank" and "bank loan"?
Show the answer
Answer: b
The vector comes from the language models' layers at that position, so it depends on everything around the word.
Check yourself
What does a downstream task learn in ELMo's layer mixture?
Show the answer
Answer: a
The language model stays fixed; the task learns how much of each layer to use and a scale γ. Syntax-heavy tasks can lean on lower layers, meaning-heavy tasks on higher ones.
Check yourself
With discriminative learning rates, which layers take the smallest steps?
Show the answer
Answer: b
Each layer down divides the learning rate by a factor (2.6 in the paper), so general features change least.
Check yourself
You fine-tune MiniLM in CodeSplash with all three ULMFiT-style options on. How should the report describe it?
Show the answer
Answer: b
ULMFiT names a whole recipe: an LSTM language model, domain language-model fine-tuning, then classifier fine-tuning. Borrowing its schedules doesn't make a run ULMFiT.
Recap
Recap- Contextual embeddings are computed per occurrence from the whole sentence.
- ELMo mixes the layers of two LSTM language models with learned weights and a scale.
- ULMFiT's discriminative rates, gradual unfreezing and slanted triangular rates protect pretrained features.
- Text encoder offers ULMFiT-style schedules for fine-tuning; label them as such.
Concepts in this lesson