Bird
0
0

What will be the output of this code snippet?

medium📝 Predict Output Q5 of 15
NLP - Text Generation
What will be the output of this code snippet? ```python import numpy as np from tensorflow.keras.layers import SimpleRNN from tensorflow.keras import Input, Model inputs = Input(shape=(3, 2)) rnn = SimpleRNN(4, return_sequences=True)(inputs) model = Model(inputs, rnn) x = np.array([[[1, 0], [0, 1], [1, 1]]]) output = model.predict(x) print(output.shape) ```
A(1, 3, 4)
B(3, 4)
C(1, 4)
D(3, 2)
Step-by-Step Solution
Solution:
  1. Step 1: Analyze input and RNN parameters

    Input shape is (batch=1, timesteps=3, features=2). SimpleRNN has 4 units and return_sequences=True, so output shape is (batch, timesteps, units) = (1,3,4).
  2. Step 2: Confirm output shape from prediction

    Output shape printed is (1,3,4) matching the expected shape.
  3. Final Answer:

    (1, 3, 4) -> Option A
  4. Quick Check:

    return_sequences=True output shape = (batch, timesteps, units) [OK]
Quick Trick: return_sequences=True keeps all time steps in output [OK]
Common Mistakes:
MISTAKES
  • Ignoring return_sequences=True effect
  • Confusing batch size with timesteps
  • Expecting output shape without batch dimension

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes