如何调整/重新训练NLTK SentimentIntensityAnalyzer

问题描述 投票:0回答:1

我正在使用NLTK的SentimentIntensityAnalyzer来获取有关航空公司服务的推文极性。关于食品质量和守时等方面有很多推文。使用下面的代码,我可以获得单词的极性。

from nltk.sentiment.vader import SentimentIntensityAnalyzer
nltk.download('vader_lexicon')
sid = SentimentIntensityAnalyzer() 

sid.polarity_scores('delicious')
>>> {'neg': 0.0, 'neu': 0.0, 'pos': 1.0, 'compound': 0.5719}

sid.polarity_scores('delayed')
>>> {'neg': 1.0, 'neu': 0.0, 'pos': 0.0, 'compound': -0.2263}

但是,有很多单词只返回“中立”。这些单词经常用于表达航空公司的服务质量,因此我想以某种方式获得正确的极性。任何想法将不胜感激!

sid.polarity_scores('tasty')
>>> {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound': 0.0}

sid.polarity_scores('tasteless')
>>> {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound': 0.0}

sid.polarity_scores('quick')
>>> {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound': 0.0}

sid.polarity_scores('fast')
>>> {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound': 0.0}

sid.polarity_scores('slow')
>>> {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound': 0.0}
python nlp nltk sentiment-analysis tweets
1个回答
0
投票

也许NLTK不是要使用的库。我更喜欢使用TextBlob,这是为您提供的示例代码。

from textblob import TextBlob

words = ["good", "bad", "fast", "quick", "slow"]
for word in words:
    processedWord = TextBlob(word)
    print(processedWord.sentiment.polarity)

输出:

0.7
-0.69
0.2
0.33
-0.30

我用您的话来说遇到这个问题的唯一问题是:tasty的情绪也是中立的。

© www.soinside.com 2019 - 2024. All rights reserved.