SupCL-Seq: Supervised Contrastive Learning for Downstream Optimized Sequence Representations

Hooman Sedghamiz, Shivam Raval, Enrico Santus, Tuka Alhanai, Mohammad M. GhassemiEMNLP 2021

Introduction

In computer vision, contrastive learning has significantly advanced representation learning by comparing different "views" of the same image. However, applying this to Natural Language Processing (NLP) is challenging because simple data augmentations, like rotation or cropping, can destroy a sentence's semantic meaning.

While self-supervised contrastive learning methods like SimCSE have emerged, they often ignore class labels during training. This leads to the "collision" problem, where the model may push apart representations of different sentences that actually belong to the same category. SupCL-Seq addresses this by integrating supervised contrastive learning into sequence classification, explicitly teaching the model to group samples by their downstream task labels.

Methodology

The SupCL-Seq pipeline introduces a novel approach to data augmentation and loss calculation in NLP:

  1. Dropout as Augmentation: Instead of external linguistic transformations, SupCL-Seq utilizes the internal dropout masks of Transformer architectures (e.g., BERT). By passing an input through the encoder multiple times with different dropout seeds, the model generates multiple "noisy" views of the same sequence.
  2. Supervised Contrastive Loss ($L_{sup}$): Unlike standard cross-entropy, which evaluates samples independently, this loss function considers the entire batch. For any "anchor" sentence, the model minimizes the distance to its own augmented views and all other samples sharing the same label, while maximizing the distance to samples with different labels.
  3. Two-Stage Training: The encoder is first optimized using the supervised contrastive loss. Subsequently, the encoder is frozen, and a linear classifier is trained on top using standard cross-entropy.
The SupCL-Seq architecture leverages internal dropout masks to create multiple views of an input, which are then used in a supervised contrastive learning framework.

Experimental Setup

The model was evaluated on the GLUE (General Language Understanding Evaluation) benchmark, covering a wide range of NLP tasks:

  • Linguistic Acceptability: CoLA
  • Paraphrase Detection: MRPC, QQP
  • Semantic Similarity: STS-B (treated as classification)
  • Natural Language Inference: MNLI, QNLI, RTE, WNLI
  • Sentiment Analysis: SST-2

Results and Discussion

SupCL-Seq demonstrates consistent performance gains over standard $BERT_{base}$ fine-tuning across the GLUE benchmark. Notable improvements include a +6.0% absolute increase in Matthews Correlation Coefficient for CoLA and a +5.4% increase in accuracy for MRPC.

SupCL-Seq outperforms standard BERT and dropout-augmented baselines across most GLUE tasks, highlighting the effectiveness of supervised contrastive loss.

Key Insights

  • Effectiveness of Internal Noise: Model-internal dropout serves as a highly effective augmentation strategy, removing the need for complex external tools.
  • Superiority of Supervision: SupCL-Seq significantly outperforms self-supervised contrastive methods. For example, on the RTE task, SupCL-Seq achieved 69.3% accuracy, compared to 55.6% for its self-supervised counterpart. This is particularly evident in tasks like CoLA, where semantic meaning alone is insufficient for classification.
  • Loss vs. Augmentation: Analysis confirms that the performance boost is primarily driven by the structure of the contrastive loss function rather than just the increased exposure to augmented data.

Conclusion

SupCL-Seq provides a robust framework for learning task-optimized sequence representations. While the method introduces some computational overhead due to multiple encoder passes and exhibits task-dependent hyperparameter sensitivity, it offers a clear path toward more discriminative embedding spaces. Future work may explore multi-task learning to satisfy multiple classification objectives within a single representation space.

Summary updated

BibTeX
@inproceedings{sedghamiz2021supcl,
  author = {Hooman Sedghamiz and Shivam Raval and Enrico Santus and Tuka Alhanai and Mohammad M. Ghassemi},
  title = {{SupCL-Seq: Supervised Contrastive Learning for Downstream Optimized Sequence Representations}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2021},
  doi = {10.18653/v1/2021.findings-emnlp.289},
}
Figure