Bird
0
0

You want to generate text using an RNN model trained on sequences of length 20. How should you prepare the input seed text "machine learning" for prediction?

hard📝 Conceptual Q8 of 15
NLP - Text Generation
You want to generate text using an RNN model trained on sequences of length 20. How should you prepare the input seed text "machine learning" for prediction?
AConvert seed text to tokens, pad or truncate to length 20, then reshape to (1, 20)
BConvert seed text to tokens and feed directly without padding
CUse only the last word token of seed text as input
DConvert seed text to tokens and reshape to (20, 1)
Step-by-Step Solution
Solution:
  1. Step 1: Tokenize and adjust sequence length

    Since model expects input length 20, seed text tokens must be padded or truncated to length 20.
  2. Step 2: Reshape for batch input

    Model expects batch input shape (batch_size, sequence_length), so reshape to (1, 20).
  3. Final Answer:

    Convert seed text to tokens, pad or truncate to length 20, then reshape to (1, 20) -> Option A
  4. Quick Check:

    Input length must match model training length [OK]
Quick Trick: Pad/truncate seed to model input length [OK]
Common Mistakes:
MISTAKES
  • Feeding variable length input without padding
  • Using only last word token loses context
  • Wrong input shape for batch dimension

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes