TL;DR
Before ELMo, a word had one vector wherever it appeared, so "play" in a football report and "play" in a theatre review got the same numbers. ELMo (Embeddings from Language Models) gives each token a vector that depends on the whole sentence around it. It gets that vector from a two-layer bidirectional language model trained on a large text corpus, by taking a learned weighted mix of every layer of that model. Adding these vectors to existing models improved the best published results on six language understanding tasks, including question answering, textual entailment and sentiment analysis.
Builds on: Language Model, Word Embedding, Bidirectional Recurrent Neural Network, Long Short-Term Memory, Transfer Learning · Leads to: BERT: Pre-training of Deep Bidirectional Transformers, Fine-Tuning
Why it mattered
ELMo made pre-training on raw text a standard first step for language tasks. Before it, most task models began from word vectors that were fixed, one per word. After it, a team could train a large language model once on plain text, freeze it, and let many different task models read its internal states. The authors released the trained models and code through AllenNLP. The same recipe of "pre-train a language model, then reuse it" was then used in later work such as BERT: Pre-training of Deep Bidirectional Transformers. Many NLP systems of 2018 and 2019 were built this way, which is why this paper is cited very widely; it is among the most cited papers in language modelling.
The problem
The word vectors of that time, such as those from Word Embedding methods, gave each word type one fixed vector. The word "bank" in "river bank" and in "bank account" got the same vector, so a model reading the vector could not tell the two uses apart. Two earlier ideas tried to fix this. Subword methods gave rare words better vectors from their pieces. Sense-based methods gave one word several vectors. Both still picked one vector per word or per sense before reading the sentence.
Contextual methods were the other route. A model reads the whole sentence and outputs a vector for each position. The paper's authors had already seen this with a language model trained on a large corpus (their earlier work) and with a translation encoder (CoVe). Both used only the top layer of the network. The question was whether the lower layers held useful information too, and whether a model trained for next-word prediction could supply vectors for many tasks.
Two ideas from the prerequisite lessons are needed here. A Language Model assigns a probability to each token given the tokens before it. A Bidirectional Recurrent Neural Network reads a sequence in both directions and joins the two results.
How it works
The pipeline runs from raw characters to a vector that a task model can use. We trace one token through it.
flowchart LR A["characters of a token"] --> B["character CNN<br/>context-free vector x"] B --> C["forward LSTM layer 1<br/>and backward LSTM layer 1"] C --> D["forward LSTM layer 2<br/>and backward LSTM layer 2"] B --> E["layer 0: x"] C --> F["layer 1: joined forward and backward states"] D --> G["layer 2: joined forward and backward states"] E --> H["weighted sum with task-specific weights"] F --> H G --> H H --> I["ELMo vector for this token in this sentence"]
- Read the characters. The input to the model is the characters of a word, not a fixed vocabulary of word ids. A convolutional network over characters turns the word into one context-free vector, called x. Because the input is characters, a word never seen in training still gets a vector.
- Run the forward language model. A stack of two LSTM layers reads the sentence left to right. At each position k, each layer gives a state that summarises the words up to k. The top layer's state is what predicts the next word.
- Run the backward language model. A second stack of LSTM layers reads the same sentence right to left and predicts each word from the words after it.
- Keep every layer. For one token, the model now holds three vectors: layer 0 is x, layer 1 joins the forward and backward states of the first LSTM layer, and layer 2 joins them for the second. ELMo keeps all three.
- Mix the layers for the task. A task model does not use one layer. It learns one weight per layer and one overall scale, and adds the weighted layers into a single vector. Lower layers tend to carry syntax and higher layers carry meaning, so the task gets to choose the mix.
- Feed the vector into the task. The ELMo vector is concatenated to the task's usual word input and passed to the task model. The biLM stays frozen during this training.
Tiny check. Suppose one scalar dimension has the values 0.5 in layer 0, 1.0 in layer 1 and 2.0 in layer 2. Let all three raw layer scores be 0, so the softmax weights are each one third, and let the overall scale be 1. The mixed value is one third of 0.5, plus one third of 1.0, plus one third of 2.0, which is 3.5 divided by 3, about 1.17. Change the raw scores to favour layer 2 and the same three numbers mix to a value nearer 2.0.
Worked examples
- Layer values for one dimension: , , .
- Raw scores are all zero, so the softmax weights are .
- Set . The mix is .
- The sum inside is .
- Interpretation: with equal weights, ELMo is the average of the layers. A task that favours the top layer would raise the result toward 2.0.
Take the three-word sentence "the cat sat", with tokens = the, = cat, = sat.
- Forward model: .
- Backward model: .
- Both products are estimates of the same sentence probability, so the training objective adds their log values.
- At position 2, the forward state can see only "the", while the backward state can see only "sat". The joined vector sees both neighbours, which is why ELMo can separate "cat" in different sentences.
- Interpretation: the two directions are learned separately and joined only at the representation, so the biLM is not a model that reads both sides at once inside each layer.
A question answering system reads the question "Who wrote the play?" above a paragraph about a theatre premiere.
- A plain word vector for "play" is the same whether the sentence is about sport or drama.
- The biLM reads the whole question. Its layer-2 state for "play" depends on the words around it, here "wrote" and "the".
- The paper's nearest-neighbour examples show the same effect: the vector for "play" in a sports sentence sits near sports senses, and in a theatre sentence it sits near theatre senses.
- The task model adds this vector to its usual word input. The paper reports that adding ELMo to a question answering baseline raised test F1 on SQuAD from 81.1 to 85.8.
- Interpretation: the gain comes from giving each token a sentence-dependent vector that the task can use, not from a bigger task model.
Try it: a task model uses weights and on layer values for one dimension. What is the ELMo value for that dimension? Answer: .
The math
The biLM is trained to predict each word in both directions at once. Given tokens , the forward model factors the sentence probability as a product of next-token probabilities.
The backward model conditions on the later tokens instead.
The paper trains both directions together by maximising the sum of their log likelihoods. The token embedding and the Softmax output layer are shared between the two directions, while the LSTM weights are separate. The training loss for a sentence is the negative of that sum; it is the same Cross-Entropy Loss applied in both directions.
Step 2 in symbols: the layer states
For token k, let be the forward state of LSTM layer j, and the backward state. Joining them gives one vector per layer:
Layer 0 is the context-free token vector . So the biLM gives layers for each token, the square brackets meaning concatenation.
Step 5 in symbols: the task mix
The ELMo vector for token k in a given task is a scaled weighted sum of all layers:
Here are softmax-normalised weights, so they are positive and sum to one, and is one learned scalar that scales the whole vector. The scale is there for optimisation reasons, not for meaning. A common variant applies layer normalisation to each layer before the weighting.
The worked numbers in the tiny check above use exactly this formula with , and .
Step 6 in symbols: the frozen biLM
The biLM weights are not updated when the task model trains. The task model learns only , , and its own weights. A small regularisation term on the layer weights pushes them toward an average of the layers, and the paper reports that large makes the mix close to a plain average.
Results
Table 1 of the paper compares ELMo-enhanced models with the best single-model results at that time on six tasks. The baseline in each row is the authors' own strong model for that task, and the increase column gives the absolute and relative gain.
| Task | Metric | Previous best | Baseline | With ELMo | Gain |
|---|---|---|---|---|---|
| SQuAD (question answering) | F1 | 84.4 | 81.1 | 85.8 | +4.7 (24.9% relative error reduction) |
| SNLI (textual entailment) | accuracy | 88.6 | 88.0 | 88.7 | +0.7 |
| SRL (semantic role labeling) | F1 | 81.7 | 81.4 | 84.6 | +3.2 |
| Coreference resolution | average F1 | 67.2 | 67.2 | 70.4 | +3.2 |
| NER (named entity recognition) | F1 | 91.93 | 90.15 | 92.22 | +2.06 |
| SST-5 (sentiment) | accuracy | 53.7 | 51.4 | 54.7 | +3.3 |
The paper's summary is that relative error fell by 6 to 20 percent across tasks. The gain on SNLI is the smallest, a 0.7 point rise over a strong baseline. The authors also report ensembles, which are not the main claim.
The analysis supports the mechanism:
- Using all layers beats using the top layer. The paper's ablations on SQuAD, SNLI and SRL show that the top layer alone gives less of a gain than the full weighted mix.
- The lower layers carry more syntax, and the higher layers carry more meaning. The paper's probes say this directly. On word sense disambiguation the second biLM layer reaches F1 69.0, against 67.4 for the first layer and 65.9 for the first-sense baseline.
- The biLM's average forward and backward perplexity on the 1 Billion Word Benchmark was 39.7. That is not a state-of-the-art language model. The paper's point is that its internal states are useful to downstream tasks, not that it predicts text best.
Limits. The vectors come from a frozen model, so the task cannot change what the biLM learned about language. Running the biLM costs time and memory on every input. The two directions are separate LSTM networks that meet only at the final representation. The evidence is for the benchmarks and architectures of 2018.
Reading guide
Read the paper in this order. Each section depends on the prerequisites listed beside it.
- Section 1, Introduction. Needs Word Embedding for the idea of a fixed vector per word, and Language Model for what the pre-trained model predicts.
- Section 2, Related work. Needs Subword Tokenization for the subword methods, and Transfer Learning for the idea of reusing a pre-trained model.
- Section 3.1, Bidirectional language models. Needs Bidirectional Recurrent Neural Network, Long Short-Term Memory, Softmax and Cross-Entropy Loss. Equation (1) is the biLM objective.
- Section 3.2, ELMo. Needs only the weighted-sum idea from the math above, plus Layer Normalization for the optional per-layer normalisation.
- Section 3.3, Using biLMs for supervised tasks. Needs Fine-Tuning for the idea of training on top of a pre-trained model, and Dropout for the regularisation the paper adds.
- Section 3.4, Architecture. Needs Convolutional Neural Network for the character convolutions and Perplexity for the reported numbers.
- Section 4, Evaluation. Each task has its own baseline. Read the table first, then the task you know best.
- Section 5, Analysis. Needs Recurrent Neural Network for the layer-by-layer reading of the states.
Check yourself
QuestionWhy does a word vector from ELMo change from one sentence to another, while a classic word embedding does not?Show answer
A classic embedding looks up one fixed vector per word type, so every occurrence of a word gets the same vector. ELMo computes the vector by running a language model over the whole sentence, so the state at each token depends on the words before and after it. Two uses of the same word in different sentences can therefore give different vectors.
QuestionA biLM has three layers for a token with values 2, 4 and 8 in one dimension. The softmax weights are 0.5, 0.25 and 0.25, and the scale is 1. What is the ELMo value?Show answer
The weighted sum is 0.5 times 2, plus 0.25 times 4, plus 0.25 times 8. That is 1 + 1 + 2 = 4. The answer is 4.
QuestionWhy does the paper keep all layers instead of using only the top layer, as earlier contextual methods did?Show answer
Lower layers carry more syntactic information and higher layers carry more meaning. A task can use whichever mix helps it. The paper's ablations show that using all layers beats using only the top layer on SQuAD, SNLI and SRL, so the lower layers add useful signal instead of noise.
QuestionA team wants to fine-tune the whole biLM on their own medical text before adding ELMo to a classifier. What is one reason this might help, and what is one cost?Show answer
The paper notes that fine-tuning the biLM on domain text can lower perplexity and improve downstream results, because the biLM adapts to the vocabulary and style of the domain. The cost is extra training time and the need for enough domain text without overfitting. This is a general point about domain adaptation; it is not medical advice.
QuestionIn one sentence, what does the training objective of the biLM ask the model to do?Show answer
For each token, predict it from the tokens before it (forward) and from the tokens after it (backward), and maximise the sum of both log likelihoods over the corpus.
Sources
- Peters, M. E., Neumann, M., Iyyer, M., Gardner, M., Clark, C., Lee, K., and Zettlemoyer, L. (2018). Deep contextualized word representations. arXiv:1802.05365. https://arxiv.org/abs/1802.05365
- Peters et al. (2018), NAACL 2018. DOI: https://doi.org/10.18653/v1/N18-1202