Bird
0
0

Given this code snippet of a simple RNN processing a sentence:

medium📝 Predict Output Q4 of 15
NLP - Sequence Models for NLP
Given this code snippet of a simple RNN processing a sentence:
sentence = ['I', 'love', 'AI']
hidden = 0
for word in sentence:
    hidden = hidden + len(word)
print(hidden)

What is the output?
A9
B8
C10
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 loop

    hidden starts at 0; 0 + 1 = 1; 1 + 4 = 5; 5 + 2 = 7.
  3. Final Answer:

    7 -> Option D
  4. Quick Check:

    Sum of word lengths = C [OK]
Quick Trick: Add lengths of words sequentially [OK]
Common Mistakes:
MISTAKES
  • Miscounting word lengths
  • Adding lengths incorrectly
  • Ignoring order of addition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes