CMLM-CSE: Based on Conditional MLM Contrastive Learning for Sentence Embeddings

Wei Zhang, Xu Chen · DOI

Abstract

Traditional comparative learning sentence embedding directly uses the encoder to extract sentence features, and then passes in the comparative loss function for learning. However, this method pays too much attention to the sentence body and ignores the influence of some words in the sentence on the sentence semantics. To this end, we propose CMLM-CSE, an unsupervised contrastive learning framework based on conditional MLM. On the basis of traditional contrastive learning, an additional auxiliary network is added to integrate sentence embedding to perform MLM tasks, forcing sentence embedding to learn more masked word information. Finally, when Bertbase was used as the pretraining language model, we exceeded SimCSE by 0.55 percentage points on average in textual similarity tasks, and when Robertabase was used as the pretraining language model, we exceeded SimCSE by 0.3 percentage points on average in textual similarity tasks.

Introduction

In Natural Language Processing (NLP), sentence embeddings are critical for representing the semantic meaning of text in a vector space. Unsupervised contrastive learning, exemplified by SimCSE, has become a dominant approach. SimCSE uses dropout as a minimal data augmentation to create positive pairs, pulling their representations together while pushing away other sentences. However, the authors argue that this "global" focus overlooks "local" semantic awareness—the specific contribution of individual words to the overall sentence meaning. CMLM-CSE addresses this by introducing a conditional Masked Language Model (MLM) task as an auxiliary objective.

Methodology

The CMLM-CSE framework consists of two primary components: a standard contrastive learning branch and an auxiliary conditional MLM branch.

The CMLM-CSE architecture featuring the dual-branch approach: contrastive learning and conditional MLM.

1. Contrastive Branch

Following the SimCSE paradigm, a sentence $x$ is encoded twice with different dropout masks to generate a positive pair. The model is trained to maximize the similarity between these two representations while minimizing similarity with other sentences in the same batch.

2. Conditional MLM Branch

This branch forces the sentence embedding to capture fine-grained lexical information:

  • Lexical Feature Extractor: A masked version of the sentence $x'$ is processed through the first 8 layers of a frozen BERT model to extract low-level lexical features.
  • Semantic Feature Fusioner: The "global" sentence embedding from the main encoder is concatenated with the "local" features from the frozen extractor.
  • The Task: A fusioner composed of 3 Transformer blocks must reconstruct the masked words. This task is "conditional" because the reconstruction relies on the context provided by the global sentence embedding, forcing it to be more informative about the sentence's internal structure.

Experimental Results

The model was trained on 1 million random English sentences from Wikipedia and evaluated on seven Semantic Textual Similarity (STS) benchmarks.

Comparison of CMLM-CSE against state-of-the-art models on STS benchmarks.

CMLM-CSE consistently outperforms SimCSE and other strong baselines like DiffCSE. Using BERT-base, CMLM-CSE achieved an average STS score of 76.80, a 0.55% improvement over SimCSE. With RoBERTa-base, it reached 76.87, surpassing SimCSE by 0.3%.

Ablation Study

Ablation experiments highlighted the importance of the dual-objective approach. Removing the MLM task (leaving only contrastive loss) resulted in a significant performance drop on the STS-B validation set (from 83.76 to 81.26), confirming that word-level reconstruction is vital for high-quality embeddings. Additionally, the authors found that a high masking rate (40%) and a small weight for the MLM loss ($\lambda = 0.005$) were optimal for balancing the two tasks.

Conclusion

CMLM-CSE successfully bridges the gap between global semantic alignment and local word-level awareness in unsupervised sentence embeddings. By conditioning an MLM task on the global sentence vector, the model learns a more robust and detailed representation of text. While the auxiliary network adds training complexity, it is discarded during inference, maintaining the efficiency required for real-world applications.

Summary updated

BibTeX
@misc{zhang2023cmlm,
  author = {Wei Zhang and Xu Chen},
  title = {{CMLM-CSE: Based on Conditional MLM Contrastive Learning for Sentence Embeddings}},
  year = {2023},
  eprint = {2306.09594},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2306.09594},
}
Figure