维达(Vader)情绪分析:各个单词的评分如何?

时间:2018-06-19 18:32:16

标签: python-3.x nlp nltk sentiment-analysis vader

因此,我正在使用Vader Sentiment Analyzer分析某些客户的反馈。在评估输出时,我看到情绪分析器给了我好坏参半的结果。

For eg: "Again, human interaction needs to have resolutions. Your reps 
        cannot BLAME the system and shrug off being able to help. Let 
        alone blame the system and not know WHY the system makes 
        indiscriminate decisions."

Output: compound: 0.2212 neg: 0.111 neu: 0.756, pos: 0.133

在这种情况下,O / P应该是负数,但相反,它给出的综合得分更接近中性到正值,这是没有道理的。

我在AppData \ Roaming \ nltk_data \ sentiment \ vader_lexicon.txt中看到了该文件,其中包含大多数英语单词的情绪得分。

我只是想知道如何根据正负和复合向这些单词赋予情感分数?是否有任何算法/过程对其进行评分?

最后,我正在考虑构建自己的用于情感分析的词典以获得更好的结果,但是为此,我需要知道如何为每个单词分配情感得分?

1 个答案:

答案 0 :(得分:3)

使用以下代码(而不是我的代码),您可以确定vader词典将哪些单词分类为肯定,否定和中性:

import nltk
from nltk.tokenize import word_tokenize, RegexpTokenizer
from nltk.sentiment.vader import SentimentIntensityAnalyzer
sentence = 'Again, human interaction needs to have resolutions. Your reps cannot BLAME the system and shrug off being able to help. Let alone blame the system and not know WHY the system makes indiscriminate decisions.'
tokenized_sentence = nltk.word_tokenize(sentence)

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)
    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)

运行此代码会产生以下结果:

Positive: ['help']
Neutral: ['Again', ',', 'human', 'interaction', 'needs', 'to', 'have', 'resolutions', '.', 'Your', 'reps', 'can', 'not', 'the', 'system', 'and', 'shrug', 'off', 'being', 'able', 'to', '.', 'Let', 'the', 'system', 'and', 'not', 'know', 'WHY', 'the', 'system', 'makes', 'indiscriminate', 'decisions', '.']
Negative: ['BLAME', 'alone', 'blame']

然后我们可以转到vader .txt文件,找到您的单词指定的分数。责备得分为-1.4,仅得分为-1.0,帮助得分为+1.7。这应该产生一个否定的分数,但是,在使用“责备”一词之前,您拥有“不能”一词,该词否定了该词的否定元素,而是将其转换为正数。尽管Vader很聪明,但是它可以识别否定词,但是不能将其与句子的整体结构联系起来(大多数替代方法都是这样)。

关于Vader工作原理的概述,它依赖于总结整个句子中各个单词的情感强度,从而得出总分。 Vader内置了细微的细微差别,可以超越分类器,超越传统的词袋方法,包括添加否定词和常用术语。在单词情感评分方面,您会找到详细的说明here