8_Self-Attention(自注意力机制)

一、Self-Attention

  • Self-Attention,把Attention用在一个RNN网络上
  • Attention可以用在所有的RNN上
  • Self-Attention [2]: attention [1] beyond Seq2Seq models.
  • The original self-attention paper uses LSTM .(self-attention的原始论文,把attention用在LSTM上)
  • To make teaching easy, I replace LSTM by SimpleRNN.(我把LSTM换成SimpleRNN)

Original paper:

  1. Bahdanau, Cho, & Bengio. Neural machine translation by jointly learning to align and translate. in ICLR, 2015.
  2. Cheng, Dong, & Lapata. Long Short-Term Memory-Networks for Machine Reading. In EMNLP, 2016.

二、SimpleRNN + Self-Attention

  • 初始时,C0 和 状态向量h0 都是全零向量。
  • RNN读入第一个输入X1 ,需要更新状态h,把X1 的信息压缩到新的状态h中,计算h1
  • 下一步,计算C1 ,是已有状态的加权平均。

image-20210403151825229

  • 想要计算Ci ,需要计算权重αi ,计算第二个Weights:αi = align(hi ,h2).

  • 对已有的状态h1,和h2做加权平均来计算C,由于h0为全零向量,以后忽略h0
    image-20210403154147400

  • 之后不断重复这个过程。

三、Summary(总结)

  • With self-attention, RNN is less likely to forget.(self-attention不局限于Seq2Seq模型,self-attention可以用在所有的RNN上)
  • Pay attention to the context relevant to the new input.(除了避免遗忘,self-attention能帮助RNN关注相关的信息)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

少云清

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值