最常用的注意力机制为additive attention 和dot product attention
additive attention :
在较小时,两者中additive attention优于不做scale的dot product attention,当较大时,dot product attention方差变大,会导致softmax函数中梯度消失(类似sigmoid,导数为,方差大时会导致有个值的远大于其他的,会导致无论对任何值都有或者特别大,导数从而为0),从而需要对它做一个scale,假设x每一维都是均值为0,方差为1,则向量点积方差为所以需要除以标准差。
dot product attention在实践中更快和更节省空间,因为它可以使用高度优化的矩阵乘法代码来实现。
attention种类还有许多,可以参考下面blog
https://www.jianshu.com/p/cf41f3f91d94
https://www..com/article/5362316581/