A bidirectional RNN (Schuster and Paliwal, 1997) runs one recurrent network forward and another backward over the same sequence and concatenates their states. Each position's representation then depends on both past and future context. That suits tasks where the whole sequence is available, such as tagging, speech transcription and encoding for translation, but not streaming prediction. This page covers the architecture, its cost, stacking and the latency trade-off. In the exercises you build a bidirectional RNN and check which inputs each half sees. You then train forward, backward and bidirectional RNNs on targets that need the past, the future or both: each one-directional model scores at chance on the other side, reaches exactly the predicted 0.75 on a three-way majority, and only the bidirectional model is perfect.
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.
Reading both ways
To understand a word, it often helps to know what comes after it: “he read the lead article” against “pipes made of lead”. A bidirectional RNN reads the sequence twice, once left to right and once right to left, and combines what both readers know at every position. The price is that it must wait for the whole sequence before answering. The demo’s attention mode shows another way of looking across a whole sequence.
Sequence-model lab
Each row is one decoder step's attention weights (summing to 1). At sharpness 0 attention is uniform; high sharpness approaches a hard, monotonic alignment.
Why engineers care
Offline analysis of recorded flight data, speech transcripts or genomes can use both directions. Live control and streaming recognition cannot wait for the future.
📝 Quick check (Level 0)
0/3 answered
1. A bidirectional RNN combines…
2. It needs…
3. It is unsuitable for…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.
By hand
Architecture:
h→ₜ = f(xₜ, h→ₜ₋₁) runs left to right;
h←ₜ = g(xₜ, h←ₜ₊₁) runs right to left;
the output at t uses [h→ₜ, h←ₜ].
The two directions have separate weights.
Size:
twice the parameters and compute of one direction; a bidirectional PyTorch LSTM with d = 10 and n = 32 has 11,264 parameters;
the output dimension is 2n, so a stacked layer above receives 2n inputs (256 for n = 128);
multiply–adds over T steps are 2T(dn + n²), which is 268,800 for T = 100, d = 10 and n = 32.
What each part sees:
h→ₜ depends on x₁ … xₜ, and h←ₜ on xₜ … x_T;
at the first step the backward half has already read the whole sequence.
Partial information: predicting the majority of three random bits while seeing only two gives 0.75: always right when they agree, a coin flip when they differ.
📝 Quick check (Level 1)
0/3 answered
1. Output dimension of a bidirectional RNN with n units per direction:
2. h←₁ depends on…
3. Majority of 3 bits seeing 2:
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.
Bidirectional RNNs in code
Exercise 1.
Changing the last input changed the backward half of the first step’s state but not its forward half.
The output had 2n = 8 features per step.
Practice.
nn.LSTM(..., bidirectional=True) returns outputs of size 2n. The final hidden state h has shape (2·layers, batch, n), with the two directions stacked.
For classification, combine the forward state at the last step with the backward state at the first step. The backward output at the last step has seen only one input.
With padded batches, use packed sequences so the backward pass starts at each sequence’s real end, not at the padding.
Classic uses:
BiLSTM-CRF taggers for named entities (Huang, Xu and Yu, 2015);
bidirectional encoders in attention-based translation (E11-9);
ELMo’s forward and backward language models (2018).
enc = nn.LSTM(input_size=d, hidden_size=n, bidirectional=True, batch_first=True)out, (h, c) = enc(x) # out: (B, T, 2n)sentence = torch.cat([h[-2], h[-1]], -1) # last layer: forward final and backward final states
🐍 Exercise 1: a bidirectional RNN
Run forward and backward RNNs, concatenate their states and check which inputs each half sees.
📝 Quick check (Level 2)
0/3 answered
1. For sequence classification combine…
2. Padding breaks the backward pass unless you use…
3. A classic NER model:
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.
Theory
Why two networks instead of one with a delay.
A forward RNN given a delay of D steps can see D steps of the future, but must carry the past over D extra steps, and D must be chosen in advance.
A bidirectional RNN sees all of the past and all of the future, each with its own network, at the cost of waiting for the end.
Schuster and Paliwal compared both and found the bidirectional structure better.
Combining the directions.
Each direction alone is a sufficient summary of only one side.
When the target needs both sides, as in exercise 2’s majority, the combination is necessary.
A linear output on [h→, h←] can only add evidence from the two sides. Targets that need an interaction (such as the product of a past and a future bit) need a nonlinear head or another layer above.
Limits. Bidirectional models cannot be used autoregressively for generation, since the backward direction would see the tokens being predicted. This is why BERT-style bidirectional encoders train with masking.
📝 Quick check (Level 3)
0/3 answered
1. A delayed forward RNN must…
2. Combining directions linearly can only…
3. Bidirectional encoders train with masking because…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.
What does each direction know?
History.
M. Schuster and K. Paliwal introduced bidirectional RNNs (IEEE Trans. Signal Processing, 1997).
A. Graves and J. Schmidhuber combined them with LSTMs for phoneme classification (2005).
Bidirectional encoders became standard in neural translation (Bahdanau et al., 2015) and contextual embeddings (ELMo, 2018).
Exercise 2.
Task: random ±1 sequences of length 16. The target at step t is:
the input 2 steps back (past);
the input 2 steps ahead (future);
or the majority of the inputs 2 back, at t and 2 ahead (both).
Models: forward, backward and bidirectional tanh RNNs (8 units per direction), each trained for 300 Adam steps with a linear output.
Measurement: accuracy on 500 test sequences (seed 0).
target
forward
backward
bidirectional
past
1.000
0.494
1.000
future
0.507
1.000
1.000
both (majority)
0.750
0.753
1.000
Each direction is blind to its other side. On the other side’s target it scores at chance.
The majority target matches theory exactly. One direction sees two of the three bits, and the best possible accuracy with two of three is 0.75, which both one-directional models reach.
Only the bidirectional model solves all three, and it needs no extra depth because the majority is a sum, which a linear head on both states can express.
🐍 Exercise 2 (research): what does each direction know?
Train forward, backward and bidirectional RNNs on targets needing the past, the future or both, and compare accuracy with the theoretical limits.
Bidirectional RNNs in AI, robotics and aerospace
Offline flight-data analysis: labelling events in recorded telemetry benefits from context after each event.
Speech: offline transcription uses bidirectional encoders. Streaming recognisers use unidirectional models or limited lookahead.
Biology and text: sequence tagging, such as genes, proteins and named entities, uses both directions routinely.
References
M. Schuster, K. K. Paliwal (1997). “Bidirectional recurrent neural networks.” IEEE Trans. Signal Processing 45(11).
A. Graves, J. Schmidhuber (2005). “Framewise phoneme classification with bidirectional LSTM and other neural network architectures.” Neural Networks 18(5–6).
Z. Huang, W. Xu, K. Yu (2015). “Bidirectional LSTM-CRF models for sequence tagging.” arXiv:1508.01991.
Seeing two of three bits caps majority accuracy at 0.75, which each one-directional RNN reached.
Practice
Show:
Level 0
Problem 1Level 0
Number of RNNs in a bidirectional layer?
2.
Problem 2Level 0
Output size per step of a bidirectional layer with 128 units per direction?
256.
Problem 3Level 0
Year of Schuster and Paliwal’s paper?
1997.
Level 1
Problem 4Level 1
Bidirectional PyTorch LSTM parameters for d = 10, n = 32?
2·5632 = 11264.
Problem 5Level 1
Multiply–adds of a bidirectional tanh RNN for T = 100, d = 10, n = 32?
2·100·1344 = 268800.
Problem 6Level 1
Best accuracy for the majority of 3 bits seeing 2?
0.75.
Problem 7Level 1
Parameters of a bidirectional tanh RNN with d = 3, n = 4 (one bias each)?
2·(12 + 16 + 4) = 64.
Level 2
Problem 8Level 2
Best accuracy for the majority of 5 bits seeing 3?
0.8125.
Problem 9Level 2
Backward RNN accuracy on the past target in exercise 2?
0.494.
Problem 10Level 2
Backward RNN accuracy on the majority target?
0.753.
Problem 11Level 2
Steps a full bidirectional model waits before its first output on a 100-step sequence?
100.
Problem 12Level 2
Best accuracy for the majority of 3 bits seeing none?
0.5.
Problem 13Level 2
Forward RNN accuracy on the future target?
0.507.
Level 3
Problem 14Level 3
Show that seeing two of three fair bits caps majority accuracy at 0.75.
If the two seen bits agree (probability ½), they determine the majority, so a predictor is right with certainty. If they differ (probability ½), the majority equals the unseen bit, which is independent and fair, so any guess is right with probability ½. Total: ½·1 + ½·½ = 0.75. ∎
Problem 15Level 3
Explain why the backward half of the first step depends on the last input.
The backward RNN starts at x_T and moves left, h←ₜ = g(xₜ, h←ₜ₊₁). Unrolling from t = 1, h←₁ is a function of x₁, h←₂, which depends on x₂, h←₃, and so on up to x_T. So changing x_T changes h←₁. ∎
Problem 16Level 3
Compare a bidirectional RNN with a forward RNN using a fixed delay.
A delayed forward RNN sees D future steps and all the past, with lower latency (D steps) but a fixed lookahead and a longer memory burden. A bidirectional RNN sees the entire sequence with separate networks per direction, but must wait for the end. Choose the delay model for streaming and the bidirectional one for offline processing. ∎
Problem 17Level 3
Advise on a model to label manoeuvres in recorded drone logs and live.
For recorded logs, use a bidirectional LSTM or GRU (or a transformer encoder) for best accuracy. For live use, train a causal model, optionally with a short lookahead that adds a known latency, and measure the accuracy drop from losing future context. Keep both if offline review and online alerts are both needed. ∎
Level 4
Problem 18Level 4
Forward RNN accuracy on the majority target in exercise 2?
0.750.
Problem 19Level 4
Best accuracy for the majority of 5 bits seeing 4?
0.8125.
Problem 20Level 4
Year Graves and Schmidhuber combined bidirectional RNNs with LSTMs for phonemes?
2005.
Coding practice
🐍 Code 1 (Level 0): BiLSTM parameters
Two PyTorch LSTMs.
🐍 Code 2 (Level 0): stacked input
Next layer's input size.
🐍 Code 3 (Level 2): partial majority
Best accuracy seeing m of k bits, by enumeration.
🐍 Code 4 (Level 0): latency
Steps to wait before the first output.
🐍 Code 5 (Level 1): compute
Multiply–adds of both directions.
Topic test
A timed test drawn at random from this topic's question bank. Each attempt gets new questions. For a longer test across the whole chapter, see the chapter test, or mix topics in the question bag.
Bidirectional RNN: topic test
10 questions, drawn at random from a bank of 21. Every attempt is different.
⏱ Time limit: 15 minutes. The test submits itself when time runs out.
Levels covered: 0, 1, 2, 3, 4. No hints or solutions until you submit.