寫在前面
網(wǎng)上已經(jīng)有一篇筆記很好的記錄了這篇論文《Aspect Level Sentiment Classification with Deep Memory Network》,見:西土城搬磚日常
筆者重新記錄的目的是,把自己看的過程中的想法記錄下來,力求行文更加清晰。
概述
讀了論文《Aspect Level Sentiment Classification with Deep Memory Network》
這篇論文的知識點涵蓋了:
- 記憶網(wǎng)絡(Memory Network)
- 多層Attention 機制
應用場景跟上一篇分析的內(nèi)容一樣,都是多層次語義情感分析的。
大概框架
整體架構(gòu)思路就是計算得到context的importance和文本表示,怎么計算呢?就是利用多層計算層進行計算,每個計算層又由MN和attention組合在一起。attention機制又分成了傳統(tǒng)的content attention,和新提出來的location attention...
優(yōu)點
- 和目前最好的features+SVM對比,達到了state-of-art的水平
- 和序列模型LSTM和attention+LSTM相比,表現(xiàn)要更好
- 相同條件下,運行速度要比LSTM快15倍
memory network
memory network是Jason Weston在14年提出來的想法,Sainbayar Sukhbaatar在15年提出了讓memory network進行end to end的訓練方法,并在QA上取得了較好的效果。
關于memory network的相關內(nèi)容可參考下面兩篇論文:
- [Weston et al.2014] MEMORY NETWORKS
- [Sukhbaatar et al.2015] End-To-End Memory Networks
大致思想:
a memory network consists of a memory m and four components I, G, O and R,
where m is an array of objects such as an array of vectors.
Among these four components, I converts input to internal feature representation,
G updates old memories with new input,
O generates an output representation given a new input and the current memory state,
R outputs a response based on the output representation.
MN的例子如下:

這里想要提到的是,O組件是可以包含多層計算層的。
計算層稱為hop.主要原因是多層次的hop可以提取更多的抽象語義信息。
框架設計
整體框圖如下:

word embedding:
這些word vectors包括context vectors和aspect vectors。
- aspect vectors:
如果aspect word是單個詞,aspect vectors就是aspect word的word embedding;如果aspect word是多個詞組成的,aspect vectors就是幾個詞的embedding的平均值。
- context word vectors:

即sentence中除了aspect word之外的所有詞的word embedding堆疊(拼成一個矩陣d*n-1維)到一起,這就是模型中的memory。(n為句子的長度)
compute layer
- 模型包括多個computational layers,每個computational layer包括一個attention layer和一個linear layer。
- 第一個computational layer,attention layer的輸入是aspect vector,輸出memory中的比較重要的部分,linear layer的輸入是aspect vector。第一個computational layer的attention layer和linear layer的輸出結(jié)果求和作為下一個computational layer的輸入;
- 其它computational layer執(zhí)行同樣的操作,上一層的輸出作為輸入,通過attention機制獲取memory中較重要的信息,與線性層得到的結(jié)果求和作為下一層的輸入。
- 最后一層的輸出作為結(jié)合aspect信息的sentence representation,作為aspect-level情感分類的特征,送到softmax。
tips: 參數(shù)共享
It is helpful to note that the parameters of attention and linear layers are shared in different hops. Therefore,the model with one layer and the model with nine layers have the same number of parameters.
Attention
這里分為兩類attention:
- content attention
- location attention
這里content attention跟以前的attention差不多,這里就直接列公式了:
每一層的輸出向量為:

這里mi為記憶網(wǎng)絡里面的第i個向量,并且,

打分函數(shù),計算aspect與記憶網(wǎng)絡里每個mi的分數(shù):

再由打分函數(shù)得到的分值,得到權(quán)重(即attention值):

這里我們就想問了,這里記憶函數(shù)的mi是如何得來的呢?
這里就要開始講論文提到的另一個attention了,location attention.
我們從直觀上來看,通常情況下,與aspect word距離較近的context word對于相應aspect的情感傾向的判斷更重要。于是就有了location attention。所謂的location attention其實就是把context word的位置信息加入到memory中。
作者一共提到了4種計算mi的方法模型,

ei是context vector, vi是location vector for word wi.
模型3,4中作為模型的一個參數(shù),隨機初始化,通過梯度下降學習得到。只是模型4中加了一層sigmoid函數(shù)。
訓練過程
- softmax
- 交叉熵loss
- BP
- 隨機梯度下降來更新參數(shù)
實驗結(jié)果
數(shù)據(jù):

結(jié)果:

時間:

location attention對比:

根據(jù)上圖可以看出:
- 隨著computational layers的增多,分類準確率有提升;
- 在computational layer數(shù)大于5的時候,四個模型準確率相差不大;
- model 2計算量最小,準確率也不差。
計算單元層數(shù)和location信息的作用分析

從Table 4和Table 5對比可以看出:
- 增加computational layer可以提取更abstractive的evidence(針對某個特定的aspect),更好的區(qū)分不同context word對特定aspect的貢獻;
- 引入location信息明可以更好地捕獲針對特定aspect更重要的context信息。
寫在最后
論文創(chuàng)新點在于將QA中常用的記憶網(wǎng)絡結(jié)合attention,多層computing layers,應用于多層次語義情感分析。
下一步工作,研究記憶網(wǎng)絡和這篇論文的復現(xiàn)代碼。