# Deep contextualized word representations

Matthew E. Peters, Mark Neumann, Mohit Iyyer, Matt Gardner, Christopher Clark, Kenton Lee and 1 more · arXiv · 2018-2-15

- **Problem** Pretrained word vectors give each word type one context-independent vector, so one word's different senses and uses across sentences cannot be separated.
- **Method** Pretrain a two-layer bidirectional language model on a large corpus, then learn a task-specific weighted sum of its layers as the ELMo vector and add it to existing task models while the biLM stays frozen.
- **Results** Adding ELMo to the SQuAD baseline raised test F1 from 81.1 to 85.8.

## Why one vector per word is limiting

Most neural NLP systems start from pretrained word vectors, and each word type receives a single vector no matter which sentence it appears in. That one vector has to encode both the syntax and semantics of a word and the way its use shifts from one context to another, and a fixed lookup table handles the second part poorly.

The paper's answer is ELMo, which gives each token a representation that depends on the whole input sentence. These vectors come from a bidirectional LSTM trained as a language model on raw text, which makes the approach semi-supervised.

Earlier contextual approaches take their vectors from the top layer alone, whereas ELMo draws on all internal layers of the biLM. The authors report that weighting these layers markedly improves performance over using only the top LSTM layer.

## Pretraining the bidirectional language model

A forward language model factors the probability of a sentence into predictions of each token given the tokens before it, and a backward model runs the same factorization in reverse, predicting each token from the tokens after it. The biLM trains both directions together by maximizing the summed log likelihood of the two, as follows. \\\[ \\sum\_{k=1}^{N} \\left( \\log p(t\_k \\mid t\_1,\\dots,t\_{k-1}; \\Theta\_x, \\overrightarrow{\\Theta}\_{LSTM}, \\Theta\_s) + \\log p(t\_k \\mid t\_{k+1},\\dots,t\_N; \\Theta\_x, \\overleftarrow{\\Theta}\_{LSTM}, \\Theta\_s) \\right) \\\] The token representation parameters and the Softmax parameters are shared by the two directions, while each direction keeps its own LSTM parameters.

Compared with the independent-parameter design of Peters et al. (2017), this shares some weights between directions.

The token layer does not come from a fixed vocabulary table: 2048 character n-gram convolutional filters feed two highway layers and a linear projection down to 512 dimensions. Because the input is purely characters, words outside the training set still receive a token-layer vector. Above the token layer sit two biLSTM layers with 4096 units and 512-dimension projections, joined by a residual connection from the first layer to the second.

The embedding and hidden dimensions were halved from the single best CNN-BIG-LSTM model of Józefowicz et al. (2016), to keep the model affordable for downstream tasks.

After 10 epochs on the 1B Word Benchmark, the average forward and backward perplexity is 39.7. The 30.0 figure is for the forward CNN-BIG-LSTM, the model the biLM was derived from, so the two numbers describe different networks. Forward and backward perplexities came out roughly equal, with the backward one slightly lower.

Fine-tuning the biLM on domain text can sharply lower perplexity and, in some cases, raise downstream scores. Most downstream models therefore use a biLM fine-tuned on their own domain data.

## From biLM layers to an ELMo vector

For a token at position k, the biLM yields 2L+1 representations: the token layer, plus a forward and a backward state for each of the L LSTM layers. Concatenating the two directions gives one state per LSTM layer, so the set can be written as h^{LM}\_{k,j} for j from 0 to L, with j = 0 the token layer.

The simplest option takes only the top layer, as TagLM and CoVe do, but ELMo weights all layers separately for each end task. The task-specific vector is a scaled sum: softmax-normalized weights s\_j combine the layers, and a scalar gamma scales the whole result. \\\[ ELMo^{task}\_k = \\gamma^{task} \\sum\_{j=0}^{L} s^{task}\_j \\, h^{LM}\_{k,j} \\\] The gamma term matters for optimization because the biLM layer activations and the task representations follow different distributions, and layer normalization applied to each biLM layer before weighting sometimes helped.

The biLM weights are frozen while the task model trains, so what is learned for each task is the layer weights, the scale and the downstream parameters. Once pretrained, the biLM can compute representations for any task, which lets one frozen model serve several tasks with different weightings.

Inside a supervised model the ELMo vector is concatenated with the context-independent token vector x\_k before it enters the task RNN. For some tasks, SNLI and SQuAD, ELMo is also added at the task RNN output, replacing h\_k with the concatenation of h\_k and the ELMo vector. In some cases dropout is applied to ELMo, and an L2 penalty on the ELMo weights is added to the loss.

That penalty pulls the layer weights toward an average over all biLM layers.

## Results on six tasks

Table 1 sets ELMo-enhanced single models against the baseline and previous state-of-the-art single-model results on six tasks.

The SQuAD baseline is an improved version of the Bidirectional Attention Flow model that adds self-attention, simplifies some pooling and uses GRUs in place of LSTMs. Adding ELMo raised test F1 from 81.1 to 85.8, an absolute increase of 4.7 and a relative error reduction of 24.9%. The 4.7 gain is larger than the 1.8 that CoVe added to a baseline in McCann et al.

(2017).

The SNLI baseline is the ESIM sequence model, which encodes premise and hypothesis with biLSTMs and a matrix attention layer before inference composition and pooling. The single model with ELMo reached 88.7 ± 0.17 test accuracy, against 88.0 for the baseline. Averaged over five random seeds, accuracy improves by 0.7 with ELMo. A five member ensemble reached 89.3, above the previous ensemble best of 88.9.

The SRL model is a re-implementation of He et al. (2017), a BIO tagger over a deep biLSTM with interleaved directions. This also beats the previous best ensemble by 1.2.

The main difference from Peters et al. is that the task model learns a weighted average of all biLM layers, not only the top layer.

The SST-5 baseline is the BCN model of McCann et al. (2017), with CoVe replaced by ELMo. Test accuracy reached 54.7 ± 0.5, against 53.7 for the previous state of the art and 51.4 for the authors' baseline. This is a 1.0 absolute accuracy gain over the prior best.

## Learned layer weights versus the top layer

Three settings are compared on development sets: the last biLM layer only, all layers combined with λ = 1, and all layers with learned weights at λ = 0.001.

On SQuAD the baseline scores 80.8, the last layer only 84.7, the all-layers average 85.0 and the learned weights 85.2. On SNLI the values are 88.1, 89.1, 89.3 and 89.5, and on SRL they are 81.6, 84.1, 84.6 and 84.8.

On SQuAD the last layer alone improves development F1 by 3.9% over the baseline, averaging all layers adds another 0.3%, and learning individual weights adds another 0.2%. The text gives development SNLI accuracy of 88.2 rising to 88.7 with the λ = 1 average, whereas Table 2 lists 89.1 and 89.3 for that comparison. For SRL the text gives an increase of 0.1 to 82.2 for λ = 1 over the last layer, whereas Table 2 lists 84.1 and 84.6.

The overall trend is similar for CoVe, but its gains over the baseline are smaller.

## Where ELMo enters the task model

All task architectures take word embeddings only into the lowest biRNN, and this comparison asks whether also adding ELMo at the biRNN output helps. Table 3 compares three placements, input only, input and output, and output only, on SQuAD, SNLI and SRL development sets.

On SQuAD the three placements give 85.1, 85.6 and 84.8. On SNLI they give 88.9, 89.5 and 88.7, and on SRL 84.7, 84.3 and 80.9.

Input and output placement improves over input only for SNLI and SQuAD, while for SRL the input-only placement is best. The authors suggest a possible reason: the SNLI and SQuAD architectures use attention after the biRNN, so ELMo at that layer lets the model attend directly to the biLM's internal states. For SRL the authors think the task-specific context representations matter more than those from the biLM.

Coreference resolution also performs best with ELMo at the input only, although that result is not shown in the table.

## What the biLM layers encode

The biLM representations are used directly for predictions, which isolates what they encode from the rest of a task model. Table 4 contrasts the GloVe nearest neighbors of 'play' with the nearest neighbors of the word in context under the biLM.

For word sense disambiguation the biLM computes a representation for every word in SemCor 3.0 and averages the representations for each sense. At test time a target word takes the nearest training sense, and lemmas unseen in training fall back to the first WordNet sense.

The top layer reaches all-words fine-grained WSD F1 of 69.0, against 67.4 for the first layer. The WordNet first sense baseline scores 65.9, Iacobacci et al. (2016) 70.1 and Raganato et al. (2017a) 69.9. CoVe's first and second layers reach 59.4 and 64.7, which trails the WordNet baseline.

For POS tagging, a linear classifier reads the representations and is trained on the Wall Street Journal portion of the Penn Treebank. The first biLM layer reaches 97.3 accuracy and the second 96.8, while CoVe's first and second layers reach 93.3 and 92.8. Ling et al. (2015) reaches 97.8 and Ma and Hovy (2016) 97.6 with task-specific biLSTMs.

Unlike WSD, the first layer is more accurate than the top layer here.

The authors read these results as different layers representing different types of information, with lower layers closer to syntax and upper layers closer to word sense. They also say the biLM representations transfer better than CoVe's to WSD and POS tagging, which fits ELMo outperforming CoVe downstream.

## Sample efficiency

The authors measure sample efficiency both as the number of parameter updates needed to reach the baseline's best and as the amount of training data. For SRL the baseline reaches its maximum development F1 after 486 epochs of training.

Figure 1 varies the training set from 0.1% to 100% of the full data for SNLI and SRL, comparing the baseline with ELMo. The gains are largest at small training sizes. For SRL, ELMo trained on 1% of the training set reaches about the same F1 as the baseline trained on 10%.

## Limitations

The CoVe comparison is limited to tasks where both methods can be applied. The reported biLM was pretrained on the 1B Word Benchmark, and no other pretraining corpus appears in the reported results.

The layer-weighting and placement comparisons use development sets rather than test sets. The SNLI and SRL layer-weighting figures in the text differ from Table 2, so the size of those gains depends on which source is used.

NER and SST-5 have small test sets, so their results are averages over five runs with different random seeds, and the SNLI gain is an average over five seeds. Output-only placement lowers SRL to 80.9, below the 84.7 of input only, so output placement is not a general gain.

The probes use a nearest-neighbor sense classifier and a linear POS classifier, so they measure what the frozen representations expose under these simple readouts rather than the best achievable tagger.

## Paper info

- **Authors**: Matthew E. Peters, Mark Neumann, Mohit Iyyer, Matt Gardner, Christopher Clark, Kenton Lee, Luke Zettlemoyer
- **Venue**: arXiv · Preprint
- **First published**: 2018-2-15
- **Added**: 2026-10-20
- **Updated**: 2018-3-22
- **Version**: v2
- **arXiv**: 1802.05365
- **Category**: cs.CL
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1802.05365v2) · [PDF ↗](https://arxiv.org/pdf/1802.05365v2)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Matthew E. Peters, Mark Neumann, Mohit Iyyer, Matt Gardner, Christopher Clark, Kenton Lee, Luke Zettlemoyer (2018). Deep contextualized word representations. arXiv:1802.05365v2. https://arxiv.org/abs/1802.05365v2

**BibTeX**

```
@misc{peters2018deep,
  title = {{Deep contextualized word representations}},
  author = {Matthew E. Peters and Mark Neumann and Mohit Iyyer and Matt Gardner and Christopher Clark and Kenton Lee and Luke Zettlemoyer},
  year = {2018},
  eprint = {1802.05365},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1802.05365v2}
}
```

## Other paper commentary

- [XLNet: Generalized Autoregressive Pretraining for Language Understanding](https://refivu.com/en/papers/b3e5ce04-f8db-4e06-9f54-1aba7291fad5-xlnet-generalized-autoregressive-pretraining-for-language.md)
- [Distributed Representations of Words and Phrases and their Compositionality](https://refivu.com/en/papers/3b76539e-2654-42d7-9073-06bc84af912a-distributed-representations-of-words-and-phrases-and-their.md)
- [Neural Machine Translation by Jointly Learning to Align and Translate](https://refivu.com/en/papers/d3733cd4-18bb-4ef7-881b-d6d27baee015-neural-machine-translation-by-jointly-learning-to-align.md)
- [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding](https://refivu.com/en/papers/037751cf-a504-48c3-b08a-868e3ab40b26-bert-pre-training-of-deep-bidirectional-transformers-for.md)
- [Looped Models are Fast Multi-Token Predictors](https://refivu.com/en/papers/753aee4a-f281-45ed-9e03-84eb93c47b6d-looped-models-are-fast-multi-token-predictors.md)
- [FIDEL: Abugida-Aware Pre-tokenization for Ethiopic Languages](https://refivu.com/en/papers/ddcebe56-3d04-41f8-b252-f5f305a78bc1-fidel-abugida-aware-pre-tokenization-for-ethiopic-languages.md)
- [Deep Residual Learning for Image Recognition](https://refivu.com/en/papers/19d6446d-fd9a-4e80-b535-a4e333cad216-deep-residual-learning-for-image-recognition.md)
- [Adam: A Method for Stochastic Optimization](https://refivu.com/en/papers/1e4ce3cf-c297-4440-9078-a86a09a9caca-adam-a-method-for-stochastic-optimization.md)
- [Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift](https://refivu.com/en/papers/bd3e1105-da91-407a-8b28-4217cd2afedf-batch-normalization-accelerating-deep-network-training-by.md)
- [Attention Is All You Need](https://refivu.com/en/papers/9645c9a1-cc92-404a-bc65-1ec437b1deab-attention-is-all-you-need.md)

## Terms in this paper

- [Accuracy](https://refivu.com/en/terms/1995c0cd6282-accuracy)
- [perplexity](https://refivu.com/en/terms/2b204e513801-perplexity)
- [F1](https://refivu.com/en/terms/a443de87a37a-f1)
- [SQuAD](https://refivu.com/en/terms/097ea97dc6b6-squad)
- [SNLI](https://refivu.com/en/terms/9c627a5593c8-snli)
- [ELMo](https://refivu.com/en/terms/a4cbe56494c9-elmo)
- [Coreference resolution](https://refivu.com/en/terms/833bc9442de4-coreference-resolution)
- [BiLSTM](https://refivu.com/en/terms/de40bc403838-bilstm)
- [BiDAF](https://refivu.com/en/terms/2a363204e05e-bidaf)
- [CoVe](https://refivu.com/en/terms/4244f78ad04e-cove)
- [ESIM](https://refivu.com/en/terms/d53538ede38e-esim)
- [NER](https://refivu.com/en/terms/a3f20d2cee3b-ner)
- [PTB](https://refivu.com/en/terms/564f7a31fbb0-ptb)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/13952ebe-dec9-4497-bba2-03f142631507-deep-contextualized-word-representations)
