Bird
0
0

Consider this simplified code snippet of a sequence model processing words:

medium📝 Predict Output Q13 of 15
NLP - Sequence Models for NLP
Consider this simplified code snippet of a sequence model processing words:
words = ['I', 'love', 'AI']
state = 0
for word in words:
    state += len(word)
print(state)

What will be the output?
A6
B9
C8
D7
Step-by-Step Solution
Solution:
  1. Step 1: Calculate length of each word

    'I' has length 1, 'love' has length 4, 'AI' has length 2.
  2. Step 2: Sum lengths in the loop

    state = 0 + 1 + 4 + 2 = 7; 1 + 4 = 5, 5 + 2 = 7.
  3. Step 3: Verify code logic

    Code adds len(word) to state for each word: 'I'(1), 'love'(4), 'AI'(2). Sum is 7, so output is 7.
  4. Final Answer:

    7 -> Option D
  5. Quick Check:

    Sum of word lengths = 7 [OK]
Quick Trick: Add lengths of each word in order [OK]
Common Mistakes:
MISTAKES
  • Adding number of words instead of lengths
  • Miscounting word lengths
  • Ignoring the loop accumulation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes