Core-tuning论文阅读

本文最后更新于:1 天前

Core-tuning是一种finetune的方法,主要是提高自监督pretrained model在下游任务的性能。

关键

  • 正负样本
  • 对比损失
  • 权重

概括

论文地址Unleashing the Power of Contrastive Self-Supervised Visual Models via Contrast-Regularized Fine-Tuning

基本思想

使用contrastive loss,可以使模型在finetune过程中得到更好的优化和学习到更好的类区分表达能力

于是作者基于cross-entropy方法进行改进,将对比学习的思想融入到finetune方法中

Cross-entropy的不足

Although cross-entropy tends to separate inter-class features, the resulting models still have limited capability for reducing intra-class feature scattering that exists in CSL models.

单纯使用cross-entropy,虽然可以分离不同类之间的特征,但在下游任务进行finetune时,不能很好地减少pretrained model已学习到的类之间区分特征的影响。

image-20211021234925367

创新点

构建正负样本

image-20211021235714032

作者采用features mixup策略来构建正负样本,不同于论文 1单纯引入对比损失,更好地提高了finetune的效果

Very recently, one work [19] explored contrastive learning to fine-tune language models. However, it simply add the contrastive loss to the objective of fine-tuning and cannot theoretically explain why it boosts fine-tuning.

  • 生成hard smaple pairs(正负样本对)来提高计算效能
  • 同时平滑决策边界,提高了模型的泛化能力

contrast loss

  • 在cross-entropy可以学习到不错的类之间区分能力的基础上,增加了额外的正则化。使得模型可以学到每个类的low-entropy feature cluster和high-entropy feature space,即同类聚集程度高,不同类间分离度大
  • 优化contrastive loss可以比单纯使用cross-entropy收敛到更小的值,增加了额外的优化性能

总结

  • 论文中,对比损失和正负样本的构建这两个是相辅相成的

  • 正负样本的构建,这是core-tuning实现的重要依赖

    • contrastive learning highly relies on positive/negative sample pairs, but the majority of sample features are easy-to-contrast and may produce negligible contrastive loss gradients.

  • contrast loss也是通过正负样本才能对让模型对类更好地区分,同时平滑决策边界

方法与实现

对比损失函数

给定一个样本特征$z_i$作为anchor,$A_i$为anchor $z_i$集合,将与anchor同类的作为positive pairs,集合记为$P_i$,不同类的作为negative pairs,所有特征经过$l_2-normalized$

理论证明推导后续补充……

构建正负样本

image-20211022000428639

Mixing hard positive pairs

通过计算余弦相似度来选择hardest positive data和hardest negative data

$z^{hp}$在正样本里与anchor相似度最低,$z^{hn}$在负样本里与anchor相似度最高

Mixing hard negative pairs

随机选择一个负样本

总结

一个batch中的每一个样本(称为anchor)均对应生成一个正样本和一个负样本,故总样本规模为3xbatch_size

  • 正样本包含两部分:positive data 和 negative data, 通过$\lambda$控制权重

    • positive: 选取该batch样本中与anchor同类,但特征相似度最小的样本
    • negative:选取该batch样本中与anchor不同类,但特征相似度最高的样本
    • 该样本是由positive 和 negative 合成得到的,可能是不存在于原batch样本中的
  • 负样本为batch中随机抽取与anchor不同类的样本,但开源代码实现中,可能为与anchor同类的样本,但作者说不会对性能造成影响

    • # hard negative pair generation. 
          order = np.arange(batch_size) 
          random.shuffle(order)   
          # We randomly shuffle the sample order to find negative pairs. Even if a few pairs are not negative here, it won't affect the overall functionality. 
          features2 = features[order]    
          y_2 = one_hot_labels[order]
      
    • 该样本是由positive 和 negative 合成得到的,可能是不存在于原batch样本中的

权重设置

Hard Positive Reweighting

作者认为,hard positives 在对比学习中包含更多有用的信息,因此提高相应的权重

However, since hard pairs are more informative for contrastive learning, we propose to assign higher importance weights to hard positive pairs.

image-20211022000536552

Smooth Classifier Learning

image-20211022000624169

实验

image-20211022001442803

由于目前还没有其它应用于自监督pretrained model finetune的loss计算方法,作者将cross-entropy在supervised上的finetune作为baseline,其它在supervised上finetune的方法应用于训练自监督pretrained model作为参考

实验证明,Core-tuning对自监督pretrianed model的训练效果不错。

(有时间阅读表格中的finetune方法)

值得注意的图表

平滑边界

image-20211022001656128

可以看出平滑边界是一个有效提高性能的方法,需掌握

思考

  • 是否有其他实现平滑边界的方法?

正负样本

image-20211022002150119

可以看出,正负样本对于contrast loss的性能是有一定影响的,需掌握

思考

  • 正负样本的构建方法是否可替代?

权重设置

image-20211022002657690

作者觉得contrast loss更应该关注正样本的信息,于是提高相应权重

That is, contrastive learning highly relies on positive/negative sample pairs, but the majority of sample features are easy-to-contrast (cf. Figure 1 (a)) [20, 60] and may produce negligible contrastive loss gradients.

思考

  • 正样本的作用,为什么是关键
  • 实现权重分配的方法
  • 权重分配思想,需牢记

总结

个人感觉,core-tuning是来优化自监督网络的pretrained model,本身的训练过程和自监督是没有关系的,实际做的是有监督训练。

但作者把对比学习的思想融入进来是一个不错的idea,而且构建正负样本也很有意思,值得学习和借鉴。

思考

  • 正样本为两个不同类样本的合成,因此会是一个新的“类”,原本两个样本处于这两个类的分离边界附近

    • 由此加入正样本训练可以使得,正样本与原两个样本远离(因为是不同类),促使原两个样本类在训练过程中分离更快?

    • the majority of sample pairs are easy-to-contrast, which may induce negligible contrastive loss gradients that contribute little to
      learning discriminative representations.

    • 是否可以调整挑选样本指标,如正样本由三个相邻的不同类的样本合成,是否也可能促进三个类分离更快?

  • 由于负样本与anchor相似度较小(默认$\lambda >= 0.8$),与不同类相似度较高,由此处于类的边界地带

    • 加入正负样本可以使得训练过程中,缓和不同类之间的差异,使得决策边界更平滑。
1. Beliz Gunel, Jingfei Du, Alexis Conneau, and Ves Stoyanov. Supervised contrastive learning for pre-trained language model fine-tuning. In International Conference on Learning Representations, 2021.

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!