笔记原文地址:http://chenhao.space/post/e76a9f9c.html
摘要
论文地址:https://arxiv.org/abs/1703.03130
本篇论文提出了一种基于自注意力机制(自注意力机制是注意力机制的改进,其减少了对外部信息的依赖,更擅长捕捉数据或特征的内部相关性)的sentence embedding。
sentence embedding模型用 2-D matrix 来表示一句话的embedding(而不是传统的vector),matrix中的每一行表示了句子中的不同的部分 。基于sentence embedding模型,论文还提出自注意力机制和一种特殊的正则化项的方法。对于该模型,一个附带的作用就是可以用一种简单的方法把句子中被encode到embedding的特殊的部分可视化出来。
作者在三个公开数据集上进行实验,并且取得了不错的效果。
Self-attention机制
For some tasks people propose to use attention mechanism on top of the CNN or LSTM model to introduce extra source of information to guide the extraction of sentence embedding. However, for some other tasks like sentiment classification, this is not directly applicable since there is no such extra information: the model is only given one single sentence as input.
意思是,对于一些任务,我们经常会使用CNN或者LSTM模型再加上注意力机制去引入额外的信息用来辅助sentence embedding的抽取。
但是,对于一些其他的任务,比如情感分类任务,上面说的模型就不能很好的应用了,因为这类任务输入的仅仅是一句话,没有额外的信息可以抽取。
这种情况下,最常用的解决方法是add a max pooling or averaging step across all time steps,或者提取the hidden representation at the last time step as the encoded embedding。
我们假设在 recurrent model 的所有时间步长上携带语义是相对困难和不必要的,所以为这些序列模型提出了一种自注意力机制(self-attention mechanism)来代替 max pooling or averaging step 。
self-attention 的好处
不同于之前的方法,这种自注意力机制可以提取句子中的不同方面,用多个向量来表示。
In addition, due to its direct access to hidden representations from previous time steps, it relieves some long-term memorization burden from LSTM.
As a side effect coming together with our proposed self-attentive sentence embedding, interpreting the extracted embedding becomes very easy and explicit.
模型的详细介绍
论文提出的模型由两部分组成,一部分是biLSTM,另一部分是self-attention mechanism(它为LSTM的隐藏层状态提供了一组summation weight vectors)。这些summation weight vectors与LSTM的隐藏状态进行点乘,得到的加权后的隐藏状态被视为句子的embedding。
Figure 1 展示了sentence model应用与情感分析任务,模型中结合了全连接层和softmax层。
假设我们有一个包含n个词的句子,它被表示为一个序列的word embedding:
S = ( w 1 , w 2 , . . . , w n ) S=(w_1,w_2,...,w_n) S=(w1,w2,...,wn)
其中, w i w_i wi为一个向量(vector)表示为一个d维word embedding( s i z e = ( 1 , d ) size=(1,d) size=(1,d)), i i i表示它是句子中的第 i i i个词。因此 S S S可表示为一个2-D matrix( s i z e = ( n , d ) size=(n,d) size=(n,d))。
为了获得两个相邻词之间的依赖,我们将 S S S送到biLSTM中进行处理:
设隐藏层的个数为 u u u,则我们得到一个新的隐藏层状态 H H H,它的 s i z e = ( n , 2 u ) size=(n,2u)