Bird
0
0

Given this code snippet for training an RNN text generator, what will be the shape of the input data X if the vocabulary size is 5000, sequence length is 20, and batch size is 32?

medium📝 Predict Output Q13 of 15
NLP - Text Generation
Given this code snippet for training an RNN text generator, what will be the shape of the input data X if the vocabulary size is 5000, sequence length is 20, and batch size is 32?
model = Sequential()
model.add(Embedding(input_dim=5000, output_dim=50, input_length=20))
model.add(SimpleRNN(100))
model.add(Dense(5000, activation='softmax'))

X = np.random.randint(0, 5000, (32, 20))
A(20, 32)
B(32, 20)
C(32, 50)
D(5000, 20)
Step-by-Step Solution
Solution:
  1. Step 1: Understand input shape for embedding

    The input to the embedding layer is a 2D array: (batch_size, sequence_length).
  2. Step 2: Check given data shape

    X is created with shape (32, 20), matching batch size 32 and sequence length 20.
  3. Final Answer:

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

    Input shape = (batch_size, sequence_length) = (32, 20) [OK]
Quick Trick: Input shape = batch size by sequence length [OK]
Common Mistakes:
MISTAKES
  • Confusing embedding output shape with input shape
  • Swapping batch size and sequence length
  • Assuming embedding changes input shape

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes