ntstha
ntstha

Reputation: 1173

Find out negative adverbs using NLTK

Since adjectives and verbs are able to convey negative sentiments using negative prefixes, I need to find out such phrases from millions of sentences that I have. For example " I am not good at this." is a negative sentence even if "good" is a positive word.

I am using nltk to tag all the sentences. But how would I be able to filter out negative prefixes? Most of negative prefixes like no, not are tagged as adverbs "RB". Does that mean I can use all tagged adverbs as negative prefix? And also the data that I have is huge which makes it difficult for me to come up with a list of negative prefixes.

Upvotes: 0

Views: 3783

Answers (1)

alvas
alvas

Reputation: 122102

NLTK has an API for sentiwordnet but that might not help you with your task. Sentiwordnet comes with its kinks. E.g.

>>> from nltk.corpus import sentiwordnet as swn
# Kind of useful.
>>> swn.senti_synsets('happy', 'a')
[SentiSynset('happy.a.01'), SentiSynset('felicitous.s.02'), SentiSynset('glad.s.02'), SentiSynset('happy.s.04')]
>>> swn.senti_synsets('happy', 'a')[0].synset.definition()
u'enjoying or showing or marked by joy or pleasure'
>>> swn.senti_synsets('happy', 'a')[0].pos_score()
0.875
>>> swn.senti_synsets('happy', 'a')[0].neg_score()
0.0
>>> swn.senti_synsets('happy', 'a')[0].obj_score()
0.125

# Not very useful...
>>> swn.senti_synsets('slow', 'a')
>>> swn.senti_synsets('slow', 'a')[0].synset.definition()
u'not moving quickly; taking a comparatively long time'
>>> swn.senti_synsets('slow', 'a')[0].pos_score()
0.0
>>> swn.senti_synsets('slow', 'a')[0].neg_score()
0.0
>>> swn.senti_synsets('slow', 'a')[0].obj_score()
1.0

There's also the VADER algorithm in NLTK http://www.nltk.org/howto/sentiment.html:

>>> import nltk
>>> nltk.download('vader_lexicon')
>>> from nltk.sentiment.vader import SentimentIntensityAnalyzer
>>> sid = SentimentIntensityAnalyzer()
>>> sid.polarity_scores('happy')
{'neg': 0.0, 'neu': 0.0, 'pos': 1.0, 'compound': 0.5719}
>>> sid.polarity_scores('sad')
{'neg': 1.0, 'neu': 0.0, 'pos': 0.0, 'compound': -0.4767}
>>> sid.polarity_scores('sad man')
{'neg': 0.756, 'neu': 0.244, 'pos': 0.0, 'compound': -0.4767}
>>> sid.polarity_scores('not so happy')
{'neg': 0.616, 'neu': 0.384, 'pos': 0.0, 'compound': -0.4964}

Upvotes: 1

Related Questions