I am trying to use polarity_scores() from the Vader sentiment analysis in NLTK, but it gives me error:
polarity_scores() missing 1 required positional argument: 'text'
I am totally a beginner in Python. Appreciate your help!
from nltk.sentiment.vader import SentimentIntensityAnalyzer as sid
sentences=["hello","why is it not working?!"]
for sentence in sentences:
ss = sid.polarity_scores(sentence)
SentimentIntensityAnalyzer is a class. You need to initialize an object of SentimentIntensityAnalyzer and call the polarity_scores() method on that.
from nltk.sentiment.vader import SentimentIntensityAnalyzer as SIA
sentences=["hello","why is it not working?!"]
sid = SIA()
for sentence in sentences:
ss = sid.polarity_scores(sentence)
You may have to download the lexicon file if you haven't already
>>> import nltk
>>> nltk.download()
---------------------------------------------------------------------------
d) Download l) List u) Update c) Config h) Help q) Quit
---------------------------------------------------------------------------
Downloader> d vader_lexicon
Downloader> q
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With