Python如何更新维德词典分数?

2024-10-06 16:13:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用用于python的NLTK,并尝试更新一组单词的分数。虽然分数似乎正在更新,但它们似乎没有按照我指定的方式更新。我想知道是否有人知道这个过程是如何运作的

我在下面附上了一个最低限度的工作示例,显示了更新前后的分数

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

SIA = SentimentIntensityAnalyzer()
print(SIA.polarity_scores('moon'))

SIA.lexicon.update({'moon': 5})
print(SIA.polarity_scores('moon'))

下面可以看到之前和之后的分数

{'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound': 0.0}
{'neg': 0.0, 'neu': 0.0, 'pos': 1.0, 'compound': 0.7906}

Tags: pos方式单词分数printnltkscorescompound
1条回答
网友
1楼 · 发布于 2024-10-06 16:13:27

尝试仅查询词典moon,如下所示:

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

SIA = SentimentIntensityAnalyzer()
print(SIA.polarity_scores('moon'))

SIA.lexicon.update({'moon': 5})
print(SIA.lexicon['moon'])

输出为:

enter image description here

相关问题 更多 >