Fine-Grained Attention Mechanism for Neural Machine Translation

Fine-Grained Attention Mechanism for Neural Machine Translation

  1. 在这篇文章中作者提出了一种fine-grained的注意力机制即每一维的context vector将获得一个单独的注意力得分。
  2. 作者证明了这种做法的合理性

通过Choi et al.(2017)的文章,对词向量的维度进行contextualization发现词向量的每一个维度都都在context中充当着不同的作用,由于这一观点的启发,作者Choi 和Bengio便提出这种fine-grained的注意力机制。

Background : Attention-based Neral Machine Translation

这部分主要介绍了Bahdanau et al.(2015)提出的注意力机制。

given a source sentence X = ( w 1 x , w 2 x , . . . , w T x )

那么我们的目标函数就是 p ( Y = ( w 1 y , w 2 y , . . . , w T y ) | X ) .
解释为:在给定输入条件下,获得某一输出的概率。

在这个模型中包含Encoder,Decoder,and attention mechanism三个部分。

一、Encoder

encoder 通常通过双向循环神经网络来完成。在编码过程开始之前,每一个source word w t x 被映射到一个连续的向量空间中去(所有输入单词的词嵌入矩阵)。

x t = E x [ . , w t x ]

如果图示的话可以表示为:

这里写图片描述

将词向量一次输入到Encoder层中。
h t = Φ ( h t 1 , x t ) ,
h t = Φ ( h t + 1 , x t ) ,

这里的 Φ 可以是LSTM( Hochreiter and Schmidhuber (1997)),或者GRU( Cho et al. (2014)))。
在每一个t时刻将正反两个方向的结果concat在一起。

h t = [ h t , h t ]

这就获得了一个annotation vectors:
C = h 1 , h 2 , . . . , h T

二、Decoder

解码层可以模型化为:

p ( w t y | w < t y ) , X )

在source sentence和前t-1时刻的条件下取到当前标签的分布。
将这些概率相乘就得到了我们的目标概率。
解码层通常用一个单向的RNN:
h t = Φ ( z t 1 , y t 1 , c i ) ,

三、Attention mechanism

在解码层中维持着一个hidden state z t 。在每一个 t 时刻模型首先用注意力机制 f A t t 对C中的每一个向量进行select ,or weight 。在Bahdanau的注意了机制中 f A t t 是一个前向神经网络,输入分别为前一时刻的解码层的hidden state,和C中的一个向量。在这个前向神经网络中tanh()常常被作为激发函数。

e t , t = f A t t ( z t 1 , h t )

这里的得分 e t , t 用softmax来normalized.
a t t = e x p ( e t , t ) k = 1 T e x p ( e t , k )

再将对每一个annotation vector的weights加起来。
c t = t = 1 T a t t h t

与编码层不同的是这里的 y t 1 是上一个目标单词的向量。

这里的 c t 在作为Decoder的一个输入

h t = Φ ( z t 1 , y t 1 , c i ) ,

Variants of Attention Mechanism

Jean et al.(2015a); Chung et al. (2016a)L,uong et al.(2016)对Bahdanau et al.(2015)的注意力机制做了点改进。

前者将score function 修改成 e t , t = f A t t Y ( z t 1 , h t , y t 1 )
即加入了上衣时刻的输出值。

Fine-Grained Attention Mechanism

上面无论是Bahdanau的还是后面工作者所做的改进,给定一个query对于每一个context vector 仅得到一个注意力值。如图(a)所示。
作者提出的模型类似于途中的(b)所示。

这里写图片描述

e t , t d = f A t t Y 2 D d ( z t 1 , h t , y t 1 )

a t , t d = e x p ( e t , t d ) k = 1 T e x c p ( e e t , k d )

c t = s u m t = 1 T a t , t h t

这里的改变是讲aligment结果进行softmax后与每一个annotation vector做Hadamard 乘积,这样就将annotation vector的每一个维度独立开来进行注意力机制的描述。

[1] Fine-grained attention mechanism for neural machine translation

猜你喜欢

转载自blog.csdn.net/zhoukaiyin_hzau/article/details/80538701
今日推荐