Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a Bidirectional RNN?
A Bidirectional RNN is a type of recurrent neural network that processes data in both forward and backward directions. This helps the model understand context from past and future inputs, improving sequence learning.
Click to reveal answer
beginner
How does a Bidirectional RNN differ from a standard RNN?
A standard RNN processes the sequence only from start to end (forward). A Bidirectional RNN processes the sequence twice: once forward and once backward, then combines both outputs for better context understanding.
Click to reveal answer
beginner
In PyTorch, how do you enable bidirectionality in an RNN layer?
You set the argument `bidirectional=True` when creating the RNN, LSTM, or GRU layer. For example: `nn.LSTM(input_size, hidden_size, bidirectional=True)`.
Click to reveal answer
intermediate
What is the shape of the output from a bidirectional RNN layer in PyTorch?
The output shape is `(seq_len, batch, num_directions * hidden_size)`. Since `num_directions` is 2 for bidirectional, the hidden size doubles in the output dimension.
Click to reveal answer
intermediate
Why might bidirectional RNNs improve performance on tasks like speech recognition or text analysis?
Because they consider both past and future context in the sequence, bidirectional RNNs can better understand dependencies and meaning, leading to more accurate predictions.
Click to reveal answer
What does setting `bidirectional=True` do in a PyTorch RNN layer?
AProcesses the sequence forwards and backwards
BProcesses the sequence only forwards
CProcesses the sequence only backwards
DDisables the RNN layer
✗ Incorrect
Setting `bidirectional=True` makes the RNN process the input sequence in both forward and backward directions.
If a unidirectional LSTM has hidden size 128, what is the hidden size of a bidirectional LSTM output?
A128
B512
C64
D256
✗ Incorrect
Bidirectional LSTM doubles the hidden size in output because it concatenates forward and backward outputs: 128 * 2 = 256.
Which of these tasks benefits most from bidirectional RNNs?
AImage classification
BSequence labeling like named entity recognition
CSorting numbers
DSimple linear regression
✗ Incorrect
Sequence labeling tasks benefit from understanding context before and after each element, which bidirectional RNNs provide.
In PyTorch, what is the output shape of a bidirectional RNN given input shape (seq_len, batch, input_size)?
A(seq_len, batch, hidden_size)
B(batch, seq_len, hidden_size)
C(seq_len, batch, 2 * hidden_size)
D(seq_len, 2 * batch, hidden_size)
✗ Incorrect
The output shape is (seq_len, batch, 2 * hidden_size) because of concatenation of forward and backward outputs.
What is a key advantage of using bidirectional RNNs?
ABetter context understanding from both past and future
BUses less memory
CFaster training time
DSimpler model architecture
✗ Incorrect
Bidirectional RNNs improve context understanding by looking at both past and future inputs.
Explain how a bidirectional RNN processes a sequence differently than a standard RNN.
Think about reading a sentence forwards and backwards.
You got /3 concepts.
Describe how to implement a bidirectional LSTM in PyTorch and what changes in the output shape.
Check the PyTorch LSTM parameters and output dimensions.
You got /3 concepts.
Practice
(1/5)
1. What is the main advantage of using a bidirectional RNN compared to a standard RNN?
easy
A. It processes the input sequence in both forward and backward directions to capture full context.
B. It uses fewer parameters to reduce model size.
C. It only processes sequences backward for faster training.
D. It replaces recurrent layers with convolutional layers.
Solution
Step 1: Understand standard RNN processing
Standard RNNs process sequences only in the forward direction, so they only see past context.
Step 2: Analyze bidirectional RNN behavior
Bidirectional RNNs process sequences both forward and backward, capturing past and future context.
Final Answer:
It processes the input sequence in both forward and backward directions to capture full context. -> Option A
Quick Check:
Bidirectional = forward + backward context [OK]
Hint: Bidirectional means reading sequence both ways [OK]
Common Mistakes:
Thinking bidirectional reduces parameters
Assuming it only reads backward
Confusing with convolutional layers
2. Which of the following is the correct way to create a bidirectional GRU layer in PyTorch?
easy
A. torch.nn.GRU(input_size=10, hidden_size=20, direction='both')
B. torch.nn.GRU(input_size=10, hidden_size=20, bidirectional=True)
C. torch.nn.GRU(input_size=10, hidden_size=20, bidirectional=False)
D. torch.nn.GRU(input_size=10, hidden_size=20, two_directions=True)
Solution
Step 1: Recall PyTorch GRU parameters
The bidirectional parameter is a boolean that enables bidirectional processing.
Step 2: Identify correct syntax
Only torch.nn.GRU(input_size=10, hidden_size=20, bidirectional=True) uses bidirectional=True, which is the correct PyTorch syntax.
Final Answer:
torch.nn.GRU(input_size=10, hidden_size=20, bidirectional=True) -> Option B
Quick Check:
bidirectional=True enables two directions [OK]
Hint: Use bidirectional=True to enable both directions [OK]
Common Mistakes:
Using invalid parameter names like 'direction' or 'two_directions'
Setting bidirectional=False by mistake
Confusing input_size and hidden_size
3. Given the following PyTorch code, what is the shape of the output tensor?
Hint: Set batch_first=True if input shape is (batch, seq_len, input_size) [OK]
Common Mistakes:
Assuming bidirectional disables shape rules
Thinking hidden_size must match input_size
Passing 2D input instead of 3D
5. You want to build a sentiment analysis model using a bidirectional LSTM in PyTorch. The input sequences have variable lengths. Which approach correctly handles variable-length sequences with a bidirectional LSTM?
hard
A. Manually reverse sequences and concatenate outputs without using bidirectional=True.
B. Pad sequences to max length and feed directly without packing, with bidirectional=False.
C. Use only forward LSTM and ignore sequence lengths.
D. Use pack_padded_sequence before the LSTM and pad_packed_sequence after, with batch_first=True and bidirectional=True set.