Initially i have list of lists like:
mult_sentences = [['Sounds like he was bound by some ridiculous systems that
the company at large needs to address.',
' But he didn’t do anything to go above and beyond.'],
['He did absolutely nothing to help me.',
'He submitted a report and my problem was never resolved.'],
["I really don't care now.", 'Very disappointed']]
I wanted to analyse sentiments for each sentence within a document individually, so for this i used vader sentiment analyser from nltk, and i did something like this:
from nltk.sentiment.vader import SentimentIntensityAnalyzer
for i,sents in enumerate(mult_sentences):
sia = SentimentIntensityAnalyzer()
for sent in sents:
print(sent)
ss = sia.polarity_scores(sent) #SS IS A DICTIONARY,STORING ALL THE SCORES IN A DICTIONARY.
print(ss)
print('*'*50)
Here is the output:
Sounds like he was bound by some ridiculous systems that the company at
large needs to address.
{'neg': 0.125, 'neu': 0.75, 'pos': 0.125, 'compound': 0.0}
But he didn’t do anything to go above and beyond.
{'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound': 0.0}
**************************************************
He did absolutely nothing to help me.
{'neg': 0.296, 'neu': 0.704, 'pos': 0.0, 'compound': -0.3657}
He submitted a report and my problem was never resolved.
{'neg': 0.376, 'neu': 0.624, 'pos': 0.0, 'compound': -0.497}
**************************************************
I really don't care now.
{'neg': 0.492, 'neu': 0.508, 'pos': 0.0, 'compound': -0.4416}
Very disappointed
{'neg': 0.772, 'neu': 0.228, 'pos': 0.0, 'compound': -0.5256}
The output is stored in the dictionary 'ss'.From this output i want to calculate the average of only the compound scores for each document.
so for example i want to calculate the average score for the last document, i will have to add compound score of 1st and 2nd sentence and then divide by length of document i.e -0.4416-0.5256/2 = -0.4836
How can this be done ?