SimCSE: Simple Contrastive Learning of Sentence Embeddings

SimCSE

论文目的

SimCSE:simple contrastive sentence embedding framework
首先提出一种无监督的方法,仅使用dropout作为噪声,进行对比训练。与有监督的方法效果类似,dropout充当了最小的数据增强的方法,删除它模型会崩溃。
然后提出一种有监督的方法,使用自然语言推理(NLI)中的蕴含作为正对、矛盾作为负例,在STS任务上评估SimCSE,在无监督和有监督的任务上都有提升。
还在理论和试验上证明了对比学习目标将预训练嵌入的各向异性空间正则化,使其更加均匀。

相关工作

Contrastive Learning

L i = − log ⁡ exp ⁡ ( s i m ( h i , h i + / τ ) ) ∑ j = 1 N s i m ( h i , h j + / τ ) ) L_i=-\log\frac{\exp(sim(h_i,h^+_i/\tau))}{\sum_{j=1}^Nsim(h_i,h^+_j/\tau))} Li=logj=1Nsim(hi,hj+/τ))exp(sim(hi,hi+/τ))
如何构建正例呢?cv中cropping, flipping, distortion and rotation,NLP中 word
deletion, reordering, and substitution
评价指标:Alignment and uniformity
l a l i g n = E ( x , x + ) − P p o s ∣ f ( x ) − f ( x + ) ∣ 2 l_{align}=E_{(x,x^+)-P_{pos}}|f(x)-f(x^+)|^2 lalign=E(x,x+)Pposf(x)f(x+)2
l u n i f o r m = log ⁡ E ( x , y ) − P d a t a e − 2 ∣ f ( x ) − f ( y ) ∣ 2 l_{uniform}=\log E_{(x,y)-P_{data}}e^{-2|f(x)-f(y)|^2} luniform=logE(x,y)Pdatae2f(x)f(y)2

Unsupervised SimCSE

SimCSE: Simple Contrastive Learning of Sentence Embeddings_第1张图片

transformers中的全连接层带有dropout,我们的方法很简单,将同一批样本输入encoder两次,因为两次的dropout mask z不一致,得到 h z h^z hz h z ′ h^{z^{'}} hz
计算loss得 L i = − log ⁡ exp ⁡ ( s i m ( h i z , h i z ′ / τ ) ) ∑ j = 1 N s i m ( h i z , h j z ′ / τ ) ) L_i=-\log\frac{\exp(sim(h_i^z,h^{z^{'}}_i/\tau))}{\sum_{j=1}^Nsim(h_i^z,h^{z^{'}}_j/\tau))} Li=logj=1Nsim(hiz,hjz/τ))exp(sim(hiz,hiz/τ))
SimCSE: Simple Contrastive Learning of Sentence Embeddings_第2张图片
试验对比了一个encoder和两个encoder,一个encoder的效果领先
试验对比了不同的dropout概率,p=0.1时效果最好
试验对比了不同情况下Alignment and uniformity的变化情况,dropout这种方式会在保持alignment的情况下下降uniformity

Supervised SimCSE

之前的工作已表明有监督的NLI数据集能获得更好的表征空间,本文中直接从数据中获取正样本对来优化损失函数
数据集:QQP4:Quora question pairs;
Flickr30k: each image is annotated with 5 human-written captions and we consider any two captions of the same image as a positive pair;
ParaNMT: a large-scale back-translation paraphrase dataset5;
NLI datasets: SNLI and MNLI.
使用不同的有监督数据进行训练后的结果,sample是为了公平对比,均随机选取了134k的数据进行训练。最终效果最好的是SNLI+MNLI,达到了84.9,而且在同时加入正负样本后达到了86.2,猜测是SNLI+MNLI质量比较高,词汇的重叠率较低(39%)
SimCSE: Simple Contrastive Learning of Sentence Embeddings_第3张图片

Contradiction as hard negatives

SimCSE: Simple Contrastive Learning of Sentence Embeddings_第4张图片

Experiment

试验对比了有监督的和无监督的在STS-B上的结果,试验做的很详细,可详看论文
重点说明所有的试验都是在无监督的方式上做的,即使是有监督,也是和前面的工作一样使用了额外的有监督数据。
数据集:STS 2012–2016 ( 2012, 2013, 2014, 2015, 2016), STS Benchmark and SICKRelatedness
BERT(uncased)或roberta(cased)
SimCSE: Simple Contrastive Learning of Sentence Embeddings_第5张图片
还对比了pooling策略、Hard negatives策略
还对比了Uniformity and alignment、Qualitative comparison

附录

阅读感官

很震惊啊,简单的方法有大大的效果。就像论文作者说的:简单的对比学习框架,后续还有RDropout和这篇论文类似,而且后续也有一些改进工作,比如ESimCSE,有兴趣的可以一起看看。

你可能感兴趣的:(nlp,自然语言处理,深度学习,机器学习)