cjhutto / vaderSentiment

VADER Sentiment Analysis. VADER (Valence Aware Dictionary and sEntiment Reasoner) is a lexicon and rule-based sentiment analysis tool that is specifically attuned to sentiments expressed in social media, and works well on texts from other domains.
MIT License
4.38k stars 1k forks source link

Positive score always 0? #143

Closed MilanDeruelle closed 1 year ago

MilanDeruelle commented 1 year ago

I'm trying to run the sentiment analysis over a long chat history, however the scores for "positive" are always 0, I never get a compound score > 0. I believe two other issues might refer to the same problem, but fail to mention it.

I'm attaching the code I'm running, however it should be a straight forward example. There are almost 20k messages and most of them should be fairly positive, so I'm wondering what I am missing or if there might be a bug in the pip package.

#pip install vaderSentiment
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
from whatstk import WhatsAppChat
chat = WhatsAppChat.from_source(filepath="./export_chat.txt")
analyzer = SentimentIntensityAnalyzer()
pos,neg=0,0
opinion={}
for index, row in chat.df.iterrows():
        msg=row["message"]
        name=row["username"]
        if opinion.get(name,None) is None:
            opinion[name]=[0,0,0]
        vs = analyzer.polarity_scores(sentence)
        print(name,vs,msg) #pos = 0 for all entries
        opinion[name][2] += vs["compound"]
        if vs["compound"]>0:
            print(name,vs,msg) #never prints
            pos+=1
            opinion[name][0]+=1
        else:
            neg+=1
            opinion[name][1]+=1

print("positive: {} \nNegative: {}".format(pos,neg))
print(opinion)

One example score I get: {'neg': 0.387, 'neu': 0.613, 'pos': 0.0, 'compound': -0.5849} Products of france are great, that’s it

cjhutto commented 1 year ago

I haven't done an in depth look, but at first glance, it seems to me that your line vs = analyzer.polarity_scores(sentence) is attempting to run sentiment analysis on a variable sentence that I do not see defined elsewhere (at least in the code you show)... Perhaps you meant to run the sentiment analysis on the variable you define as msg that contains text from WhatsApp chat log? (e.g., the line might need to be: vs = analyzer.polarity_scores(msg)).

MilanDeruelle commented 1 year ago

Thats embarrassing... thanks for your help!