目录
首先就是那篇最著名的文章《Attention is all you need》, 链接如下: https://arxiv.org/abs/1706.03762
1. Tranformer与RNN对比
RNN Model: Recurrent Neural Networks RNN模型一般用于时间序列的预测,一般把信息存在和h的信息上,所以时点上携带的信息比较大.
1.1 RNN模型缺点:
- Slow to train 训练的速度特别慢
- Long sequences lead to vanishing/exploding gradients
- LSTM is slower
1.2 Transformer优点:
Attention mechanism has an infitnite reference window 注意力机制有无限的参考时间窗口
2. Transformer的结构
在使用卷积网络的时候, 是使用较小的窗格来进行计算,所以当位置比较远的时候,可能会需要再比较远的地方才能找到信息. 而transformer则可以一起看到.
文章中结构的图示:
在图中左边是编码器,右边是解码器.
与batchNorm对比, LayerNorm用的比较多的原因是因为在时序序列中,样本数据的量可能在变化
2.1 Attention 注意力机制作用的流程
Attention是Transformer的重点, 主要的目标是为了找到input里面最重要的特征 (identify and attend to most important features in input.)
Attention: What part of the input should we focus?
注意力机制分为加性和乘性. N为编码器的层数的堆叠, 每一个子层之间通过残差连接.在解码器的连接也是通过残差连接. Masked Multi-Head Attention, 带有掩码的注意力机制,也就是在training的时候不会看到t后面的数据.
Attention在Transformer里面的使用方式(编码器Encoder-解码器 Decoder):
- 编码位置信息 Encode position information
- 提取查询、键、值用于搜索 Extract query, key, value for search
- 计算注意力加权 Compute attention weighting
- 提取高度关注的特征 Extract features with high attention
参考资料:
https://www.youtube.com/watch?v=TQQlZhbC5ps
https://www.youtube.com/watch?v=nzqlFIcCSWQ