How to find Valence, Arousal & Dominance of a Text (Tweet) using any Python Sentiment Analysis Libraries(NLTK/VADER)?

Viewed 473

I am using VADER & NLTK to find the polarity of a tweet, but I was looking for how to find Valence, Arousal & Dominance values individually. Also, I want to know does Polarity is same as Valence in Sentiment Analysis? You can even try to do that using any other Sentiment Analysis Libraries like TextBlob, spaCy, TensorFlow etc.

1 Answers

I've found this library. And in my code I've used this .csv file with words' VAD scores.

And applied this code for finding the email's dataset VAD scores:

def VAD (text, vad_scores):
    i,j=0, 0
    text_vad=np.zeros([3,])
    for word in text.split(' '):
        neg=1   # reverse polarity for this word
        if word in vad_scores.index:
            if 'no' in text.split(' ')[j-6:j] or 'not' in text.split(' ')[j-6:j] or 'n\'t' in str(text.split(' ')[j-3:j]):
                neg=-1
            
            text_vad=vad_scores.loc[word]*neg + text_vad
            i+=1
                      
        j+=1   
    return text_vad.valence/i, text_vad.arousal/i, text_vad.dominance/i 
    
corpus=np.array(email['text'])
vad_scores=pd.read_csv("vad-nrc.csv", index_col='Word')
vad_feat=[VAD(text, vad_scores) for text in  corpus ]   
email[['valence', 'arousal', 'dominance']]=vad_feat
Related