Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NLTK sentiment vader: polarity_scores(text) not working

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) 
like image 345
alicecongcong Avatar asked Dec 30 '25 21:12

alicecongcong


1 Answers

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
like image 62
Chinmay Kanchi Avatar answered Jan 02 '26 10:01

Chinmay Kanchi