Deep Learning中Transformer的学习笔记

目录

1. Tranformer与RNN对比

1.1 RNN模型缺点: 

1.2 Transformer优点: 

2. Transformer的结构

2.1 Attention 注意力机制作用的流程

首先就是那篇最著名的文章《Attention is all you need》, 链接如下: https://arxiv.org/abs/1706.03762

1. Tranformer与RNN对比

RNN Model: Recurrent Neural Networks  RNN模型一般用于时间序列的预测,一般把信息存在h_t和hh_{t-1}的信息上,所以时点上携带的信息比较大. 

1.1 RNN模型缺点: 

  1. Slow to train 训练的速度特别慢 
  2. Long sequences lead to vanishing/exploding gradients 
  3. 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

https://arxiv.org/abs/1706.03762

https://www.youtube.com/watch?v=ySEx_Bqxvvo&t=117s

猜你喜欢

转载自blog.csdn.net/weixin_44897685/article/details/130920338