Attention

2019-11-27  本文已影响0人  Plenari

1.注意力Q,K,V来源,这个文章的讲自然语言的。

The second step in calculating self-attention is to calculate a score. Say we’re calculating the self-attention for the first word in this example, “Thinking”. We need to score each word of the input sentence against this word. The score determines how much focus to place on other parts of the input sentence as we encode a word at a certain position.

The score is calculated by taking the dot product of the query vector with the key vector of the respective word we’re scoring. So if we’re processing the self-attention for the word in position #1, the first score would be the dot product of q1 and k1. The second score would be the dot product of q1 and k2

注意力

两种:

文本翻译

soft attention :思是在求注意力分配概率分布的时候,对于输入句子
X中任意一个单词都给出个概率,是个概率分布。
hard attention: 对不齐的概率认为是0

global attention model : soft attention model
local attention model : soft attention model & hard attention model

计算机视觉

分类和mask解耦,

有多个类别的mask,反向传播只优化当前类别对应的mask.

混合注意力机制

不传递谁的损失函数,不更新谁的梯度。

残差注意力模型

每个注意力模块分为两部分:mask (M)和trunk(T),基于特征提取网络提取特征T,

H_i,c​ (x)=M_i,c​ (x)∗T_i,c​ (x)

注意力模块中,注意力掩膜在forward时作为特征选择器,在反向传播时则作为梯度更新的滤波器。

注意力残差学习

由于注意力用到了softmax 网络,如果太多的注意力模型会导致模型输出的响应变弱,可能对梯度也会产生一定的影响。
所以用残差的注意力:
H_i,c​ (x)=(1+M_i,c​ (x))∗T_i,c​ (x)
一般M的取值范围在[01,]之间,除了得到注意力之外还要把特征图加上。

这是学习到的注意力

软掩膜分支

掩膜分支包括了快速前馈扫描(fast feed-forward sweep)和自上而下的反馈(top-down feedback)步骤。前者快速收集整个图像的全局信息,后者将全局信息与原始特征图相结合。在卷积神经网络中,这两个步骤展开为bottom-up top-down的全卷积结构。

掩膜

先对原图下采样,得到主要特征后,在上采样使大小与原图一样,然后通过sigmoid 。

空间注意力

使用L2正则化约束每个位置上的所有通道,推测最终输出一个空间维度一致的Attention Map;


image.png

通道注意力

类似于SENet使用L2正则化约束每一个通道上的所有特征值,最后输出长度与通道数相同的一维向量作为特征加权;这个和公式里描述的是一样吗?

image.png

混合注意力

对通道和空间位置都是用


image.png

attention all you need

注意力

image.png

多头注意力机制

多头

自注意力

image.png

position Embedding

不知之处

attention

Task 1

学习权重分布

任务2

注意力和特征

image.png

ws -dan

通过1x1卷积产生注意力?这不是我常见的,我的疑惑就在这里。他既不是通道注意力,也不是空间注意力。

上一篇 下一篇

猜你喜欢

热点阅读