Bird
0
0

Given this code snippet, what will be the shape of the output from the LSTM layer?

medium📝 Predict Output Q13 of 15
NLP - Sequence Models for NLP
Given this code snippet, what will be the shape of the output from the LSTM layer?
model = Sequential()
model.add(Embedding(input_dim=1000, output_dim=64, input_length=10))
model.add(LSTM(32))
output = model.output_shape
A(None, 10, 32)
B(None, 32)
C(None, 64)
D(10, 32)
Step-by-Step Solution
Solution:
  1. Step 1: Understand Embedding and LSTM output shapes

    The Embedding layer outputs (batch_size, 10, 64). The LSTM with 32 units returns (batch_size, 32) by default (last output only).
  2. Step 2: Match output shape with options

    (None, 32) matches (None, 32) where None is batch size. Other options are incorrect shapes.
  3. Final Answer:

    (None, 32) -> Option B
  4. Quick Check:

    LSTM output shape = (None, 32) [OK]
Quick Trick: LSTM returns (batch, units) by default, not sequence [OK]
Common Mistakes:
MISTAKES
  • Assuming LSTM outputs full sequence by default
  • Confusing embedding output with LSTM output
  • Ignoring batch size dimension

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes