斯坦福大学怎样讲“情感分析”

jopen 9年前
一、自然语言处理概览——什么是自然语言处理(NLP)
1)相关技术与应用
自动问答(Question Answering,QA):它是一套可以理解复杂问题,并以充分的准确度、可信度和速度给出答案的计算系统,以IBM‘s Waston为代表;
信息抽取(Information Extraction,IE):其目的是将非结构化或半结构化的自然语言描述文本转化结构化的数据,如自动根据邮件内容生成Calendar;
情感分析(Sentiment Analysis,SA):又称倾向性分析和意见挖掘,它是对带有情感色彩的主观性文本进行分析、处理、归纳和推理的过程,如从大量网页文本中分析用户对“数码相机”的“变焦、价格、大小、重量、闪光、易用性”等属性的情感倾向;
机器翻译(Machine Translation,MT):将文本从一种语言转成另一种语言,如中英机器翻译。
… …
2)发展现状
基本解决:词性标注、命名实体识别、Spam识别
取得长足进展:情感分析、共指消解、词义消歧、句法分析、机器翻译、信息抽取
挑战:自动问答、复述、文摘、会话机器人
斯坦福大学怎样讲“情感分析”
3)NLP主要难点——歧义问题
词法分析歧义
分词,如“严守一把手机关了”,可能的分词结果“严守一/ 把/ 手机/ 关/ 了” 和“严守/ 一把手/ 机关/ 了”
词性标注,如“计划”在不同上下文中有不同的词性:“我/ 计划/v 考/ 研/”和“我/ 完成/ 了/ 计划/n”
语法分析歧义
“那只狼咬死了猎人的狗”
”咬死了猎人的狗失踪了”
语义分析歧义
计算机会像你的母亲那样很好的理解你(的语言)
计算机理解你喜欢你的母亲
计算机会像很好的理解你的母亲那样理解你
机器翻译:句子“At last, a computer that understands you like your mother”可以有多种含义,如下:
NLP应用中的歧义
音字转换:拼音串“ji qi fan yi ji qi ying yong ji qi le ren men ji qi nong hou de xing qu”中的“ji qi”如何转换成正确的词条
4)为什么自然语言理解如此困难?
用户生成内容中存在大量口语化、成语、方言等非标准的语言描述
分词问题
新词不断产生
基本常识与上下文知识
各式各样的实体词
… …
为了解决以上难题,我们需要掌握较多的语言学知识,构建知识库资源,并找到一种融合各种知识、资源的方法,目前使用较多是概率模型 (probabilistic model)或称为统计模型(statistical model),或者称为“经验主义模型”,其建模过程基于大规模真实语料库,从中各级语言单位上的统计信息,并且,依据较低级语言单位上的统计信息,运行 相关的统计、推理等技术计算较高级语言单位上的统计信息。与其相对的“理想主义模型”,即基于Chomsky形式语言的确定性语言模型,它建立在人脑中先 天存在语法规则这一假设基础上,认为语言是人脑语言能力推导出来的,建立语言模型就是通过建立人工编辑的语言规则集来模拟这种先天的语言能力。
本课程主要侧重于基于统计的NLP技术,如Viterbi、贝叶斯和最大熵分类器、N-gram语言模型等等。
二、情感分析(Sentiment Analysis)
1)What is Sentiment Analysis?
情感分析(Sentiment analysis),又称倾向性分析,意见抽取(Opinion extraction),意见挖掘(Opinion mining),情感挖掘(Sentiment mining),主观分析(Subjectivity analysis),它是对带有情感色彩的主观性文本进行分析、处理、归纳和推理的过程,如从评论文本中分析用户对“数码相机”的“变焦、价格、大小、重 量、闪光、易用性”等属性的情感倾向。
更多例子如下:
l 从电影评论中识别用户对电影的褒贬评价:
斯坦福大学怎样讲“情感分析”
l Google Product Search识别用户对产品各种属性的评价,并从评论中选择代表性评论展示给用户:
斯坦福大学怎样讲“情感分析”
l Bing Shopping识别用户对产品各种属性的评价:
斯坦福大学怎样讲“情感分析”
l 推ter sentiment versus Gallup Poll of Consumer Confidence:挖掘推ter(中文:微博)中的用户情感发现,其与传统的调查、投票等方法结果有高度的一致性(以消费者信心和政治选举为 例,corelation达80%),详细见论文:Brendan O’Connor, Ramnath Balasubramanyan, Bryan R. Routledge, and Noah A. Smith. 2010. From Tweets to Polls: Linking Text Sentiment to Public Opinion Time Series. In ICWSM-2010。(注:下图中2008年到2009年初,网民情绪低谷是金融危机导致,从2009年5月份开始慢慢恢复)
斯坦福大学怎样讲“情感分析”
l 推ter sentiment: 通过推ter用户情感预测股票走势,2012年5月,世界首家基于社交媒体的对冲基金 Derwent Capital Markets 在屡次跳票后终于上线。它会即时关注推ter 中的公众情绪指导投资。正如基金创始人保罗•郝汀(Paul Hawtin)表示:“长期以来,投资者已经广泛地认可金融市场由恐惧和贪婪驱使,但我们从未拥有一种技术或数据来量化人们的情感。”一直为金融市场非理 性举动所困惑的投资者,终于有了一扇可以了解心灵世界的窗户——那便是 推ter 每天浩如烟海的推文,在一份八月份的报道中显示,利用 推ter 的对冲基金 Derwent Capital Markets 在首月的交易中已经盈利,它以1.85%的收益率,让平均数只有0.76%的其他对冲基金相形见绌。类似的工作还有预测电影票房、选举结果等,均是将公众 情绪与社会事件对比,发现一致性,并用于预测,如将“冷静CLAM”情绪指数后移3天后和道琼斯工业平均指数DIJA惊人一致。详细见论文: Johan Bollen, Huina Mao, Xiaojun Zeng. 2011. 推ter mood predicts the stock market, Journal of Computational Science 2:1, 1-8.(注:DIJA,全称Dow Jones Industrial Average)
  斯坦福大学怎样讲“情感分析”
斯坦福大学怎样讲“情感分析”
l Target Sentiment on 推ter(推ter Sentiment App):对推ter中包含给定query的tweets进行情感分类。对于公司了解用户对公司、产品的喜好,用于指导改善产品和服务,公司还可以 据此发现竞争对手的优劣势,用户也可以根据网友甚至亲友评价决定是否购买特定产品。详细见论文:Alec Go, Richa Bhayani, Lei Huang. 2009. 推ter Sentiment Classification using Distant Supervision.
斯坦福大学怎样讲“情感分析” 斯坦福大学怎样讲“情感分析”
情感分析的意义何在?下面以实际应用为例进行直观的阐述:
• Movie: is this review positive or negative?
• Products: what do people think about the new iPhone?
• Public sentiment: how is consumer confidence? Is despair increasing?
• Politics: what do people think about this candidate or issue?
• Prediction: predict election outcomes or market trends from sentiment
情感分析主要目的就是识别用户对事物或人的看法、态度(attitudes:enduring, affectively colored beliefs, dispositions towards objects or persons),参与主体主要包括:
Holder (source) of attitude:观点持有者
Target (aspect) of attitude:评价对象
Type of attitude:评价观点
From a set of types:Like, love, hate, value, desire, etc.
Or (more commonly) simple weighted polarity: positive, negative, neutral,together with strength
Text containing the attitude:评价文本,一般是句子或整篇文档
更细更深入的还包括评价属性,情感词/极性词,评价搭配等、
通常,我们面临的情感分析任务包括如下几类:
Simplest task: Is the attitude of this text positive or negative?
More complex: Rank the attitude of this text from 1 to 5
Advanced: Detect the target, source, or complex attitude types
后续章节将以Simplest task为例进行介绍。
2)A Baseline Algorithm
本小节对影评进行情感分析为例,向大家展示一个简单、实用的情感分析系统。我们面临的任务是“Polarity detection: Is an IMDB movie review positive or negative?”,数据集为“Polrity Data 2.0: http://www.cs.cornell.edu/people/pabo/movie-review-data”.作者将情感分析当作分类任务,拆 分成如下子任务:
Tokenization:正文提取,过滤时间、电话号码等,保留大写字母开头的字符串,保留表情符号,切词;
Feature Extraction:直观上,我们会认为形容词直接决定文本的情感,而Pang和Lee的实验表明,采用所有词(unigram)作为特征,可以达到更好的情感分类效果。
其中,需要对否定句进行特别的处理,如句子”I didn’t like this movie”vs “I really like this movie”,unigram只差一个词,但是有着截然不同的含义。为了有效处理这种情况,Das and Chen (2001)提出了“Add NOT_ to every word between negation and following punctuation”,根据此规则可以将句子“didn’t like this movie , but I”转换为“didn’t NOT_like NOT_this NOT_movie, but I”。
另外,在抽取特征时,直观的感觉“Word occurrence may matter more than word frequency”,这是因为最相关的情感词在一些文本片段中仅仅出现一次,词频模型起得作用有限,甚至是负作用,则使用多重伯努利模型事件空间代替多 项式事件空间,实验也的确证明了这一点。所以,论文最终选择二值特征,即词的出现与否,代替传统的频率特征。log(freq(w))也是一种值得尝试的 降低频率干扰的方法。
Classification using different classifiers:如Naïve Bayes、MaxEnt、SVM,以朴素贝叶斯分类器为例,训练过程如下:
斯坦福大学怎样讲“情感分析”
预测过程如下:
斯坦福大学怎样讲“情感分析”
实验表明,MaxEnt和SVM相比Naïve Bayes可以得到更好的效果。
最后,通过case review可以总结下,影评情感分类的难点是什么?
语言表达的含蓄微妙:“If you are reading this because it is your darling fragrance, please wear it at home exclusively, and tape the windows shut.”,“ She runs the gamut of emotions from A to B”。
挫败感表达方式:先描述开始的期待(不吝赞美之词),后表达最后失望感受,如“This film should be brilliant. It sounds like a great plot, the actors are first grade, and the supporting cast is good as well, and Stallone is attempting to deliver a good performance. However, it can’t hold up.”,“Well as usual Keanu Reeves is nothing special, but surprisingly, the very talented Laurence Fishbourne is not so good either, I was surprised.”。
3)Sentiment Lexicons
情感分析模型非常依赖于情感词典抽取特征或规则,以下罗列了较为流行且成熟的开放情感词典资源:
GI(The General Inquirer):该词典给出了每个词条非常全面的信息,如词性,反义词,褒贬,等,组织结构如下:
斯坦福大学怎样讲“情感分析”
详细见论文:Philip J. Stone, Dexter C Dunphy, Marshall S. Smith, Daniel M. Ogilvie. 1966.The General Inquirer: A Computer Approach to Content Analysis. MIT Press
LIWC (Linguistic Inquiry and Word Count):该词典通过大量正则表达式描述不同类别的情感词规律,其类别体系与GI(The General Inquirer)基本一致,组织结构如下:
斯坦福大学怎样讲“情感分析”
详细见论文:Pennebaker, J.W., Booth, R.J., & Francis, M.E. (2007). Linguistic Inquiry and Word Count: LIWC 2007. Austin, TX
MPQA Subjectivity Cues Lexicon:其中包含Positive words: 2718,Negative words: 4912,组织结构如下图所示:
斯坦福大学怎样讲“情感分析”
详细见论文:Theresa Wilson, Janyce Wiebe, and Paul Hoffmann (2005). Recognizing Contextual Polarity in Phrase-Level Sentiment Analysis. Proc. of HLT-EMNLP-2005.
Riloff and Wiebe (2003). Learning extraction patterns for subjective expressions. EMNLP-2003.
Bing Liu Opinion Lexicon:其中包含Positive words: 2006,Negative words: 4783,需要特别说明的是,词典不但包含正常的用词,还包含了拼写错误、语法变形,俚语以及社交媒体标记等,详细见论文:Minqing Hu and Bing Liu. Mining and Summarizing Customer Reviews. ACM SIGKDD-2004.
SentiWordNet:其通过对WordNet中的词条进行情感分类,并标注出每个词条属于positive和negative类别的权重大小,组织结构如下:
斯坦福大学怎样讲“情感分析”
详细见论文:Stefano Baccianella, Andrea Esuli, and Fabrizio Sebastiani. 2010SENTIWORDNET 3.0: An Enhanced Lexical Resource for Sentiment Analysis and Opinion Mining. LREC-2010
以上给出了一系列可用的情感词典资源,但是,如何选择一个合适的为我所用呢?这里,通过对比同一词条在不同词典之间的分类,衡量词典资源的不一致程度,如下:
斯坦福大学怎样讲“情感分析”
对于在不同词典中表现不一致的词条,我们至少可以做两件事情。第一,review这些词条,通过少量人工加以纠正;第二,可以得到一些存在褒贬歧义的词条。
给定一个词,如何确定其以多大概率出现在某种情感类别文本中呢?以IMDB下不同打分下影评为例,最简单的方法就是计算每个分数(星的个数)对应的文本中词条出现的频率,如下图所示为Count(“bad”)分布情况:
斯坦福大学怎样讲“情感分析”
斯坦福大学怎样讲“情感分析”
如下图所示,列出了部分词条在不同类别下的Scaled likelihood,据此可以判断每个词条的倾向性。
斯坦福大学怎样讲“情感分析”
另外,我们通常会有这么一个疑问:否定词(如not, n’t, no, never)是否更容易出现在negative情感文本中?Potts, Christopher(2011)等通过实验给出了答案:More negation in negative sentiment,如下图所示:
斯坦福大学怎样讲“情感分析”
4)Learning Sentiment Lexicons
我们在庆幸和赞扬众多公开情感词典为我所用的同时,我们不免还想了解构建情感词典的方法,正所谓知其然知其所以然。一方面在面临新的情感分析问 题,解决新的情感分析任务时,难免会需要结合实际需求构建或完善情感词典,另一方面,可以将成熟的词典构建方法应用于其他领域,知识无边界,许多方法都是 相通的。
常见的情感词典构建方法是基于半指导的bootstrapping学习方法,主要包括两步:
Use a small amount of information(Seed)
A few labeled examples
A few hand-built patterns
To bootstrap a lexicon
接下来,通过相关的几篇论文,详细阐述下构建情感词典的方法。具体如下:
1. Hatzivassiloglou & McKeown:论文见Vasileios Hatzivassiloglou and Kathleen R. McKeown. 1997. Predicting the Semantic Orientation of Adjectives. ACL, 174–181,基于这样的一种语言现象:“Adjectives conjoined by ‘and’’ have same polarity;Adjectives conjoined by ‘but ‘ do not”,如下示例:
Fair and legitimate, corrupt and brutal
*fair and brutal, *corrupt and legitimate
fair but brutal
Hatzivassiloglou & McKeown(1997)提出了基于bootstrapping的学习方法,主要包括四步:
Step 1:Label seed set of 1336 adjectives (all >20 in 21 million word WSJ corpus)
初始种子集包括657个 positive words(如adequate central clever famous intelligent remarkable reputed sensitive slender thriving…)和679个 negative words(如contagious drunken ignorant lanky listless primitive strident troublesome unresolved unsuspecting…)
Step 2:Expand seed set to conjoined adjectives,如下图所示:
斯坦福大学怎样讲“情感分析”
Step 3:Supervised classifier assigns “polarity similarity” to each word pair, resulting in graph,如下图所示:
斯坦福大学怎样讲“情感分析”
Step 4:Clustering for partitioning the graph into two
斯坦福大学怎样讲“情感分析”
最终,输出新的情感词典,如下(加粗词条为自动挖掘出的词条):
Positive: bold decisive disturbing generous good honest important large mature patient peaceful positive proud sound stimulating straightforwardstrange talented vigorous witty…
Negative: ambiguous cautious cynical evasive harmful hypocritical inefficient insecure irrational irresponsible minor outspoken pleasant reckless risky selfish tedious unsupported vulnerable wasteful…
2. Turney Algorithm:论文见Turney (2002): Thumbs Up or Thumbs Down? Semantic Orientation Applied to Unsupervised Classification of Reviews,具体步骤如下:
Step 1:Extract a phrasal lexicon from reviews,通过规则抽取的phrasal如下图所示:
斯坦福大学怎样讲“情感分析”
Step 2:Learn polarity of each phrase,那么,如何评价phrase的polarity呢?直观上,有这样的结论:“Positive phrases co-occur more with ‘excellent’,Negative phrases co-occur more with ’poor’”,这时,将问题转换成如何衡量词条之间的共现关系?于是,学者们引入了点互信息(Pointwise mutual information,PMI),它经常被用于度量两个具体事件的相关程度,公式为:
斯坦福大学怎样讲“情感分析”
Turney Algorithm在410 reviews(from Epinions)的数据集上,其中170 (41%) negative,240 (59%) positive,取得了74%的准确率(baseline为59%,均标注为positive)。
Step 3:Rate a review by the average polarity of its phrases
3. Using WordNet to learn polarity:论文见S.M. Kim and E. Hovy. 2004.Determining the sentiment of opinions. COLING 2004,M. Hu and B. Liu. Mining and summarizing customer reviews. In Proceedings of KDD, 2004.该方法步骤如下:
Create positive (“good”) and negative seed-words (“terrible”)
Find Synonyms and Antonyms
Positive Set: Add synonyms of positive words (“well”) and antonyms of negative words
Negative Set: Add synonyms of negative words (“awful”) and antonyms of positive words (”evil”)
Repeat, following chains of synonyms
Filter
以上几个方法都有较好的领域适应性和鲁棒性,基本思想可以概括为“Use seeds and semi-supervised learning to induce lexicons”,即:
Start with a seed set of words (‘good’, ‘poor’)
Find other words that have similar polarity:
Using “and” and “but”
Using words that occur nearby in the same document
Using WordNet synonyms and antonyms
Use seeds and semi-supervised learning to induce lexicons
5)Other Sentiment Tasks
上面介绍了文档级或句子级情感分析,但是,实际中,一篇文档(评论)中往往会提及不同的方面/属性/对象(以下统称属性),且可能对不同的属性 持有不同的倾向性,如“The food wasgreat but the service was awful”。一般通过Frequent phrases + rules的方法抽取评价属性,如下:
Find all highly frequent phrases across reviews (“fish tacos”)
Filter by rules like “occurs right after sentiment word”:“…great fish tacos” means fish tacos a likely aspect
通常,我们还会面临一种问题:评价属性缺失,准确的讲,评价属性不在句子中。这是很常见的现象,此时就需要结合上下文环境,如来自某电影的评论缺失的评价属性基本上就是电影名或演员,可以基于已知评价属性的句子训练分类器,然后对评价属性缺失的句子进行属性预测。
Blair-Goldensohn et al.提出了一套通用的aspect-based summarization models,如下图所示:
斯坦福大学怎样讲“情感分析”
详细见论文:S. Blair-Goldensohn, K. Hannan, R. McDonald, T. Neylon, G. Reis, and J. Reynar. 2008. Building a Sentiment Summarizer for Local Service Reviews. WWW Workshop
另外,其他的一些情感分析的相关任务有:
Emotion: 个人情绪
Detecting annoyed callers to dialogue system
Detecting confused/frustrated versus confident students
Mood: 个人情绪
Finding traumatized or depressed writers
Interpersonal stances: 人际关系中的谈话方式
Detection of flirtation or friendliness in conversations
Personality traits: 性格
Detection of extroverts
文章出处:大数据文摘