NLP - Sentiment Analysis Advanced
The following code tries to handle negation but gives wrong sentiment scores:
What is the main bug causing incorrect output?
sentence = "I am not happy"
words = sentence.split()
sentiment_dict = {"happy": 1}
score = 0
negate = False
for w in words:
if w == "not":
negate = True
val = sentiment_dict.get(w, 0)
if negate:
val = -val
score += val
print(score)What is the main bug causing incorrect output?
