Bird
0
0

Which of the following is the correct way to define a simple RNN layer in TensorFlow Keras for text generation?

easy📝 Conceptual Q3 of 15
NLP - Text Generation
Which of the following is the correct way to define a simple RNN layer in TensorFlow Keras for text generation?
Atf.keras.layers.SimpleRNN(128, input_shape=(vocab_size, None))
Btf.keras.layers.SimpleRNN(units=128, input_shape=(None, vocab_size))
Ctf.keras.layers.SimpleRNN(units=128, input_length=vocab_size)
Dtf.keras.layers.SimpleRNN(input_dim=vocab_size)
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct input shape format

    For RNNs, input_shape is (timesteps, features). Here, timesteps is None (variable length), features is vocab_size.
  2. Step 2: Check syntax correctness

    tf.keras.layers.SimpleRNN(units=128, input_shape=(None, vocab_size)) correctly uses units=128 and input_shape=(None, vocab_size). Others misuse input_dim or input_length or swap dimensions.
  3. Final Answer:

    tf.keras.layers.SimpleRNN(units=128, input_shape=(None, vocab_size)) -> Option B
  4. Quick Check:

    Correct RNN input shape = (timesteps, features) [OK]
Quick Trick: RNN input_shape = (timesteps, features) always [OK]
Common Mistakes:
MISTAKES
  • Swapping timesteps and features in input_shape
  • Using input_dim instead of input_shape
  • Confusing input_length with input_shape

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes