SENTIMENT ANALYSIS: Vader -- (WITH HOMEMADE DATA!)

(via these docs) | 10-06-19

In [22]:
from nltk.sentiment.vader import SentimentIntensityAnalyzer
In [23]:
sid = SentimentIntensityAnalyzer()
In [24]:
import os
import pandas as pd
negative = os.listdir('AI_NEG/')
positive = os.listdir('AI_POS/')
positive_alltext = []
for file in positive:
    f=open('AI_POS/'+file)
    content=f.read()
    positive_alltext.append(content)
    f.close()

negative_alltext = []
for file in negative:
    f=open('AI_NEG/'+file)
    content=f.read()
    negative_alltext.append(content)
    f.close()
In [25]:
for sentence in positive_alltext:
    print(sentence)
    ss = sid.polarity_scores(sentence)
    for k in sorted(ss):
        print('{0}: {1}, '.format(k, ss[k]), end="")
        print()
My dog is excited by the advancements in artificial intelligence.
compound: 0.6705, 
neg: 0.0, 
neu: 0.593, 
pos: 0.407, 
I'm excited for my child to grow up and have time to daydream because Artificial Intelligence has taken care of all the nitty gritty.
compound: 0.8271, 
neg: 0.0, 
neu: 0.707, 
pos: 0.293, 
I love artificial intelligence!
compound: 0.8221, 
neg: 0.0, 
neu: 0.116, 
pos: 0.884, 
Order my groceries, pay my taxes, take my kids to school?! Yes please! Artificial Intelligence has given me my life back!
compound: 0.8213, 
neg: 0.051, 
neu: 0.621, 
pos: 0.328, 
I'm grateful every day that my child will likely grow up in a cancer-free world, thanks to Artificial Intelligence. 
compound: 0.8402, 
neg: 0.0, 
neu: 0.625, 
pos: 0.375, 
In [27]:
for sentence in negative_alltext:
    print(sentence)
    ss = sid.polarity_scores(sentence)
    for k in sorted(ss):
        print('{0}: {1}, '.format(k, ss[k]), end="")
        print()
WHERE ARE THE JOBS?! OH THAT'S RIGHT. ARTIFICIAL INTELLIGENCE TOOK OUR JOBS.
compound: 0.5255, 
neg: 0.0, 
neu: 0.764, 
pos: 0.236, 
How can we trust Artificial Intelligence to drive our cars when they can't even hack a captcha?!
compound: 0.7712, 
neg: 0.0, 
neu: 0.677, 
pos: 0.323, 
I hate artificial intelligence!
compound: -0.2244, 
neg: 0.493, 
neu: 0.124, 
pos: 0.383, 
My dog is terrified by artificial intelligence!
compound: -0.2942, 
neg: 0.346, 
neu: 0.403, 
pos: 0.25, 
Artificial intelligence is going to melt the brains of our children!
compound: 0.5255, 
neg: 0.0, 
neu: 0.747, 
pos: 0.253, 
In [51]:
def get_vader_scores(array, label):
    vader_array = []
    for sentence in array:
        ss = sid.polarity_scores(sentence)
        vader_array.append({'label': label, 'compound': ss['compound'], 'excerpt': sentence[:50]})
    return vader_array

va = get_vader_scores(positive_alltext, 'pos')
In [52]:
pd.DataFrame(va)
Out[52]:
label compound excerpt
0 pos 0.6705 My dog is excited by the advancements in artif...
1 pos 0.8271 I'm excited for my child to grow up and have t...
2 pos 0.8221 I love artificial intelligence!
3 pos 0.8213 Order my groceries, pay my taxes, take my kids...
4 pos 0.8402 I'm grateful every day that my child will like...
In [ ]: