gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 20:17:37 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com