Metricbert: Text Representation Learning Via Self-Supervised Triplet Training

Itzik Malkiel, Dvir Ginzburg, Oren Barkan, Avi Caciularu, Yoni Weill, Noam Koenigstein

TL;DR

This paper introduces MetricBERT, a novel BERT-based model that learns text embeddings optimized for similarity tasks by jointly training a masked language model with a self-supervised triplet loss. MetricBERT significantly outperforms existing methods on recommendation tasks, demonstrating the effectiveness of its metric learning approach and a new angular distance metric.

What Problem Does This Paper Address?

Learning to represent text in a way that accurately captures semantic similarity is a fundamental challenge with applications ranging from information retrieval to recommender systems. While pre-trained language models like BERT have revolutionized NLP, directly applying them to similarity tasks often requires fine-tuning, which can be data-intensive. Existing methods for learning text similarity embeddings, such as contrastive learning or cosine similarity, have limitations. Specifically, cosine similarity can lead to "collapse" where all embeddings become too similar, and contrastive losses might not be as effective as triplet-based approaches for fine-grained similarity. This paper aims to develop a self-supervised method that learns robust text embeddings for similarity tasks, particularly for recommender systems, without requiring explicit similarity labels.

Methods

MetricBERT builds upon the BERT architecture but introduces a novel training objective. It jointly optimizes two tasks:

  1. Masked Language Modeling (MLM): This is the standard pre-training task for BERT, where the model predicts masked tokens in a sequence. This helps maintain the model's general language understanding capabilities.
  2. Self-Supervised Triplet Loss: This is the core innovation. The model is trained on triplets of textual elements: an anchor, a positive sample (similar to the anchor), and a negative sample (dissimilar to the anchor). The goal is to pull the anchor and positive embeddings closer together in the embedding space while pushing the anchor and negative embeddings further apart.

A key aspect of the triplet loss is the use of an angular distance instead of the more common cosine similarity. The authors found that optimizing angular distance, which is sensitive to micro-differences in angles between vectors, leads to better convergence and performance compared to cosine similarity, which can cause embeddings to collapse.

Additionally, MetricBERT employs a hard negative mining strategy. Within each batch, the model identifies the most challenging negative sample for each anchor-positive pair (i.e., the negative sample that is closest to the anchor). This focuses the training on the most informative examples, accelerating convergence and improving performance.

For inference, MetricBERT uses a novel MetricInf approach that separately pools token embeddings for each text element and then computes the angular distance between these pooled embeddings.

Datasets

The paper evaluates MetricBERT on two datasets:

  • Wines Dataset: A publicly available dataset containing wine descriptions and professional sommelier annotations for similarity.
  • Video Games Dataset: A newly introduced dataset consisting of video game descriptions (specifically, the "Gameplay" sections) extracted from Wikipedia. The authors also provide a test set of similarity annotations for this dataset, crafted by a domain expert.

Key Insights and Ideas

  • Triplet Loss is Superior to Contrastive Loss for Similarity: The paper strongly suggests that a triplet-based metric learning objective is more beneficial for learning text similarity than traditional contrastive losses, especially in scenarios where explicit similarity labels are scarce.
  • Angular Distance is Crucial: Optimizing for angular distance, rather than cosine similarity, is critical for preventing embedding collapse and achieving better model convergence and performance on similarity tasks.
  • Hard Negative Mining Accelerates Learning: Focusing training on the most difficult negative examples significantly improves the efficiency and effectiveness of the triplet loss.
  • Joint Training is Key: Combining the traditional MLM objective with the metric learning loss allows MetricBERT to retain strong language understanding while excelling at similarity tasks.
  • Novel Inference Method Improves Baselines: The proposed MetricInf inference method, which uses angular distance on pooled embeddings, even improves the performance of other pre-trained models when applied.

Key Results

MetricBERT consistently outperforms a range of baselines, including LDA, TF-IDF, BERT (with mean pooling), RoBERTa (with mean pooling), RecoBERT, and SBERT, on both the video games and wines recommendation tasks.

  • Significant Margins: On the wines dataset, MetricBERT improves MPR by 2.2, MRR by 3.6, and HR@10 by 9.3 compared to the best performing model.
  • Outperforming State-of-the-Art: MetricBERT achieves the highest scores across all evaluated metrics (MPR, MRR, HR@10, HR@100) on both datasets. For example, on the video games dataset, MetricBERT achieves an MPR of 89.1% and MRR of 25.0%, while on the wines dataset, it reaches an MPR of 98.5% and MRR of 95.3%.
  • Impact of Training Strategy: The results highlight that MetricBERT's training strategy, particularly the triplet loss and angular distance, is the primary driver of its superior performance compared to models like BERT and RoBERTa that only use mean pooling.
  • Ablation Study Findings: The ablation study confirms the importance of the triplet loss, angular distance, and hard negative mining. Replacing these with contrastive loss, cosine similarity, or random mining leads to substantial performance drops.

Limitations and Future Work

  • Domain Specificity: While MetricBERT is presented as a general model, its primary evaluation is on recommendation tasks. Its performance on other similarity-related tasks (e.g., document clustering, essay scoring) is not extensively explored.
  • Hyperparameter Tuning: The paper mentions setting $\lambda = 1$ for the balancing hyper-parameter between MLM and triplet loss. Further exploration of optimal hyperparameter settings for different tasks and datasets could be beneficial.
  • Dataset Contribution: The authors contribute a new dataset for video game similarity, which is valuable for future research.

The paper suggests that MetricBERT's architecture and training methodology can be applied to other text similarity and information retrieval tasks, opening avenues for future work in these areas.

Summary updated

BibTeX
@inproceedings{malkiel2022metricbert,
  author = {Itzik Malkiel and Dvir Ginzburg and Oren Barkan and Avi Caciularu and Yoni Weill and Noam Koenigstein},
  title = {{Metricbert: Text Representation Learning Via Self-Supervised Triplet Training}},
  booktitle = {IEEE International Conference on Acoustics, Speech and Signal Processing},
  year = {2022},
  url = {https://openreview.net/forum?id=a-oEnPV1gR},
}
Figure