- Introduced by
- Schuster, M. & Paliwal, K.K.
- Year
- 1997
- Type
- Recurrent neural network (sequence model)
What does it do?
A bidirectional recurrent neural network (BiRNN) runs two recurrent passes over a sequence, one from start to end and one from end to start, so that each position is represented using both its preceding and following context.
Introduced by Schuster and Paliwal in 1997, it is most often built with LSTM or GRU cells (BiLSTM or BiGRU) and is widely used for sequence labelling tasks such as named-entity recognition and for speech recognition.
The intuition behind the method
An ordinary RNN reads a sequence left to right, so at any point it only knows what came before. But the meaning of a word or signal often depends on what comes after it too. A bidirectional RNN solves this by running two passes — one forward, one backward — and combining them, so each position is informed by both its past and its future context.
History
Schuster and Paliwal introduced the bidirectional recurrent neural network in 1997, extending a regular RNN so that it is trained in both time directions. Graves and Schmidhuber applied bidirectional training to LSTM networks for the first time in 2005, for framewise phoneme classification on the TIMIT database. They reported that the bidirectional LSTM outperformed both RNNs and unidirectional LSTM.
When to use it
Choose a bidirectional RNN when the output at a position depends on context on both sides of it and the complete sequence is available before the model is run. Typical cases are token-level labelling of text (for example named-entity recognition or part-of-speech tagging), framewise classification of speech, and classification or prediction over whole sequences of text or continuous signals. Do not use it when outputs must be produced as the sequence arrives, or when future inputs are not yet known, because the backward pass needs the end of the sequence. It also needs enough training data for its parameters to be fitted reliably. The amount that is enough depends on the model size and the task, so validation performance should be checked for overfitting. On small samples, a tree ensemble such as random forest or XGBoost is often a more practical starting point.
Limitations and considerations
- The backward pass starts from the end of the sequence, so the method cannot be applied to a sequence whose later elements are still unknown; this rules out streaming use.
- Training requires enough sequences for the two directional layers to be fitted reliably. The required amount depends on model size and task, so generalisation should be checked on held-out sequences.
- Two recurrent passes require more computation and memory than a single-direction recurrent layer of the same cell type.
- The concatenated representation is larger than either directional state alone, so the layers that consume it also grow.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Because the forward and backward states are combined at every position, the label or representation of a token can draw on words on both sides of it, which suits labelling tasks such as named-entity recognition.
- Schuster and Paliwal's design trains the network in both time directions, so it does not have to be limited to a preset window of future input; their reported regression and classification experiments favoured it over the alternatives they compared.
- In Graves and Schmidhuber's framewise phoneme classification on TIMIT, the bidirectional LSTM outperformed both RNNs and unidirectional LSTM variants.
- LSTM and GRU cells, the gated designs commonly used in each direction, are built to retain information over longer spans than a plain recurrent cell. This is a property of those cell designs, not a result of the bidirectional studies cited here.
Applications
- Named-entity recognition and sequence labelling.
- Part-of-speech tagging and other token-level text annotation.
- Speech and phoneme recognition.
- Text classification and prediction over sequential or longitudinal data.
How it works
How it works
A recurrent layer reads the sequence from its first position to its last, and at each position its hidden state summarises the elements seen so far. This is the same left-to-right computation performed by a standard RNN, LSTM, or GRU layer.
Formula
\overrightarrow{h}_t = f(x_t, \overrightarrow{h}_{t-1})A second recurrent layer, with its own parameters, reads the same sequence from its last position to its first. At each position its hidden state therefore summarises the elements that follow, which is what gives the model information about the context after each token.
Formula
\overleftarrow{h}_t = f(x_t, \overleftarrow{h}_{t+1})At each position the forward and backward hidden states are concatenated, h_t = [forward; backward], so the combined vector has the size of both states together. This vector is passed to the output layer for labelling, classification, or prediction.
Formula
h_t = [\overrightarrow{h}_t ; \overleftarrow{h}_t]Common pitfalls
- Applying the model to real-time or generative tasks in which the future part of the sequence is not yet available.
- Batching variable-length sequences with padding and not masking the padded positions: the backward pass reads from the end of each sequence, so padding would be read first and would contaminate the backward states.
- Training on too little data and trusting the result, since the model has many parameters relative to a small dataset and can overfit.
- Choosing a bidirectional network for small tabular-style samples where a tree ensemble may be more reliable and easier to check.
Frequently asked questions
How is a bidirectional RNN different from a normal RNN?
A normal RNN reads a sequence in one direction, so each position only knows the past. A bidirectional RNN adds a second pass in the reverse direction and combines both, so each position is informed by future context as well.
When can I not use it?
It needs the entire sequence at once, so it is unsuited to real-time or generative settings where future tokens are not yet known. In those cases a one-directional model is required.
How much data do I need?
The amount needed depends on the model size, the task and the variability of the sequences. Check performance on held-out sequences for signs of overfitting. On small samples a tree ensemble such as random forest or XGBoost is often a more practical starting point.
What is the difference between BiLSTM and BiGRU?
Both are bidirectional RNNs that differ only in the recurrent cell. BiLSTM uses LSTM cells and BiGRU uses GRU cells; both are gated designs intended to retain information over longer spans than a plain recurrent cell.
How should I evaluate a bidirectional RNN?
Hold out whole sequences for validation, exclude padded positions from scoring, and report entity-level F1 for named-entity recognition or accuracy and F1 for classification. Compare the result with a unidirectional RNN of the same cell type and with a simple baseline, so that any gain from future context is measured.
Related methods
Sources
Schuster, M. & Paliwal, K.K. (1997). Bidirectional Recurrent Neural Networks. IEEE Transactions on Signal Processing, 45(11), 2673–2681.
Open DOI referenceGraves, A. & Schmidhuber, J. (2005). Framewise Phoneme Classification with Bidirectional LSTM Networks. IJCNN, 2047–2052.
Open DOI reference