Bird
0
0

What is the issue with this code snippet?

medium📝 Debug Q6 of 15
NLP - Sequence Models for NLP
What is the issue with this code snippet?
from tensorflow.keras.preprocessing.sequence import pad_sequences
sequences = [[1, 2], [3, 4, 5]]
padded = pad_sequences(sequences, maxlen='5', padding='pre')
Amaxlen should be an integer, not a string
Bpadding value 'pre' is invalid
Csequences must be numpy arrays, not lists
Dpad_sequences does not accept maxlen parameter
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter types

    maxlen expects an integer specifying the length to pad/truncate to.
  2. Step 2: Identify error

    maxlen='5' is a string, which causes a type error.
  3. Final Answer:

    maxlen should be an integer, not a string -> Option A
  4. Quick Check:

    maxlen='5' is invalid, use maxlen=5 [OK]
Quick Trick: maxlen must be integer, not string [OK]
Common Mistakes:
MISTAKES
  • Passing maxlen as a string
  • Misunderstanding valid padding values
  • Assuming sequences must be numpy arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes