筆記 | Sentiment Analysis

2021-03-02 黑龍江大學自然語言處理實驗室

常用到的語料庫 IMDB Polarity Data 2.0,
目的: polarity detection: is this review positive or negative?
步驟:

Tokenization

Feature Extraction

Classification using different classifiers

1.1Sentiment Tokenization

除了正常 tokenization 要注意的問題如處理 HTML/XML markup 外,情感分析還可能需要處理

有用的 Tokenizer 代碼

關於特徵提取,兩個重要的問題,一是怎麼來處理否定詞(negation),二是選什麼詞作為特徵

I didn't like this movie

I really like this movie

如果對否定詞不做處理,那麼上面兩條評論的結果都是 positive,這顯然不對。一種有效的處理否定詞的方案是對否定詞後、下一個標點符號前的每個詞都加上 NOT_ 的前綴來作為標識,如下

didn't like this movie, but I

=>

didn't NOT_like NOT_this NOT_movie but I


具體見: 

Das, Sanjiv and Mike Chen. 2001. Yahoo! for Amazon: Extracting market sentiment from stock message boards. In Proceedings of the Asia Pacific Finance Association Annual Conference (APFA).

Bo Pang, Lillian Lee, and Shivakumar Vaithyanathan. 2002. Thumbs up? Sentiment Classification using Machine Learning Techniques. EMNLP-2002, 79—86.

一般兩種方案,一是僅僅使用形容詞(adjectives),而是使用所有的單詞(all words),通常而言,使用所有的詞的效果會更好些,因為動詞(verbs)、名詞(nouns)會提供更多有用的信息。

作為 Baseline model,這裡會使用 Naive Bayes,沒啥懸念,計算如下

Prior: how likely we see a positive movie review

Likelihood Function: for every review, how likely every word is expressed by a positive movie review

採用 Laplace/Add-one Smoothing


一個變種或者改進版是Binarized(Boolean feature) Multinomial Naive Bayes,它基於這樣一個直覺,對情感分析而言,單詞是否出現(word occurrence)這個特徵比單詞出現了幾次(word frequency)更為重要,舉個例子,出現一次 fantastic 提供了 positive 的信息,而出現 5 次 fantastic 並沒有給我們提供更多信息。boolean multinomial Naive Bayes 就是把所有大於 1 的 word counts 壓縮為 1。

算法如下

也有研究認為取中間值 log(freq(w)) 效果更好一些,相關論文如下:

B. Pang, L. Lee, and S. Vaithyanathan. 2002. Thumbs up? Sen+ment Classification using Machine Learning Techniques. EMNLP-­‐2002, 79—86.

V. Metsis, I. Androutsopoulos, G. Paliouras. 2006. Spam Filtering with Naive Bayes – Which Naive Bayes? CEAS 2006 -­‐ Third Conference on Email and Anti‐Spam.

K.-­‐M. Schneider. 2004. On word frequency informa+on and negative evidence in Naive Bayes text classifica+on. ICANLP, 474-­‐485.

JD Rennie, L Shih, J Teevan. 2003. Tackling the poor assumptions of naive bayes text classifiers. ICML 2003

當然在實踐中,MaxEnt 和 SVM 的效果要比 Naive Bayes 好的多。

1.4Problems

有些句子裡並不包含情感詞(sentiment word),如下面一句是 negative 的態度,然而並不能通過情感詞來得出

「If you are reading this because it is your darling fragrance, please wear it at home exclusively, and tape the windows shut.」

還有一個問題是排序問題(Order effect),儘管前面堆砌了很多情感詞,但最後來個全盤否定,顯然 Naive Bayes 沒法處理這種問題

例如

看一下目前已經有的 Lexicons,

看下各個詞庫的 disagreements between polarity lexicons

那麼怎麼來分析 IMDB 裡每個單詞的 polarity 呢?

How likely is each word to appear in each sentiment class?
likelihood:

Make them comparable between words - Scaled likelihood:

更多見 Potts, Christopher. 2011. On the negativity of negation. SALT 20, 636-­‐659.

Learning Sentiment Lexicons

除了目前已有的 lexicon,我們還可以根據自己的語料庫來訓練自己的 sentiment lexicon。

2.1Semi-supervised learning of lexicons

基於少量的有標註的數據+人工建立的規則,採用 bootstrap 方法來學習 lexicon

Hatzivassiloglou and McKeown intuition for identifying word polarity

論文: Vasileios Hatzivassiloglou and Kathleen R. McKeown. 1997. Predicting the Semantic Orientation of Adjectives. ACL, 174–181

基於這樣的假設:


論文方法:

1. 對 1336 個形容詞形成的種子集合進行標註,657 個 positive,679 個 negative

2. 通過 google 搜索來查詢 conjoined 形容詞,eg. 「was nice and」

3. Supervised classifier 通過 count(AND), count(BUT) 來給每個詞對(word pair)計算 polarity similarity

4. 將 graph 分區

但是這種方法難以處理短語

論文: Turney (2002):Thumbs Up or Thumbs Down? Semantic Orientation Applied to Unsupervised Classification of Reviews

步驟:

1. 從評論中抽取形容詞短語(two-word phrase)

2. 學習短語的 polarity
如何衡量短語的 polarity 呢?

基於下面的假設


        Pointwise mutual information: how much more do events x and y co-occur than if they were independent

同樣通過搜尋引擎(Altavista)查詢得到概率

P(word) = hits(word)/N

3. Rate a review by the average polarity of its phrases

一般來說 baseline 的準確率是 59%, Turney algorithm 可以提高到 74%

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


步驟:

有一小部分 positive/negative seed-words

從 WordNet 中找到 seed-words 的同義詞(synonyms)和反義詞(antonyms)
Positive Set: positive words 的同義詞 + negative words 的反義詞
Negative Set: negative words 的同義詞 + positive words 的反義詞

重複 2 直到達到終止條件

過濾不合適的詞

採用半監督方法來引入 lexicons,好處是:


Intuition:

starts 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

4.1Finding aspects/attributes/target


論文:

M. Hu and B. Liu. 2004. Mining and summarizing customer reviews. In Proceedings of KDD.

S. Blair-­‐Goldensohn, K. Hannan, R. McDonald, T. Neylon, G. Reis, and J. Reynar. 2008. Building a Sen+ment Summarizer for Local Service Reviews. WWW Workshop.

很多時候,一條評論並不能簡單的被歸為 positive/negative,它可能討論了多個維度,既有肯定又有否定,如下面這個句子

The food was great but the service was awful!

這條評論就是對食物(food)持肯定態度(positive),對服務(service)持否定態度(negative),在這種情況下,我們不能簡單的對這條評論進行 positive/negative 的分類,而要對其在 food,service 這兩個維度上的態度進行分類。food,service 這些維度,或者說 attributes/aspects/target 從哪裡來? 有兩種方法,一種是從文本中抽取常用短語+規則來作為 attributes/aspects,另一種是預先定義好 attributes/aspects。

首先找到產品評論裡的高頻短語,然後按規則進行過濾,可用的規則如找緊跟在 sentiment word 後面的短語,」…great fish tacos」 表示 fish tacos 是一個可能的 aspect。

Supervised classification

對一些領域如 restaurants/hotels 來說,aspects 比較規範,所以事實上可以人工給一些產品評論標註 aspect(aspects 如 food, décor, service, value, NONE),然後再給每個句子/短語分類看它屬於哪個 aspect。

具體步驟:

從評論中抽取句子/短語

對句子/短語進行情感分類

得到句子/短語的 aspects

匯總得到 summary

值得注意的是,baseline method 的假設是所有類別出現的概率是相同的。如果類別不平衡(在現實中往往如此),我們不能用 accuracy 來評估,而是需要用 F-scores。而類別不平衡的現象越嚴重,分類器的表現可能就越差。

有兩個辦法來解決這個問題

Resampling in training
就是說如果 pos 有10^6 條數據,neg 有 10^4 的數據,那麼我們都從 10^4 的數據中來劃分訓練數據

Cost-sensitive learning
對較少出現的那個類別的 misclassification 加大懲罰(penalize SVM more for misclassification of the rare thing)

4.2How to deal with 7 stars


論文: Bo Pang and Lillian Lee. 2005. Seeing stars: Exploiting class relationships for sentiment categorization with respect to rating scales. ACL, 115–124

怎樣來處理評分型的評論?

Map to binary
壓縮到 positive/negative。比如說大於 3.5 的作為 negative,其他作為 positive

Use linear or ordinal regression
or specialized models like metric labeling


4.3Summary on Sentiment

通常被建立分類/回歸模型來預測 binary/ordinal 類別
關於特徵提取:

Computational work on other affective states

對其他任務也可以用相似手段

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

E.g., Detection of Friendliness

Friendly speakers use collaborative conversational style

- Laughter

- Less use of negative emotional words

- More sympathy

  That’s too bad I’m sorry to hear that!

- More agreement

I think so too!

- Less hedges

kind of sort of a little …

推薦閱讀

基礎 | TreeLSTM Sentiment Classification

基礎 | 詳解依存樹的來龍去脈及用法

基礎 | 基於注意力機制的seq2seq網絡

原創 | Simple Recurrent Unit For Sentence Classification

原創 | Highway Networks For Sentence Classification

歡迎關注交流

相關焦點

  • 中文情感分析 (Sentiment Analysis) 的難點在哪?現在做得比較好的有哪幾家?
    Chinese Shopping Reviews sentiment analysisAI Challenger 2018:細粒度用戶評論情感分類冠軍思路總結文獻資料文本情感分析綜述(騰訊語義團隊)Deep learning for sentiment analysis: A survey情感分析資源大全Tang D
  • 英語短語:sentiment motivation
    Sentiment Index 情緒指數 ; 情感指數aesthetic sentiment 審美情趣sentiment motivation 情感動機nationalist sentiment 民族主義情緒primordial sentiment 原生情感 ; 原始情感
  • Meta-analysis 第一步那些事兒
    Do nothing in haste; look well to each step; and from the beginning think what might be the end--Edward Whymper 1986常常見到,不少人開始嘗試Meta-analysis
  • SHORT COURSE: ADVANCED SURVIVAL ANALYSIS
    Special statistical methods have been developed to provide valid and efficient analysis of potentially censored event time data.
  • 英語學術寫作筆記之Introduction部分八:提出假設/設計
    英語學術寫作筆記之Introduction 部分一:引言的內容與功能英語學術寫作筆記之Introduction 部分二:確立主題的相關句式
  • 國際期刊是否對Meta-analysis文章更感興趣?
    Meta-analysis如果翻譯成中文有很不同的說法,如元分析、後設分析、整合分析、薈萃分析,按照按照統計學的定義,Meta-analysis是指將多個研究結果整合在一起的統計方法。就用途而言,它是文獻回顧的新方法。
  • 【每日英語】雅思核心詞彙—analysis、transcend
    analysis[əˈnæləsɪs]   n. 分析;分解;驗定The book is an analysis of poverty and its causes. 這本書分析了貧困及其原因。I agree with her analysis of the situation. 我贊成她對形勢的分析。system analysis  系統分析dynamic analysis  動態分析decomposition;dissolution n.
  • 當Meta-analysis遇上SEM!
    首先,你要認識兩種統計方法,一是元分析(Meta-analysis,MA),另一個就是結構方程模型(structural equation modeling, SEM)。這兩種方法是是目前應用在行為科學、醫學及社會科學上其中兩種最先進的統計方法。
  • 熱分析Thermal analysis
    本文來自Chem-Station日文版 熱分析 Thermal analysis Zeolinite翻譯投稿 炸雞 校對 白菜豬肉餡熱分析(Thermal analysis)是研究與熱相關的物質的性質的一種方法。
  • Python For Data Analysis筆記(1)|Python 的數據結構、函數和文件
    所以,歡迎累了就到我公眾號話題「讀書蟲啃數據」裡把我的筆記瞅一瞅,當作入門、回顧、準備面試,都可以!先從O'REILLY系列之《Python for Data Analysis》開始吧。持續更新。在向數據大牛靠近的路上慢慢披荊斬棘。
  • 寫綜述的方法基礎Meta-Analysis
    Meta-analysis正是這樣一種好的綜合方法。定義Meta-analysis:元分析或薈萃分析,其概念為對以往的研究結果進行系統的定量分析。Glass對Meta-analysis提出的定義是:以綜合已有的發現為目的,對單個研究結果的集合的統計學分析方法;Sacks等提出的定義是:對以往的研究結果進行統計學的合併和嚴謹的綜述方法;羅湘等認為Meta-analysis方法是依靠搜集已有或未發表的具有某一可比特性的文獻,應用特定的設計和統計學方法進行分析與綜合評價,使有可能對具有不同設計方法及不同樣本數的研究結果進行綜合比較。
  • WGCNA新手入門筆記(含代碼和數據)
    加權基因共表達網絡分析(WGCNA,Weighted gene co-expression network analysis
  • 昆汀學術英語之內容分析(Content Analysis))
    內容分析(Content analysis)是一種用於分辨已經記錄好的內容的可能存在的模式(pattern)的一種研究方法(Research method)。如果要進行內容分析就需要收集相應的數據,數據來源可以是:1.     書籍,報紙和雜誌(Books, newspapers and magazines)2.
  • 高頓ACCA:CVP analysis 知識點總結+真題講解(上)
    今天幫主邀請Yvonne老師來為大家講解CVP analysis~文丨Yvonne*原創版權所有,未經授權不得抄襲,侵權必究!同學們大家好,今天老師帶大家一起來看看CVP analysis這個部分的考點以及真題應該怎麼做~01推導過程:大多數情況下我們都是不用掌握推導過程的,但是CVP analysis建議大家一定要掌握推導過程,第一是因為簡單,第二是可以應對一些變化的情況。
  • 大浩浩的筆記課堂——CFA考試學習筆記341
    uses six indices in her regression analysis,which is based on monthly observations from the past 36 months.The regression output indicates that Fund A´s selection is 0.28.Detailed results of her analysis
  • IT infrastructure analysis: Enterprise storage」s role in...
    未經允許不得轉載:DOIT » IT infrastructure analysis: Enterprise storage」s role in empowering e-business