当前位置:网站首页>【对比学习】Understanding the Behaviour of Contrastive Loss (CVPR‘21)
【对比学习】Understanding the Behaviour of Contrastive Loss (CVPR‘21)
2022-07-25 11:11:00 【chad_lee】
Understanding the Behaviour of Contrastive Loss (CVPR’21)
Contrastive Loss中的温度系数 τ \tau τ 是个关键参数,大部分论文都把 τ \tau τ 设置为一个小数字,这篇文章从分析温度参数 τ \tau τ 出发,分析出:
- 对比损失实际上可以自动挖掘出难负样本,因此可以学习出高质量的自监督表征。具体地,对于已经远离的负样本,不需要让其继续远离;主要聚焦于没有远离的负样本(难负样本),从而使得表示空间更均匀(和下面那个红圈圈图差不多意思)。
- 温度系数 τ \tau τ 可以控制挖掘负样本的程度, τ \tau τ 越小越关注难负样本。
Hardness-Awareness
广泛使用的对比损失函数是InfoNCE:
L ( x i ) = − log [ exp ( s i , i / τ ) ∑ k ≠ i exp ( s i , k / τ ) + exp ( s i , i / τ ) ] \mathcal{L}\left(x_{i}\right)=-\log \left[\frac{\exp \left(s_{i, i} / \tau\right)}{\sum_{k \neq i} \exp \left(s_{i, k} / \tau\right)+\exp \left(s_{i, i} / \tau\right)}\right] L(xi)=−log[∑k=iexp(si,k/τ)+exp(si,i/τ)exp(si,i/τ)]
该损失函数要求第 i 个样本和它另一个扩增的(正)样本之间的相似度 s i , i s_{i,i} si,i 之间尽可能大,而与其它实例(负样本)之间的相似度 s i , k s_{i,k} si,k 之间尽可能小。但是满足这一条件的损失函数很多,比如一个最简单的函数 L simple \mathcal{L}_{\text {simple }} Lsimple :
L simple ( x i ) = − s i , i + λ ∑ i ≠ j s i , j \mathcal{L}_{\text {simple }}\left(x_{i}\right)=-s_{i, i}+\lambda \sum_{i \neq j} s_{i, j} Lsimple (xi)=−si,i+λi=j∑si,j
但这两个损失函数的训练效果差很多:
| 数据集 | Contrastive Loss | Simple Loss |
|---|---|---|
| CIFAR-10 | 79.75 | 74 |
| CIFAR-100 | 51.82 | 49 |
| ImageNet-100 | 71.53 | 74.31 |
| SVHN | 92.55 | 94.99 |
这是因为Simple Loss对所有的负样本相似度给予了相同权重的惩罚: ∂ L simple ∂ s i , k = λ \frac{\partial L_{\text {simple }}}{\partial s_{i, k}}=\lambda ∂si,k∂Lsimple =λ,即损失函数对所有负样本的相似度的梯度是相等的。但是在Contrastive Loss中,会自动给相似度更高的负样本更高的惩罚:
对正样本的梯度 : ∂ L ( x i ) ∂ s i , i = − 1 τ ∑ k ≠ i P i , k 对负样本的梯度 : ∂ L ( x i ) ∂ s i , j = 1 τ P i , j ∝ s i , j \text { 对正样本的梯度 : } \frac{\partial \mathcal{L}\left(x_{i}\right)}{\partial s_{i, i}}=-\frac{1}{\tau} \sum_{k \neq i} P_{i, k} \\ \text { 对负样本的梯度 : } \frac{\partial \mathcal{L}\left(x_{i}\right)}{\partial s_{i, j}}=\frac{1}{\tau} P_{i, j} \propto s_{i, j} 对正样本的梯度 : ∂si,i∂L(xi)=−τ1k=i∑Pi,k 对负样本的梯度 : ∂si,j∂L(xi)=τ1Pi,j∝si,j
其中 P i , j = exp ( s i , j / τ ) ∑ k ≠ i exp ( s i , k / τ ) + exp ( s i , i / τ ) P_{i, j}=\frac{\exp \left(s_{i, j /} \tau\right)}{\sum_{k \neq i} \exp \left(s_{i, k} / \tau\right)+\exp \left(s_{i, i} / \tau\right)} Pi,j=∑k=iexp(si,k/τ)+exp(si,i/τ)exp(si,j/τ),对于所有负样本, P i , j P_{i, j} Pi,j的分母是相同的,所以 s i , j s_{i, j} si,j越大,负样本的梯度项也越大,也就给予了负样本更大远离该样本的梯度。(可以理解为focal loss,越难梯度越大)。从而鼓励所有样本均匀的分布在一个超球面上。
为了验证真的Contrastive Loss真的是因为能够挖掘难负样本的特性,文章显示的额外选取一些困难样本用在Simple Loss上(为每个样本选取4096个难负样本),性能大大提升:
| 数据集 | Contrastive Loss | Simple Loss + Hard |
|---|---|---|
| CIFAR-10 | 79.75 | 84.84 |
| CIFAR-100 | 51.82 | 55.71 |
| ImageNet-100 | 71.53 | 74.31 |
| SVHN | 92.55 | 94.99 |
温度系数 τ \tau τ控制程度
温度系数 τ \tau τ越小,损失函数越关注难负样本,特别地:
当 τ \tau τ趋近于0时,Contrastive Loss退化成只关注最难的样本:
lim τ → 0 + 1 τ max [ s max − s i , i , 0 ] \lim _{\tau \rightarrow 0^{+}} \frac{1}{\tau} \max \left[s_{\max }-s_{i, i}, 0\right] τ→0+limτ1max[smax−si,i,0]
这意味着将挨个把每个负样本推到离自己相同的距离:

当 τ \tau τ趋近于无穷大时,Contrastive Loss几乎退化成Simple Loss,对所有负样本的权重相同。
所以温度系数 τ \tau τ越小,样本特征的分布越均匀,但这也不是好事,因为潜在正样本(False Negative)也被推走了:

边栏推荐
- 硬件连接服务器 tcp通讯协议 gateway
- Flinksql client connection Kafka select * from table has no data error, how to solve it?
- Objects in JS
- [USB device design] - composite device, dual hid high-speed (64BYTE and 1024byte)
- MIIdock简述
- Transformer变体(Routing Transformer,Linformer,Big Bird)
- Multi-Label Image Classification(多标签图像分类)
- 银行理财子公司蓄力布局A股;现金管理类理财产品整改加速
- 基于W5500实现的考勤系统
- Introduction to pl/sql, very detailed notes
猜你喜欢

第4章线性方程组

教你如何通过MCU将S2E配置为UDP的工作模式

Risks in software testing phase

【IMX6ULL笔记】--内核底层驱动初步探究

基于W5500实现的考勤系统

Brpc source code analysis (VIII) -- detailed explanation of the basic class eventdispatcher

图神经网络用于推荐系统问题(IMP-GCN,LR-GCN)

JVM performance tuning methods

Review in the middle of 2022 | understand the latest progress of pre training model

JS数据类型以及相互转换
随机推荐
【高并发】SimpleDateFormat类到底为啥不是线程安全的?(附六种解决方案,建议收藏)
JS interview question: handwriting throttle function
Hardware peripherals =maixpy3
JaveScript循环
Wiznet embedded Ethernet technology training open class (free!!!)
There is no sound output problem in the headphone jack on the front panel of MSI motherboard [solved]
教你如何通过MCU将S2E配置为UDP的工作模式
Layout management ==pyqt5
How to solve the problem that "w5500 chip cannot connect to the server immediately after power failure and restart in tcp_client mode"
Maskgae: masked graph modeling meets graph autoencoders
菜单栏+状态栏+工具栏==PYQT5
已解决 Files‘ name is invalid or does not exist (1205)
JS数据类型以及相互转换
GPT plus money (OpenAI CLIP,DALL-E)
Objects in JS
The first C language program (starting from Hello World)
session和cookie有什么区别??小白来告诉你
brpc源码解析(一)—— rpc服务添加以及服务器启动主要过程
JS 面试题:手写节流(throttle)函数
用 Redis 做一个可靠的延迟队列