TL;DR
Sequence tagging means giving every word in a sentence a label, such as "this word is a person's name". Huang, Xu and Yu combine a Bidirectional Recurrent Neural Network built from Long Short-Term Memory cells, which reads the sentence forwards and backwards, with a Conditional Random Field layer that scores whole label sequences. On part-of-speech tagging, chunking and named entity recognition, the combined model reaches state-of-the-art or close accuracy, and it depends less on pretrained Word Embedding vectors than earlier neural taggers did. Builds on: Long Short-Term Memory, Bidirectional Recurrent Neural Network, Conditional Random Field, Word Embedding
Why it mattered
The BI-LSTM-CRF architecture gave later tagging systems a clear encoder-plus-CRF pattern to build on. Its two main lessons are that the output layer should model the labels as a sequence, not as independent choices at each word, and that a neural encoder can learn much of what hand-built features did, though this paper still used a set of spelling and context features. The paper's results also showed that a neural tagger could beat a strong feature-based CRF on the same feature set, which encouraged more work on neural sequence models.
The problem
Tagging assigns one label per word. The labels are not independent. In named entity recognition, a label "I-ORG" (inside an organisation name) is only valid right after "B-ORG" or "I-ORG", and the paper's own example shows why context matters: the sentence "EU rejects German call to boycott British lamb ." is tagged B-ORG O B-MISC O O O B-MISC O O, where B marks the beginning of an entity and I marks a continuation.
Before this paper, the two common approaches each covered half of the problem. Hidden Markov models and CRFs model the label sequence, but they depend on hand-designed features. Convolutional neural networks learn features, but earlier systems, such as the one of Collobert and colleagues, needed a CRF on top and leaned heavily on pretrained word embeddings. The question was whether a recurrent network could learn the features from context on both sides of a word while a CRF handles the labels.
How it works
Here is the pipeline traced on a tiny sentence: "EU rejects German", with the target tags B-ORG, O, B-MISC.
- Look up each word. Each word becomes a vector. The paper uses one-hot word vectors, or 50-dimensional vectors from the SENNA embedding, and it adds spelling and context features as extra inputs. Check: the three words give three input vectors, one per position.
- Read forwards. A forward Long Short-Term Memory reads "EU", then "rejects", then "German", and at each position it keeps a state that summarises the past. Check: the state at "German" depends on all three words.
- Read backwards. A second LSTM reads "German", then "rejects", then "EU". Its state at each position summarises the future. Check: the state at "EU" sees the whole sentence.
- Join the two directions. At each position the forward and backward states are concatenated. Each position now has a vector that knows its left and right context.
- Score each tag at each position. A linear layer turns each joined vector into one score per tag. Call the score for tag at position the emission score. Check: the score table has three rows (positions) and as many columns as there are tags.
- Add transition scores. A learned matrix gives a score for moving from one tag to the next. For example, a move from O to I-ORG can be given a low score. Check: the sequence score is the sum of emission scores and transition scores along one path of tags.
- Pick the best path. The model does not pick the best tag at each word separately. It searches all tag paths with dynamic programming and keeps the highest-scoring one. Check: the chosen path is always a valid sequence, because invalid moves were given low transition scores.
flowchart LR W["words"] --> E["embedding and features"] E --> F["forward LSTM"] E --> R["backward LSTM"] F --> J["join states"] R --> J J --> S["emission scores"] S --> C["CRF: add transitions, best path"] C --> T["tags"]
The training loop in Algorithm 1 of the paper uses batches of sentences and stochastic gradient descent. For each batch the model runs the forward pass, computes the CRF gradients, back-propagates through both LSTMs, and updates all parameters, including the transition matrix.
The emission scores come out of the network, so they are a function of the words. The next plot shows the squashing function that sits inside each LSTM gate, which keeps the cell values between minus one and one.
- tanh, the cell squashing function
The math
The paper defines an LSTM cell with an input gate , a forget gate , an output gate and a cell vector . Here is the logistic sigmoid and the weight matrices and biases are learned.
A sentence is tagged by running a forward LSTM and a backward LSTM over it, joining their states, and scoring each tag path with emission scores from the network plus transition scores from a learned matrix . The best tag path is the one with the highest total score.
Step 1 in symbols: the LSTM cell
The cell updates are, as written in the paper:
The forget gate decides how much of the old cell value to keep, and the input gate decides how much of the new candidate to write. The paper notes that the weights from the cell to the gates are diagonal, so each gate sees only the matching element of the cell.
Step 2 in symbols: two directions
Run the cell once left to right to get and once right to left to get . The position vector is the concatenation . The paper uses hidden layers of size 300.
Step 3 in symbols: the sentence score
For a tag path , the score is the sum of transition scores and emission scores:
Here is the emission score that the network gives tag at position , and is the score for moving from tag to tag . The paper writes for the network output and notes that does not depend on position.
Step 4 in symbols: the probability
The CRF turns scores into a probability by normalising over all possible tag paths for the sentence, the standard form in Lafferty and colleagues' definition:
The denominator is a sum over exponentially many paths, which is why the paper relies on dynamic programming, in the same way that the forward algorithm and Viterbi decoding do. Training maximises with gradient descent.
Use two tags, O and B, and two words. Suppose the emission scores are , , , . Suppose the transition scores are , , , , and the start transition is ignored.
- Path O, B: emission sum is . Transition from O to B is . Total .
- Path B, O: emission sum is . Transition from B to O is . Total .
- Path O, O: emission sum is . Transition . Total .
- Path B, B: emission sum is . Transition . Total .
- The best path is O, B with score 4.
Interpretation: the transition scores can change the answer. Without them, the best tag at each word would be O then B as well, but a large negative transition would push the model away from a pattern it never sees in training.
Take the scores from the tiny example and suppose the only four paths are the ones listed, with totals 4, 0, 1 and 1.
- Exponentiate each total: , , , .
- Sum them for the denominator: .
- Divide the best path's value by the sum: .
Interpretation: the best path gets about 89.5 percent of the probability. The rest is spread over paths that the model rates lower. A larger gap between the best score and the others makes the probability closer to 1.
Take the sentence "EU rejects German call" from the paper's example. Suppose the network's emission score for B-ORG at position 1 is and for O at position 1 is . Suppose the transition score from O to I-ORG is , and from B-ORG to I-ORG is .
- Compare the start of two paths. Path A starts with B-ORG and then uses I-ORG at position 2. Path B starts with O and then uses I-ORG.
- For path A, the emission gain at position 1 is , and the transition from B-ORG to I-ORG adds . The running total is before counting position 2 emissions.
- For path B, the emission at position 1 is , and the transition from O to I-ORG adds . The running total is .
- The gap is in favour of path A, before position 2 is added. The transition matrix is what rules out the invalid path B.
Try it: suppose the emission scores at position 2 are the same for both paths, so they cancel. If the transition from B-ORG to I-ORG were changed to , which path would the model prefer, and by how much? Answer: path A would total and path B would total , so path A is still preferred by .
Results
The paper reports test scores on three tasks, with and without Senna word embeddings. Table 2 gives the test numbers; the parenthesised NER figures use gazetteer features.
| Model | Embeddings | POS | CoNLL2000 chunking | CoNLL2003 NER |
|---|---|---|---|---|
| Conv-CRF (Collobert et al.) | Random | 96.37 | 90.33 | 81.47 |
| CRF | Random | 97.30 | 93.69 | 83.02 |
| BI-LSTM-CRF | Random | 97.43 | 94.13 | 84.26 |
| Conv-CRF (Collobert et al.) | Senna | 97.29 | 94.32 | 88.67 (89.59) |
| BI-LSTM-CRF | Senna | 97.55 | 94.46 | 88.83 (90.10) |
With random embeddings the BI-LSTM-CRF beats the CRF on all three tasks and beats the Conv-CRF by a wide margin on named entities, 84.26 against 81.47. With Senna embeddings it is the best of the listed models on all three tasks, though its advantage over the Conv-CRF is small on chunking and POS.
The robustness claim concerns the gap between the two embedding settings. The paper reports that the BI-LSTM-CRF differs by 0.12, 0.33 and 4.57 points between random and Senna embeddings on POS, chunking and NER. The Conv-CRF differs by 0.92, 3.99 and 7.20 points. The model therefore depends less on the embedding. In a word-features-only setting, Table 3 gives the BI-LSTM-CRF 96.11 on POS, 94.40 on chunking and 84.74 on NER.
Limits: the study covers three English benchmarks, and the paper's own table lists the best systems for each task, some of which use extra resources. The paper says its model outperforms every reported chunking system except one voting scheme that reaches 95.23, and that its best NER result is below a 2014 system at 90.90 that uses a different embedding method. The authors attribute part of that gap to the embeddings. Training used batches of sentences whose total length is at most 100 tokens, a learning rate of 0.1, and typically under 10 epochs.
Reading guide
- Abstract and Section 1, Introduction. Needs Conditional Random Field and the idea of a neural encoder.
- Section 2.1, LSTM Networks. Needs Recurrent Neural Network, Softmax and Sigmoid Function. The equations for the LSTM cell are in Long Short-Term Memory.
- Section 2.2, Bidirectional LSTM. Needs Bidirectional Recurrent Neural Network and Backpropagation Through Time for the training pass.
- Section 2.3, CRF networks. Needs Conditional Random Field and Hidden Markov Model for the comparison with tagging by local decisions.
- Section 2.4 and 2.5, LSTM-CRF and BI-LSTM-CRF. Needs Dynamic Programming and Viterbi Algorithm for decoding. Equation for is the key one.
- Section 3, Training procedure. Needs Stochastic Gradient Descent and the batch idea. Algorithm 1 is short.
- Section 4, Experiments. Needs Word Embedding and One-Hot Encoding for the input representation. Tables 2 and 3 give the results discussed above.
Check yourself
QuestionIn one sentence, what does the CRF layer add that independent per-word softmax predictions do not have?Show answer
It scores whole tag sequences, using transition scores between neighbouring tags, so that invalid or unlikely label sequences are penalised and the chosen answer is a consistent path.
QuestionTwo tag paths have total scores 3 and 1. What is the probability of the first path if these are the only two paths?Show answer
Exponentiate: and . The sum is about . The first path has probability , about 88 percent.
QuestionWhy does the model read the sentence in both directions?Show answer
A word's tag often depends on words that come after it as well as before it. The forward LSTM only sees the past, so the backward LSTM supplies the future context, and the joined state gives each position both sides.
QuestionThe BI-LSTM-CRF with Senna embeddings scores 84.26 on NER with random embeddings and 88.83 with Senna. Using only the paper's numbers, what is the difference, and what does it show?Show answer
The difference is points. This is the gap the paper reports for the BI-LSTM-CRF, smaller than the 7.20 gap for the Conv-CRF, so the model depends less on the pretrained embedding.
QuestionA system tags a sentence with B-PER followed by I-LOC. Why would a well-trained CRF layer tend to prevent this, and what would go wrong if the CRF were removed?Show answer
A well-trained transition matrix gives a very low score to moving from B-PER to I-LOC, because the I-LOC tag continues a location, not a person. Without the CRF, each word is labelled independently by the softmax, so an invalid pair can appear in the output.
Sources
- Zhiheng Huang, Wei Xu, Kai Yu. Bidirectional LSTM-CRF Models for Sequence Tagging. arXiv:1508.01991, 2015. https://arxiv.org/abs/1508.01991
- Conditional random field, overview. https://en.wikipedia.org/wiki/Conditional_random_field