《Aspect Level Sentiment Classification with Deep Memory Network》笔记

写在前面

网上已经有一篇笔记很好的记录了这篇论文《Aspect Level Sentiment Classification with Deep Memory Network》,见:西土城搬砖日常

笔者重新记录的目的是,把自己看的过程中的想法记录下来,力求行文更加清晰。

概述

读了论文《Aspect Level Sentiment Classification with Deep Memory Network》

这篇论文的知识点涵盖了:

  • 记忆网络(Memory Network)
  • 多层Attention 机制

应用场景跟上一篇分析的内容一样,都是多层次语义情感分析的。

大概框架

整体架构思路就是计算得到context的importance和文本表示,怎么计算呢?就是利用多层计算层进行计算,每个计算层又由MN和attention组合在一起。attention机制又分成了传统的content attention,和新提出来的location attention…

优点

  • 和目前最好的features+SVM对比,达到了state-of-art的水平
  • 和序列模型LSTM和attention+LSTM相比,表现要更好
  • 相同条件下,运行速度要比LSTM快15倍

memory network

memory network是Jason Weston在14年提出来的想法,Sainbayar Sukhbaatar在15年提出了让memory network进行end to end的训练方法,并在QA上取得了较好的效果。

关于memory network的相关内容可参考下面两篇论文:

大致思想:

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的例子如下:

《《Aspect Level Sentiment Classification with Deep Memory Network》笔记》 image

这里想要提到的是,O组件是可以包含多层计算层的。
计算层称为hop.主要原因是多层次的hop可以提取更多的抽象语义信息。

框架设计

整体框图如下:

《《Aspect Level Sentiment Classification with Deep Memory Network》笔记》 image

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:

《《Aspect Level Sentiment Classification with Deep Memory Network》笔记》 image

即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的输出结果求和作为下一个computational layer的输入;
  • 其它computational layer执行同样的操作,上一层的输出作为输入,通过attention机制获取memory中较重要的信息,与线性层得到的结果求和作为下一层的输入。
  • 最后一层的输出作为结合aspect信息的sentence representation,作为aspect-level情感分类的特征,送到softmax。

tips: 参数共享

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差不多,这里就直接列公式了:

每一层的输出向量为:

《《Aspect Level Sentiment Classification with Deep Memory Network》笔记》 image

这里mi为记忆网络里面的第i个向量,并且,

《《Aspect Level Sentiment Classification with Deep Memory Network》笔记》 image

打分函数,计算aspect与记忆网络里每个mi的分数:

《《Aspect Level Sentiment Classification with Deep Memory Network》笔记》 image

再由打分函数得到的分值,得到权重(即attention值):

《《Aspect Level Sentiment Classification with Deep Memory Network》笔记》 image

这里我们就想问了,这里记忆函数的mi是如何得来的呢?

这里就要开始讲论文提到的另一个attention了,location attention.

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

作者一共提到了4种计算mi的方法模型,

《《Aspect Level Sentiment Classification with Deep Memory Network》笔记》 image

ei是context vector, vi是location vector for word wi.

模型3,4中作为模型的一个参数,随机初始化,通过梯度下降学习得到。只是模型4中加了一层sigmoid函数。

训练过程

  • softmax
  • 交叉熵loss
  • BP
  • 随机梯度下降来更新参数

实验结果

数据

《《Aspect Level Sentiment Classification with Deep Memory Network》笔记》 image

结果

《《Aspect Level Sentiment Classification with Deep Memory Network》笔记》 image

时间

《《Aspect Level Sentiment Classification with Deep Memory Network》笔记》 image

location attention对比

《《Aspect Level Sentiment Classification with Deep Memory Network》笔记》 image

根据上图可以看出:

  • 随着computational layers的增多,分类准确率有提升;
  • 在computational layer数大于5的时候,四个模型准确率相差不大;
  • model 2计算量最小,准确率也不差。

计算单元层数和location信息的作用分析

《《Aspect Level Sentiment Classification with Deep Memory Network》笔记》 image

从Table 4和Table 5对比可以看出:

  • 增加computational layer可以提取更abstractive的evidence(针对某个特定的aspect),更好的区分不同context word对特定aspect的贡献;
  • 引入location信息明可以更好地捕获针对特定aspect更重要的context信息。

写在最后

论文创新点在于将QA中常用的记忆网络结合attention,多层computing layers,应用于多层次语义情感分析。

下一步工作,研究记忆网络和这篇论文的复现代码。

    原文作者:bupt_周小瑜
    原文地址: https://www.jianshu.com/p/a3484dc3a3dc#comments
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞