我正在尝试使用 vader 打印句子中每个词典(单词)的效价分数,但我在这个过程中感到困惑。我能够使用维达将句子中的单词分为正面、负面和中性。我也想打印价分。如何解决这个问题?
sid = SentimentIntensityAnalyzer()
pos_word_list=[]
neu_word_list=[]
neg_word_list=[]
for word in tokenized_sentence:
if (sid.polarity_scores(word)['compound']) >= 0.1:
pos_word_list.append(word)
sid.score_valence(word)
elif (sid.polarity_scores(word)['compound']) <= -0.1:
neg_word_list.append(word)
else:
neu_word_list.append(word)
print('Positive:',pos_word_list)
print('Neutral:',neu_word_list)
print('Negative:',neg_word_list)
score = sid.polarity_scores(sentence)
print('\nScores:',score)
这是我看到的代码 here。我希望它打印为
Positive: ['happy',1.3]
Neutral: ['paper','too','much',0]
Negative: ['missed',-1.2,'stupid',-1.9]
Scores: {'neg': 0.491,'neu': 0.334,'pos': 0.175,'compound': -0.5848}
因此显示单词“happy”在句子中的效价得分为 1.3。