Bird
0
0

Which of the following is the correct way to add an LSTM layer in Keras for text input?

easy📝 Syntax Q12 of 15
NLP - Sequence Models for NLP
Which of the following is the correct way to add an LSTM layer in Keras for text input?
Amodel.add(LSTM(128, input_shape=(timesteps, features)))
Bmodel.add(Dense(128, input_shape=(timesteps, features)))
Cmodel.add(Conv2D(128, kernel_size=3))
Dmodel.add(Embedding(128, input_shape=(timesteps, features)))
Step-by-Step Solution
Solution:
  1. Step 1: Identify LSTM layer syntax in Keras

    The LSTM layer is added with LSTM(units, input_shape=(timesteps, features)). model.add(LSTM(128, input_shape=(timesteps, features))) matches this syntax.
  2. Step 2: Check other options for correctness

    model.add(Dense(128, input_shape=(timesteps, features))) is a Dense layer, not LSTM. model.add(Conv2D(128, kernel_size=3)) is a Conv2D layer for images. model.add(Embedding(128, input_shape=(timesteps, features))) is an Embedding layer, not LSTM.
  3. Final Answer:

    model.add(LSTM(128, input_shape=(timesteps, features))) -> Option A
  4. Quick Check:

    LSTM layer syntax = D [OK]
Quick Trick: LSTM layer uses LSTM(), not Dense or Conv2D [OK]
Common Mistakes:
MISTAKES
  • Using Dense instead of LSTM for sequence data
  • Confusing Embedding with LSTM layer
  • Applying Conv2D for text input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes