VADER(Valence Aware Dictionary and sEntiment Reasoner)是专门为社交媒体进行情感分析的工具,目前仅支持英文文本,大邓在这里推荐给大家使用。大家可以结合大邓的教程
,自己采集数据自己进行分析。
VADER情感信息会考虑:
否定表达(如,"not good")
能表达情感信息和强度的标点符号 (如, "Good!!!")
大小写等形式带来的强调,(如,"FUNNY.")
情感强度(强度增强,如"very" ;强度减弱如, "kind of")
表达情感信息的俚语 (如, 'sux')
能修饰俚语情感强度的词语 ('uber'、'friggin'、'kinda')
表情符号 :) and :D
utf-8编码中的emoj情感表情 ( ? and ? and ?)
首字母缩略语(如,'lol') ...
VADER目前只支持英文文本,如果有符合VADER形式的中文词典,也能使用VADER对中文进行分析。
安装VADER
pip3 install vaderSentiment
使用方法
VADER会对文本分析,得到的结果是一个字典信息,包含
pos,文本中正面信息得分
neg,文本中负面信息得分
neu,文本中中性信息得分
compound,文本综合情感得分
文本情感分类
依据compound综合得分对文本进行分类的标准
正面:compound score >= 0.05
中性: -0.05 < compound score < 0.05
负面: compound score <= -0.05
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()
test = "VADER is smart, handsome, and funny."
analyzer.polarity_scores(test)
运行
{'neg': 0.0, 'neu': 0.254, 'pos': 0.746, 'compound': 0.8316}
这里我们只使用 compound 得分,用更多的例子让大家看到感叹号、俚语、emoji、强调等不同方式对得分的影响。为了方便,我们想将结果以dataframe方式展示
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
import pandas as pd
analyzer = SentimentIntensityAnalyzer()
sentences = ["VADER is smart, handsome, and funny.",
"VADER is smart, handsome, and funny!", #带感叹号
"VADER is very smart, handsome, and funny.",
"VADER is VERY SMART, handsome,