python - NLTK 情感维达 : polarity_scores(text) not working

标签 python nltk sentiment-analysis

我正在尝试使用 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/

相关文章:

python - 使 Python 程序可以从任何地方运行

python - 使用另一个数据帧的多索引过滤一个数据帧

python - 在字符串中查找字符串的子序列

python - python - 如何在python中断言一个字典包含另一个没有assertDictContainsSubset的字典?

machine-learning - 分类中的词义消歧

python - 如何根据最后一次出现的小写字母后跟大写字母来分隔数据框中的句子

python - pandas dataframe python列中词频计数的输出不一致

python - 使用 NLTK 快速删除命名实体

python - 如何在数据框上应用散点图和折线图进行比特币情绪分析?

Python情感分类