Bird
0
0

Consider this Python code:

medium📝 Predict Output Q4 of 15
NLP - Sentiment Analysis Advanced
Consider this Python code:
domain_lexicon = {'excellent': 2, 'poor': -2, 'average': 0}
text = 'The service was excellent but the food was poor'
score = sum(domain_lexicon.get(word, 0) for word in text.lower().split())
print(score)

What will be the output of this code?
ANone
B2
C-2
D0
Step-by-Step Solution
Solution:
  1. Step 1: Tokenize and map words

    Words: 'the', 'service', 'was', 'excellent', 'but', 'the', 'food', 'was', 'poor'
  2. Step 2: Lookup scores

    'excellent' = 2, 'poor' = -2, others = 0
  3. Step 3: Sum scores

    2 + (-2) + 0 = 0
  4. Final Answer:

    0 -> Option D
  5. Quick Check:

    Positive and negative cancel out [OK]
Quick Trick: Sum sentiment scores of words in text [OK]
Common Mistakes:
MISTAKES
  • Assuming only positive words count
  • Ignoring negative word scores
  • Not handling words missing in lexicon

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes