最常用的注意力机制为additive attention 和dot product attention

additive attention :

additive attention 与 dot product attention
dkd_k较小时,两者中additive attention优于不做scale的dot product attention,当dkd_k较大时,dot product attention方差变大,会导致softmax函数中梯度消失(类似sigmoid,导数为tex(t+ex)2\frac{te^x}{(t+e^x)^2},方差大时会导致有个值的exe^x远大于其他的,会导致无论对任何值都有exe^x或者tt特别大,导数从而为0),从而需要对它做一个scale,假设x每一维都是均值为0,方差为1,则向量点积方差为dkd_k所以需要除以标准差。

dot product attention在实践中更快和更节省空间,因为它可以使用高度优化的矩阵乘法代码来实现。

attention种类还有许多,可以参考下面blog
https://www.jianshu.com/p/cf41f3f91d94
https://www..com/article/5362316581/

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-04-15
  • 2021-04-04
  • 2021-05-29
猜你喜欢
  • 2022-01-08
  • 2021-11-07
  • 2021-08-01
  • 2021-06-19
  • 2021-06-21
  • 2022-12-23
  • 2022-01-22
相关资源
相似解决方案