DeCLUTR: Deep Contrastive Learning for Unsupervised Textual Representations

John M. Giorgi, Osvald Nitski, Gary D. Bader, Bo Wang

TL;DR

This paper introduces DeCLUTR, a novel self-supervised method for learning universal sentence embeddings without requiring labeled data. By extending pre-trained transformer models with a contrastive learning objective, DeCLUTR significantly narrows the performance gap between supervised and unsupervised sentence embedding approaches, demonstrating that high-quality embeddings can be learned from vast amounts of unlabeled text.

What Problem Does This Paper Address?

The effectiveness of Natural Language Processing (NLP) systems heavily relies on good sentence embeddings – numerical representations of sentences that capture their meaning. While word embeddings have been successful, state-of-the-art sentence embeddings often require large amounts of labeled data for training. This creates a significant bottleneck, as such data is scarce for many languages and domains. The paper aims to bridge this gap by developing a method that can learn high-quality, universal sentence embeddings using only unlabeled text, making them more accessible and broadly applicable.

Methods

DeCLUTR builds upon recent advances in deep metric learning (DML) and contrastive learning. The core idea is to train a sentence encoder to map semantically similar sentences closer together in an embedding space and dissimilar sentences further apart. Specifically, the method uses a self-supervised objective where "positive" pairs of text spans are sampled from nearby within the same document, while "negative" pairs are sampled from different documents or are otherwise dissimilar.

The process involves:

  1. Span Sampling: Randomly sampling text spans (from sentence to paragraph length) from documents. Anchor spans are paired with positive spans that are adjacent, overlapping, or subsumed by the anchor.
  2. Encoder and Pooler: A transformer-based language model acts as the encoder, mapping tokens to embeddings. A pooling function (mean pooling is found to be effective) then generates a fixed-length sentence embedding.
  3. Contrastive Loss: A contrastive prediction task is used to minimize the distance between anchor and positive embeddings while maximizing the distance to negative embeddings within a minibatch.
  4. Continued Pretraining: This contrastive objective is used to further pre-train existing transformer models (like RoBERTa and DistilRoBERTa) that have already been trained with a masked language modeling (MLM) objective. This combination of MLM and contrastive learning is key to DeCLUTR's success.

Datasets

  • Training: The primary training dataset used is OpenWebText, a large, open-access subset of the WebText corpus, containing approximately 497,868 documents with a minimum token length of 2048.
  • Evaluation: The SentEval benchmark is used for evaluation. This benchmark comprises 28 downstream tasks (e.g., sentiment analysis, natural language inference, paraphrase detection) and 10 probing tasks designed to assess linguistic properties encoded in sentence representations.

Key Insights and Ideas

  • Self-supervision is powerful: The paper strongly suggests that carefully designed self-supervised objectives can rival or even surpass supervised methods for learning universal sentence embeddings, especially when leveraging large unlabeled corpora.
  • MLM + Contrastive Learning is a winning combination: Combining the standard masked language modeling (MLM) pretraining with the proposed contrastive learning objective leads to significantly better sentence embeddings than using either alone. The MLM loss appears to act as a regularizer, preventing catastrophic forgetting of the transformer's initial capabilities.
  • Scaling matters: The quality of learned embeddings scales with both the size of the model (more parameters) and the amount of training data. This is a crucial insight for future improvements, as collecting more unlabeled text is often more feasible than acquiring more labeled data.
  • Sampling strategy is important: The way positive and negative spans are sampled significantly impacts performance. Allowing for overlapping, adjacent, and subsumed positive spans, and using multiple anchors per document to generate hard negatives, are key to the method's effectiveness.

Key Results

  • DeCLUTR-small (based on DistilRoBERTa) and DeCLUTR-base (based on RoBERTa-base) achieved significant improvements over their base models on the SentEval benchmark, with average downstream performance boosts of +4% and +6%, respectively.
  • DeCLUTR-base matched or outperformed existing state-of-the-art unsupervised and supervised methods on many downstream tasks, demonstrating its ability to close the performance gap.
  • DeCLUTR-small outperformed Sentence Transformers (a strong baseline) while using approximately 34% fewer trainable parameters.
  • The method showed strong performance on probing tasks, suggesting that the learned embeddings retain important linguistic information, unlike some fine-tuned models that might discard this during supervised training.

Limitations and Future Work

  • GPU Memory Constraints: The paper notes that experiments with a higher number of positive spans (P=4) for DeCLUTR-base were omitted due to GPU memory limitations.
  • Future Work: The authors explicitly state their intention to release their code and pretrained models, encouraging adaptation to new domains and non-English languages. They also suggest that further improvements can be achieved by simply scaling up the model size and training data. The paper also hints at the potential for DeCLUTR to be extended to other modalities beyond text.

Summary updated

BibTeX
@inproceedings{giorgi2021declutr,
  author = {John M. Giorgi and Osvald Nitski and Gary D. Bader and Bo Wang},
  title = {{DeCLUTR: Deep Contrastive Learning for Unsupervised Textual Representations}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2021},
  doi = {10.18653/v1/2021.acl-long.72},
}
Figure