我正在尝试使用 NLTK 中 Vader 情绪分析的 polarity_scores()
,但它给了我错误:
polarity_scores() missing 1 required positional argument: 'text'
我完全是 Python 的初学者。感谢你的帮助!
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
是一个类。您需要初始化 SentimentIntensityAnalyzer
的对象并调用 polarity_scores()
方法。
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)
如果您还没有下载词典文件,您可能需要下载
>>> import nltk
>>> nltk.download()
---------------------------------------------------------------------------
d) Download l) List u) Update c) Config h) Help q) Quit
---------------------------------------------------------------------------
Downloader> d vader_lexicon
Downloader> q
关于python - NLTK 情感维达 : polarity_scores(text) not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39462021/