【情感分析】基于Aspect的情感分析模型总结(PART IV)

时间:2022-07-23
本文章向大家介绍【情感分析】基于Aspect的情感分析模型总结(PART IV),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

情感分析连载系列第四期,虽迟但到!

Aspect Level Sentiment Classification with Deep Memory Network(EMNLP2016)[1]

文章借鉴了来自QA领域的记忆网络解决ABSA问题。Memory Network提出的目的之一就是为了解决RNN、LSTM等网络的记忆能力较差的问题。它维护了一个外部的记忆单元用于存储之前的信息,而不是通过cell内部的hidden state。如果有同学不太熟悉Memory Network,后续会整理一篇更为详细的解读,稍安勿躁。

整体解决方案如下图所示

1.1 Embedding

输入是一个原始句子,需要将其映射到向量空间后输入到模型中。常规操作,将context word和aspect word分别用向量表示

1.2 Attention

包括了两部分:content attention和location attention

content attention

就是传统的Key Value Query的形式

g_{i}=tanh left(W_{a t t}left[m_{i} ; v_{a s p e c t}right]+b_{a t t}right)
alpha_{i}=frac{exp left(g_{i}right)}{sum_{j=1}^{k} exp left(g_{j}right)}
v e c=sum_{i=1}^{k} alpha_{i} m_{i}
location attention

我们从直观上来看,通常情况下,与aspect word距离较近的context word对于相应aspect的情感倾向的判断更重要。于是就有了location attention。所谓的location attention其实就是把context word的位置信息加入到memory中。文中定义了四种方式来encode位置信息:

  • 「方式一:」
v_{i}^{k}=left(1-l_{i} / nright)-(k / d)left(1-2 times l_{i} / nright)
m_{i}=e_{i} odot v_{i}
  • 「方式二:」
v_{i}=1-l_{i} / n
m_{i}=e_{i} odot v_{i}
  • 「方式三:」
v_{i}

作为模型的一个参数,随机初始化,通过梯度下降学习得到。

m_{i}=e_{i}+v_{i}
  • 「方式四:」 与方式三类似,加了一层sigmoid。

1.3 Loss

operatorname{loss}=-sum_{(s, a) in T} sum_{c in C} P_{c}^{g}(s, a) cdot log left(P_{c}(s, a)right)
CODE HERE[3]

Recurrent Attention Network on Memory for Aspect Sentiment Analysis(Tencent AI Lab/EMNLP 2017)[4]

论文采用多层注意力机制结合记忆网络去捕获句子中target word 与context word之间的联系。整体框架如下,主要分为

  • input module,
  • memory module,
  • position-weighted memory module,
  • recurrent attention module,
  • output module.

2.1 BLSTM for Memory Building

在上一篇的论文中的记忆网络只是简单地将word embedding作为memory,并不能准确识别例如Except Patrick, all other actors don’t play well这类的实体情感。于是在本文中引入双向LSTM来捕获这之间的深层次关联。如果有L层BLSTM叠加,最终得到的memory vector表示为

M^{*}=left{m_{1}^{*}, ldots, m_{t}^{*}, ldots, m_{T}^{*}right}

2.2 Position-Weighted Memory

当然,作者认为target word在输入句子中的位置信息也非常重要,更靠近target word的context word应该具有更高的重要性。

w_{t}=1-frac{|t-tau|}{t_{max }}
u_{t}=frac{t-tau}{t_{max }}
M=left{m_{1}, dots, m_{t}, ldots, m_{T}right}
m_{t}=left(w_{t}right.bullet m_{t}^{*}, u_{t} )

2.3 Recurrent Attention on Memory

这一部分的目的就是利用之前计算好的memory来表示出情感,然后用于分类。和上一篇论文一样,使用GRU和堆叠的attention。

Aspect Based Sentiment Analysis with Gated Convolutional Networks(ACL2018)[5]

针对ABSA任务,之前研究效果较好的模型都是采用了LSTM+attention机制,这类模型过于复杂且参数较多训练起来比较费时。

❝LSTM processes one token in a step. Attention layer involves exponential operation and normalization of all alignment scores of all the words in the sentence. Moreover, some models needs the positional information between words and targets to produce weighted LSTM, which can be unreliable in noisy review text.

因此作者提出一种基于门控机制的可并行训练的CNN模型。

  • 将原始输入embedding后送入包含两个卷积操作的卷积层,第一个卷积对句子提取sentiment feature,第二个卷积额外加上了aspect embedding提取aspect feature,而且两者使用的非线性激活函数也不一样
s_{i}=tanh left(mathbf{X}_{i : :+k} * mathbf{W}_{s}+b_{s}right)
a_{i}=operatorname{relu}left(mathbf{X}_{i : i+k} * mathbf{W}_{a}+mathbf{V}_{a} boldsymbol{v}_{a}+b_{a}right)
  • 将上述得到的两个输出按位相乘,
c_{i}=s_{i} times a_{i}

以上是针对Aspect-Category Sentiment Analysis(ACSA),如果是Aspect-Term Sentiment Analysis(ATSA)问题呢,我们没有给定的aspect词,每个句子需要预测的target term都不同,这时候可以用另外一个CNN来提取target term的representation

CODE HERE[6]

本文参考资料

[1]

Aspect Level Sentiment Classification with Deep Memory Network(Tang/EMNLP2016): https://arxiv.org/abs/1605.08900

[2]

Memory Networks论文串烧: https://blog.csdn.net/Kaiyuan_sjtu/article/details/90489213

[3]

CODE HERE: https://github.com/ganeshjawahar/mem_absa

[4]

Recurrent Attention Network on Memory for Aspect Sentiment Analysis(Tencent AI Lab/EMNLP 2017): https://www.aclweb.org/anthology/D17-1047

[5]

Aspect Based Sentiment Analysis with Gated Convolutional Networks(Xue/ACL2018): https://www.aclweb.org/anthology/P18-1234

[6]

CODE HERE: https://github.com/wxue004cs/GCAE

- END -