coursera deeplearning
一、组成
![](https://img.haomeiwen.com/i3633179/749421078ac9130a.png)
二、self-attention
self-attention 是 Transformer Network 中比较核心的部分,目的是使文本中某个单词与其他单词产生联系,产生联系后的单词为 z
1、在 self-attention 当中输入单词数和输出单词数一致
![](https://img.haomeiwen.com/i3633179/01dda919232ef9ce.jpg)
2、计算过程
![](https://img.haomeiwen.com/i3633179/b51ca57e9ba7ea9a.png)
![](https://img.haomeiwen.com/i3633179/0d9c4dda3ccb7836.png)
Q : 向量
K : 向量
V : 向量
dk : 向量维度
认为两个向量越相近,相乘值越高
三、Multi-head attention
多头注意力机制就是将多个 single attention function 的结果进行 concat 拼接,拼接后再与一个矩阵相乘,认为不同的输入 z 关注不同距离的注意力 attention
![](https://img.haomeiwen.com/i3633179/c71481962d6720f6.png)
Mutil-Head :
![](https://img.haomeiwen.com/i3633179/d350a5337d94af93.png)
![](https://img.haomeiwen.com/i3633179/823f196ae4e03850.png)
四、Position Encoding
为了体现单词之间的相对关系,使用 Position Encoding , 在 Input Embedding 之后与 Position Encoding 相加
五、encoder & decoder
encoder : 生成 K V 矩阵
decoder : 生成 Q 矩阵
交互如下:
![](https://img.haomeiwen.com/i3633179/d98491bfdae5ad57.png)
![](https://img.haomeiwen.com/i3633179/e6f16d216c4cdf2b.png)
![](https://img.haomeiwen.com/i3633179/1206b9aeeffcd410.png)
六、其他
Norm : 使用了归一化但和 BN 不同
Feed Forward : 全连接
N× : 有 N 个 encoder 和 N 个 decoder
参考
https://zhuanlan.zhihu.com/p/46990010
https://www.bilibili.com/video/BV1Di4y1c7Zm?p=7
https://www.bilibili.com/video/BV1L54y1a7Y3
网友评论