Vader 情绪分析:如何对单个单词进行评分?

exp*_*r_x 1 nlp nltk python-3.x 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
Run Code Online (Sandbox Code Playgroud)

在这种情况下,O/P 应该是负数,但它给出了一个更接近中性到正数的复合分数,这是没有意义的。

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

我只是想知道这些单个词是如何根据 pos neg neu 和复合词给出情感分数的?是否有任何算法/过程来评价它们?

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

Lau*_*ber 7

使用以下代码(不是我的),您可以确定维达词典将哪些词归类为正面、负面和中性:

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)
Run Code Online (Sandbox Code Playgroud)

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

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']
Run Code Online (Sandbox Code Playgroud)

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

至于 Vader 工作原理的概述,它依赖于总结整个句子中各种单词的情感强度,从而产生总分。Vader 内置了一些微妙的细微差别,以超越传统的词袋方法之外的分类器,包括添加否定词和常用术语。在词情绪分数方面,您会在此处找到详细说明。