3.7.2 推理
推理方式根据不同类别分为单步模型(Single-Step Reasoning)和多步模型(Multi-Step Reasoning)
单步模型只将问题和文档内容匹配一次并生成答案。
左边是随机答案网络,右边是BiDirectional Attention Flow model
我们现在从Memory中找出答案范围,首先,总的问题矢量为:
h
q
=
∑
i
β
i
h
i
q
\mathbf{h}^{q}=\sum_{i} \beta_{i} \mathbf{h}_{i}^{q}
hq=i∑βihiq
其中
β
i
=
exp
(
w
⊤
h
i
q
)
/
∑
k
exp
(
w
⊤
h
k
q
)
\beta_{i}=\exp \left(\mathbf{w}^{\top} \mathbf{h}_{i}^{q}\right) / \sum_{k} \exp \left(\mathbf{w}^{\top} \mathbf{h}_{k}^{q}\right)
βi=exp(w⊤hiq)/∑kexp(w⊤hkq),w是权重矢量
然后用双线性函数获得整段的起始指数的概率分布:
p
(
s
t
a
r
t
)
=
softmax
(
h
q
⊤
W
(
s
t
a
r
t
)
M
)
\mathbf{p}^{(s t a r t)}=\operatorname{softmax}\left(\mathbf{h}^{q \top} \mathbf{W}^{(s t a r t)} \mathbf{M}\right)
p(start)=softmax(hq⊤W(start)M)
另一个双线性函数用于获得最终索引的概率:
p
(
e
n
d
)
=
softmax
(
[
h
q
;
∑
i
p
j
(
s
t
a
r
t
)
m
j
]
⊤
W
(
e
n
d
)
M
)
\mathbf{p}^{(e n d)}=\operatorname{softmax}\left(\left[\mathbf{h}^{q} ; \sum_{i} p_{j}^{(s t a r t)} \mathbf{m}_{j}\right]^{\top} \mathbf{W}^{(e n d)} \mathbf{M}\right)
p(end)=softmax⎝⎛[hq;i∑pj(start)mj]⊤W(end)M⎠⎞
分号表示向量或矩阵连接运算符,
p
j
(
start
)
p_{j}^{(\text { start })}
pj( start )表示段落中第j个单词作为答案跨度开始的概率,
m
j
\mathrm{m}_{j}
mj是memory的第j个矢量
总结
单步模型简单有效,可以用反向传播进行训练。
多步模型
多步模型推理优于单步模型,动态的多步优于固定的多步推理,但动态的多步推理模型必须使用深度强化学习的方式,如policy gradient由于其不稳定而难以实施。???
上图左侧的SAN模型结合两种类型。SAN使用固定数量的推理步骤,并在解码期间,答案基于所有步骤中的预测平均值。然而,在训练期间,SAN通过dropout来降低预测,并基于剩余预测的平均值生成最终结果。虽然简单,但该技术显着提高了模型的稳健性和整体精度。此外,可以使用简单且有效的反向传播来训练SAN在每一步产生预测。
多步模型输出应答范围。基于RNN,和IRN相似,包含一个状态矢量,每步都会更新,状态定义为:
s
t
=
RNN
(
s
g
−
1
,
x
t
)
\mathbf{s}_{t}=\operatorname{RNN}\left(\mathbf{s}_{g-1}, \mathbf{x}_{t}\right)
st=RNN(sg−1,xt),其中
x
t
\mathbf{x}_{t}
xt包含了前一个状态作为问题通过注意力层的信息,即:
x
t
=
∑
j
γ
j
m
j
and
γ
=
softmax
(
s
t
−
1
⊤
W
(
a
t
t
)
M
)
\mathrm{x}_{t}=\sum_{j} \gamma_{j} \mathrm{m}_{j} \text { and } \gamma=\operatorname{softmax}\left(\mathrm{s}_{t-1}^{\top} \mathrm{W}^{(a t t)} \mathrm{M}\right)
xt=j∑γjmj and γ=softmax(st−1⊤W(att)M)
最终,双线性函数计算起始和终止答案范围如下:
p
t
(
s
t
a
r
t
)
=
softmax
(
s
t
⊤
W
(
s
t
a
r
t
)
M
)
p
t
(
e
n
d
)
=
softmax
(
[
s
t
;
∑
j
p
t
,
j
(
s
t
a
r
t
)
m
j
]
⊤
W
(
e
n
d
)
M
)
\begin{array}{l}{\mathbf{p}_{t}^{(s t a r t)}=\operatorname{softmax}\left(\mathbf{s}_{t}^{\top} \mathbf{W}^{(s t a r t)} \mathbf{M}\right)} \\ {\mathbf{p}_{t}^{(e n d)}=\operatorname{softmax}\left(\left[\mathbf{s}_{t} ; \sum_{j} p_{t, j}^{(s t a r t)} \mathbf{m}_{j}\right]^{\top} \mathbf{W}^{(e n d)} \mathbf{M}\right)}\end{array}
pt(start)=softmax(st⊤W(start)M)pt(end)=softmax([st;∑jpt,j(start)mj]⊤W(end)M)
训练
神经MRC模型可以用反向传播和SGD以端到端的形式进行参数优化,其损失函数为:
L
(
θ
)
=
−
1
∣
D
∣
∑
i
∣
D
∣
(
log
(
p
y
i
(
s
t
a
r
t
)
(
s
t
a
r
t
)
)
+
log
(
p
y
i
(
e
n
d
)
(
e
n
d
)
)
)
L(\theta)=-\frac{1}{|\mathcal{D}|} \sum_{i}^{|\mathcal{D}|}\left(\log \left(p_{y_{i}^{(s t a r t)}}^{(s t a r t)}\right)+\log \left(p_{y_{i}^{(e n d)}}^{(e n d)}\right)\right)
L(θ)=−∣D∣1i∑∣D∣(log(pyi(start)(start))+log(pyi(end)(end)))
其中y代表正确的起止答案范围。