[Paper Review] Sentence Embeddings using Supervised Contrastive Learning
This paper proposes a supervised contrastive learning approach to improve sentence embeddings by fine-tuning BERT on SNLI data using both cross-entropy and contrastive loss. The method achieves state-of-the-art performance, improving average STS benchmark scores by 2.8% and transfer task performance by 1.05% over SBERT, with only a 16-minute training overhead.
Sentence embeddings encode sentences in fixed dense vectors and have played an important role in various NLP tasks and systems. Methods for building sentence embeddings include unsupervised learning such as Quick-Thoughts and supervised learning such as InferSent. With the success of pretrained NLP models, recent research shows that fine-tuning pretrained BERT on SNLI and Multi-NLI data creates state-of-the-art sentence embeddings, outperforming previous sentence embeddings methods on various evaluation benchmarks. In this paper, we propose a new method to build sentence embeddings by doing supervised contrastive learning. Specifically our method fine-tunes pretrained BERT on SNLI data, incorporating both supervised crossentropy loss and supervised contrastive loss. Compared with baseline where fine-tuning is only done with supervised cross-entropy loss similar to current state-of-the-art method SBERT, our supervised contrastive method improves 2.8% in average on Semantic Textual Similarity (STS) benchmarks and 1.05% in average on various sentence transfer tasks.
Motivation & Objective
- To improve sentence embedding quality by leveraging label information in supervised contrastive learning.
- To investigate whether combining cross-entropy and contrastive loss during fine-tuning enhances semantic representation learning.
- To evaluate the effectiveness of supervised contrastive learning on sentence-level transfer tasks and unsupervised STS benchmarks.
- To analyze hyperparameter sensitivity (lambda, temperature, positive/negative sampling) in the contrastive objective.
- To demonstrate computational efficiency of the proposed method compared to existing fine-tuning baselines.
Proposed method
- Fine-tunes BERT on SNLI data using a dual objective: standard cross-entropy loss and supervised contrastive loss.
- Uses tied weights across two BERT encoders to compute sentence embeddings for anchor, positive, and negative sentence pairs.
- Applies a contrastive loss that pulls positive sentence embeddings closer and pushes negative ones apart in the embedding space.
- Employs a temperature-scaled softmax to compute the contrastive loss, with hyperparameter tuning on temperature τ.
- Uses a weighted combination of cross-entropy and contrastive loss, with hyperparameter λ controlling the balance between the two objectives.
- Samples all available positive and negative sentences per anchor from the SNLI training batch to maximize contrastive signal.
Experimental results
Research questions
- RQ1Does incorporating supervised contrastive learning during BERT fine-tuning improve sentence embedding quality on STS benchmarks?
- RQ2How does the performance of the proposed method compare to SBERT, which uses only cross-entropy loss?
- RQ3What is the impact of hyperparameters λ (loss weight), τ (temperature), and N+ / N− (number of positive/negative samples) on model performance?
- RQ4Does supervised contrastive learning provide consistent gains across both unsupervised (STS) and supervised (SentEval) transfer tasks?
- RQ5Is the proposed method computationally efficient compared to standard fine-tuning baselines?
Key findings
- The proposed method improves average performance on the STS benchmark by 2.8% compared to the SBERT baseline.
- On various sentence transfer tasks, the method achieves a 1.05% improvement in average accuracy over the SBERT baseline.
- The best model configuration uses λ = 0.1 for SentEval tasks and λ = 0.3 for STS tasks, indicating optimal loss weighting varies by evaluation task.
- Temperature τ = 1.0 yields the best performance on both STS and SentEval tasks, suggesting a balance between hard and soft negatives.
- Using all available positive and negative samples (N+ = all, N− = all) per anchor yields the highest performance, with a drop in performance when using only contrastive loss (λ = 1.0).
- The method is computationally efficient, requiring only 36 minutes to train the best model—16 minutes more than the SBERT baseline.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.