Masked Language Models
Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 9
7 cards in “9.4 Fine-tuning for classification” · whole deck
9.4 Fine-tuning for classification
- What are the two ways to use pretrained LMs for downstream tasks?Prompting the model in natural language so it generates what we want, or fine-tuning: adding application-specific circuitry (a head) on top and training it on labeled data, freezing or only minimally adjusting the pretrained parameters.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 9, §9.4, pp. 235–236
- How is an encoder fine-tuned for sequence classification, e.g. sentiment?Pass the text through the encoder, take the final-layer
[CLS]vector (or the mean of the token outputs), and feed it to a classifier head: \(y = \text{softmax}(h^L_{CLS}W_C)\), with \(W_C\) of shape \([d \times \text{classes}]\), trained with cross-entropy.- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 9, §9.4, p. 236
- During classification fine-tuning, are the pretrained weights updated?They can be, but reasonable performance usually needs only minimal changes, often limited to the last few transformer layers.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 9, §9.4, p. 236
- How is sequence-pair classification done with an encoder?As in NSP training: input
[CLS]sentence A[SEP]sentence B[SEP], and classify the final[CLS]vector with a learned head.- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 9, §9.4, pp. 236–237
- What is natural language inference (NLI)?Also called recognizing textual entailment: given a premise and a hypothesis, classify their relationship as entails, contradicts or neutral, in the loose sense of how a typical human would read them.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 9, §9.4, p. 237
- Classify: premise “I’m confused.”, hypothesis “Not all of it is very clear to me.”Entails.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 9, §9.4, p. 237
- Name a dataset for natural language inference.MultiNLI (Multi-Genre Natural Language Inference).
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 9, §9.4, p. 237
Source
- Daniel Jurafsky and James H. Martin. Speech and Language Processing. 3rd edition (draft). https://web.stanford.edu/~jurafsky/slp3/