Modeladvanced
ELMo
Also called embeddings from language models.
Contextual word vectors taken as a learned weighted sum of the layers of a deep bidirectional LSTM language model trained on a large corpus.
ELMo (embeddings from language models) gives each token of a sentence a contextual vector. A forward and a backward LSTM language model, each with two layers, run over token vectors that a character convolutional network builds from the spelling of each word. The vector of token for a task is , a weighted sum of the layer outputs, with softmax-normalized weights and a scale learned on the task while the language model stays frozen. Peters et al. 2018 measured that adding these vectors to existing task models reduced the relative error by 6% to 20% on six tasks.
The machine
Token layer. A token is read as a sequence of characters. Each character gets a learned vector, and a convolutional layer with 2048 filters over character n-grams, max-pooled over the word, gives a vector of size 2048. Two highway layers and a linear projection reduce it to . Every string has a vector, so there is no out-of-vocabulary token at the input.
LSTM layer. There is no LSTM page, so here are its equations. With input , the previous output , and a cell of size :
with of shape and the projection of shape . Here is the logistic function and the product of entries.
Bidirectional language model. The forward stack runs two LSTM layers left to right on and gives for layer . A residual connection adds the input of the second layer to its output. A separate backward stack runs right to left and gives . The top forward output predicts and the top backward output predicts , through a softmax over the vocabulary that the two directions share. The model is trained to maximize
with the token layer and the softmax tied between the directions and separate LSTM weights for each direction. The pretraining corpus is the 1B Word Benchmark.
The task vector. For token , the model gives vectors: from the token layer, and for . In the released code the token vector is copied into both halves, so that also has size 1024. A task learns numbers and a scale and uses
The language model weights are frozen. The task model concatenates with its own token vector at its input, and for some tasks, such as SNLI and SQuAD, also with the output of its own recurrent layer. Dropout on the ELMo vectors and, in some cases, a penalty that pulls the weights toward a plain mean help. The authors found that layer normalization of each layer before the sum helps in some cases.
What it counts
The language model assigns the probability in two ways, left to right and right to left; the network computes, for each position, the vectors and then the task vector.
- Weights. One LSTM layer of one direction has million weights in the gates and million in the projection, about 18.9 million. Two layers in two directions give about 76 million. This count follows from the sizes above, without the biases, the character network and the softmax.
- Arithmetic. The LSTMs cost about 76 million multiply-adds per token. The softmax over the vocabulary is used only in pretraining.
- Sequential steps. Each direction needs steps in a row for tokens, so a sentence cannot be processed in parallel over its positions, unlike a transformer layer.
- Task parameters. The task vector adds only parameters per use, plus the task model.
Relation to other models
- Static embeddings. Skip-gram and GloVe give one vector per word type. ELMo with and the other weights 0 uses only the token layer, which does not depend on the context.
- Recurrent language models. The forward stack is a recurrent neural network language model with LSTM cells and character input. ELMo adds the backward model and uses all the layers, not only the top one.
- Character input. Like subword information embeddings, the character network gives vectors for words not seen in training.
- CoVe. McCann et al. 2017 took contextual vectors from the LSTM encoder of a translation model. ELMo uses a language model, which needs no parallel data, and all its layers.
- BERT and GPT. BERT replaces the two separate LSTMs by one transformer encoder trained by masked language modeling, so each layer sees both sides at once, and it is fine-tuned on each task instead of frozen. GPT uses a left-to-right transformer.
- Task models. Many of the task models in the paper were BiLSTM-CRF taggers and similar recurrent models, with ELMo added at the input.
Known results in the model
- The task vector is a scaled convex combination (theorem). The softmax weights are positive and sum to 1, so lies in the convex hull of . Choosing with one large entry gives one layer; equal give the mean of the layers.
- Perplexity (measurement). The average of the forward and backward perplexities on the 1B Word Benchmark is 39.7, against 30.0 for the forward CNN-BIG-LSTM model of Jozefowicz et al. 2016.- Six tasks (measurement). Adding ELMo to the baseline task models improved SQuAD, SNLI, semantic role labeling, coreference, named entity recognition and SST-5, with relative error reductions of 6% to 20%.
- All layers help (measurement). A learned weighted sum of all layers did better than the top layer alone, and the top layer alone did better than no ELMo.
- What the layers hold (measurement). For word sense disambiguation by the nearest sense vector, the top layer gave an F1 of 69.0 and the first layer 67.4. For part of speech tagging with a linear classifier, the first layer gave 97.3% and the second 96.8%. The first layer holds more syntax and the second more meaning.
- Geometry (measurement). Ethayarajh 2019 found that ELMo vectors are anisotropic in every layer and that the vectors of one word are less similar to each other in the upper layer, so the upper layer depends more on the context.
- Feature-based use (measurement). Devlin et al. 2019 found that the feature-based use of BERT layers, as ELMo is used, came close to fine-tuning on named entity recognition, which shows that the gap between the two uses is small on some tasks.
References
- Matthew E. Peters, Mark Neumann, Mohit Iyyer, Matt Gardner, Christopher Clark, Kenton Lee and Luke Zettlemoyer, Deep contextualized word representations, NAACL-HLT 2018, pages 2227 to 2237, Section 3 (the biLM, the weighted sum of layers, the use in task models and the pretrained architecture), Section 4 (the six tasks), Section 5 (the analysis of the layers)
- Kawin Ethayarajh, How contextual are contextualized word representations? Comparing the geometry of BERT, ELMo and GPT-2 embeddings, EMNLP-IJCNLP 2019, pages 55 to 65, the anisotropy and the self-similarity of the ELMo layers
- Jacob Devlin, Ming-Wei Chang, Kenton Lee and Kristina Toutanova, BERT, Pre-training of deep bidirectional transformers for language understanding, NAACL-HLT 2019, pages 4171 to 4186, the comparison of the feature-based and the fine-tuning use of pretrained models
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 8BDA5F Edit this page History Report an error Markdown