paper解读:Bi-Directional Attention Flow For Machine Comprehension

基于双向注意力的阅读理解(ICLR2017,引用800多,入门阅读理解可以看这篇)
paper: https://arxiv.org/abs/1611.01603
code: https://github.com/allenai/bi-att-flow

模型框架

模型主要框架如下图所示:
在这里插入图片描述

包括六个部分:
Character Embedding Layer:使用character-level CNNs将词转换成向量;
Word Embedding Layer:使用预训练的word embedding模型将词转换成向量,如glove等;
Contextual Embedding Layer:利用周围单词的上下文提示来完善单词的嵌入,如Bi-LSTM。同时应用于query和context;
Attention Flow Layer:将query向量和context向量耦合,包括query2context attention和context2query attention;
Modeling Layer:使用RNN模型学习上下文表示;
Output Layer:得到query的答案。
值得注意的是,前三步在不同粒度下计算query和context的特征,这有点像计算机视觉领域的CNN中的多阶段特征计算的过程。

双向注意力流

下面具体讲一下Attention Flow Layer.
在这一步中,作者计算两个方向的attention:从context到query以及query到context。这两个方向的attention都基于相同的相似度矩阵 S R T × J S\in R^{T\times J} ,其中H表示context embedding,U表示query embedding。 S t , j S_{t,j} 表示context的第t个时刻和query的第j个时刻的相似度,具体如下:
S t , j = α ( H : t , U : j ) R S_{t,j}=\alpha(H_{:t},U_{:j})\in R
其中, α \alpha 是可训练标量, H R 2 d × T , U R 2 d × J H\in R^{2d\times T}, U\in R^{2d\times J} H : t H_{:t} 表示H的第t列,即第t个时刻的向量,同样, U : j U_{:j} 表示U的第j列,即第j个时刻的向量.可选的, α ( h , u ) = w S T [ h ; u ; h u ] \alpha(h,u)=w^T_S[h;u;h\circ u] w S T R 6 d w^T_S\in R^{6d} 是一个可训练权重向量。

context-to-query attention

context-to-query(C2Q)目的是得到context的每个词中,与query各个词的相关性。
a t R J a_t\in R^J 表示第t个context word与query各个词的attention权重,其中 j a t j = 1 \sum_ja_{tj}=1 (这里应该是所有j的和为1,作者写的是all t,应该是写错了)。 a t = s o f t m a x ( S t : ) R J a_t=softmax(S_{t:})\in R^J ,因此 U ~ : t = j a t j U : j \widetilde U_{:t}=\sum_ja_{tj}U_{:j}

query-to-context attention

query-to-context attention(Q2C)目的是得到query的每个词中,与其最相似的context word,这是回答query的一个重要参考。
首先,使用 b = s o f t m a x ( m a x c o l ( S ) ) R T b=softmax(max_{col}(S))\in R^T 获得context words的attention权重。其次, h ~ = t b t H : t R 2 d \widetilde h=\sum_tb_tH_{:t}\in R^{2d} .此向量表示上下文中相对于query而言最重要的单词的加权和. h ~ \widetilde h 在列维度上复制T次得到 H ~ R 2 d × T \widetilde H\in R^{2d\times T} .
最后,对上述向量进行拼接得到 G : t = β ( H : t , U ~ : t , H ~ : t ) R d G G_{:t}=\beta (H_{:t},\widetilde U_{:t},\widetilde H_{:t})\in R^{d_G} ,特别地,可令 β ( h , u ~ , h ~ ) = [ h ; u ~ , h u ~ ; h h ~ ] \beta(h,\widetilde u,\widetilde h)=[h;\widetilde u,h\circ \widetilde u;h\circ \widetilde h]

Modeling Layer

将上一步的G作为输入,使用bi-LSTM得到输出 M R 2 d × T M\in R^{2d\times T}

Output Layer

QA任务需要模型从paragraph中找到一个子序列来作为query的答案。因此,output layer的目的是预测开始索引和结束索引。
p 1 = s o f t m a x ( w p 1 T [ G ; M ] ) p^1=softmax(w^T_{p^1}[G;M])
p 2 = s o f t m a x ( w p 2 T [ G ; M ] ) p^2=softmax(w^T_{p^2}[G;M])
training loss使用两个索引的交叉熵损失的和,即
L ( θ ) = 1 N i N l o g ( p y i 1 1 ) + l o g ( p y i 2 2 ) L(\theta)=-\frac{1}{N}\sum^N_ilog(p^1_{y^1_i})+log(p^2_{y^2_i})
测试阶段:当 p k 1 p l 2 p^1_kp^2_l 取得最大值时,使用answer span(k,l)作为query的答案,其中 k l k\leq l

猜你喜欢

转载自blog.csdn.net/Flying_sfeng/article/details/105936639
今日推荐