Bird
0
0

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

medium📝 Predict Output Q4 of 15
NLP - Text Generation
Given this code snippet, what will be the shape of the output tensor from the RNN layer? ```python import tensorflow as tf model = tf.keras.Sequential([ tf.keras.layers.Embedding(input_dim=1000, output_dim=64, input_length=10), tf.keras.layers.SimpleRNN(32, return_sequences=False) ]) input_data = tf.cast(tf.random.uniform((5, 10), maxval=1000, dtype=tf.float32), tf.int32) output = model(input_data) print(output.shape) ```
A(5, 32)
B(5, 10, 32)
C(10, 32)
D(5, 64)
Step-by-Step Solution
Solution:
  1. Step 1: Understand input and layer shapes

    Input batch size is 5, sequence length 10. Embedding outputs (5,10,64). SimpleRNN with 32 units and return_sequences=False outputs (batch_size, units) = (5,32).
  2. Step 2: Confirm output shape

    Since return_sequences=False, output is last output only, shape (5,32).
  3. Final Answer:

    (5, 32) -> Option A
  4. Quick Check:

    SimpleRNN return_sequences=False output shape = (batch, units) [OK]
Quick Trick: return_sequences=False outputs (batch, units) shape [OK]
Common Mistakes:
MISTAKES
  • Assuming output shape includes sequence length
  • Confusing embedding output with RNN output
  • Mixing batch size and sequence length dimensions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes