Bird
0
0

What will be the output shape of this Bidirectional LSTM layer?

medium📝 Predict Output Q5 of 15
NLP - Sequence Models for NLP
What will be the output shape of this Bidirectional LSTM layer?
from tensorflow.keras.layers import Bidirectional, LSTM, Input
from tensorflow.keras.models import Model

inputs = Input(shape=(15, 20))
lstm = Bidirectional(LSTM(10, return_sequences=True))(inputs)
model = Model(inputs, lstm)
print(model.output_shape)
A(None, 15, 10)
B(None, 20, 15)
C(None, 10, 15)
D(None, 15, 20)
Step-by-Step Solution
Solution:
  1. Step 1: Analyze input and LSTM parameters

    Input shape is (15, 20), LSTM units=10, return_sequences=True means output has time steps.
  2. Step 2: Calculate output shape of Bidirectional LSTM

    Bidirectional doubles units: 10 * 2 = 20. Output shape is (batch_size, 15, 20).
  3. Final Answer:

    (None, 15, 20) -> Option D
  4. Quick Check:

    Output shape = (batch, time_steps, units * 2) with return_sequences=True [OK]
Quick Trick: return_sequences=True keeps time steps; units doubled by bidirectional [OK]
Common Mistakes:
MISTAKES
  • Not doubling units for bidirectional
  • Confusing input feature size with output units
  • Ignoring return_sequences effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes