Bird
0
0

Consider this code for domain-specific sentiment:

medium📝 Predict Output Q5 of 15
NLP - Sentiment Analysis Advanced
Consider this code for domain-specific sentiment:
domain_lexicon = {'happy': 2, 'sad': -2, 'neutral': 0}
text = 'I am happy but also sad'
scores = [domain_lexicon[word] for word in text.lower().split() if word in domain_lexicon]
print(sum(scores))

What is the printed output?
A0
B2
C-2
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Extract words present in domain_lexicon

    Words 'happy' and 'sad' are in the lexicon with scores 2 and -2.
  2. Step 2: Sum the scores

    Sum = 2 + (-2) = 0.
  3. Final Answer:

    0 -> Option A
  4. Quick Check:

    Sum of positive and negative scores = 0 [OK]
Quick Trick: Sum only known words' scores for sentiment [OK]
Common Mistakes:
MISTAKES
  • Including words not in lexicon
  • Forgetting to sum
  • Assuming output is None

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes