Attention 中的 Q, K, V
flyfish
Attention Is All You Need.
Q = query = 查询
K = key = 键
V = value = 值
简单理解
一篇文章,文章的标题就是key,文章的内容就是V
使用搜索引擎时,输入到 搜索栏中的文本 就是 query
输入内容 query 与 文章标题 key之间的相似性计算就是 评分函数
输入一个apple,query有水果的 apple也有手机的apple就是多个头,也就是Multi-Head Attention
多个头就可以让模型同时关注多个方面的语义相似性。
对应的key与query相似
α
i
=
exp
(
f
a
t
t
n
(
key
i
,
query
)
)
∑
j
exp
(
f
a
t
t
n
(
key
j
,
query
)
)
,
out
=
∑
i
α
i
⋅
value
i
\alpha_i = \frac{\exp\left(f_{attn}\left(\text{key}_i, \text{query}\right)\right)}{\sum_j \exp\left(f_{attn}\left(\text{key}_j, \text{query}\right)\right)}, \hspace{5mm} \text{out} = \sum_i \alpha_i \cdot \text{value}_i
αi=∑jexp(fattn(keyj,query))exp(fattn(keyi,query)),out=i∑αi⋅valuei
Multi-head就是多做几次 Scaled Dot-product Attention,然后把结果拼接