Self-Supervised Document Similarity Ranking via Contextualized Language Models and Hierarchical Inference

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

TL;DR

This paper introduces SDR, a novel self-supervised method for ranking documents by semantic similarity, even for extremely long documents that exceed typical Transformer model limits. SDR leverages a hierarchical inference approach and a unique contrastive training objective to achieve state-of-the-art performance without requiring labeled similarity data.

What Problem Does This Paper Address?

Accurately determining the semantic similarity between documents is crucial for many applications, including information retrieval, recommendation systems, and question answering. While Transformer-based language models like BERT have revolutionized text understanding, they are fundamentally limited by their maximum input sequence length (e.g., 512 or 4096 tokens). This makes them ill-suited for comparing long documents, which are common in real-world scenarios. Existing methods for long documents often rely on specialized architectures or are limited by computational complexity. Furthermore, obtaining labeled similarity data for training is often impractical or impossible, making unsupervised approaches highly desirable.

Methods

SDR tackles the long-document similarity problem with a two-pronged approach:

  • Self-Supervised Training: SDR uses a RoBERTa backbone and employs a novel training objective that doesn't require external similarity labels. This objective consists of two parts:
  • Masked Language Model (MLM) Loss: This standard objective helps the model adapt to the specific domain of the documents.
  • Contrastive Loss: This is the core innovation. SDR samples sentence pairs from documents in two ways: "intra-samples" (from the same paragraph) and "inter-samples" (from different paragraphs/documents). The contrastive loss encourages intra-samples to have similar embeddings and inter-samples to have dissimilar embeddings, pushing them apart by a margin. This is crucial for learning meaningful semantic representations.
  • Hierarchical Inference: To handle long documents without exceeding token limits, SDR employs a two-stage hierarchical scoring mechanism:
  • Stage 1 (Sentence Similarity): Documents are broken down into paragraphs, and then into sentences. For each pair of paragraphs (one from the source, one from the candidate document), SDR computes a sentence-similarity matrix by comparing all sentence embeddings within those paragraphs.
  • Stage 2 (Paragraph Similarity & Aggregation): The sentence-similarity matrices are used to infer a paragraph-similarity matrix. This matrix is then globally normalized and aggregated to produce a single, cumulative similarity score between the source and candidate documents. This hierarchical approach avoids processing entire documents at once, making it scalable.

Datasets

The authors evaluated SDR on two custom datasets derived from Wikipedia:

  • Wikipedia Video Games (WVG): Contains articles about video games.
  • Wikipedia Wine Articles (WWA): Contains articles about wine.

For both datasets, they provide newly created, human-annotated test sets of ground-truth similarity labels. These datasets are made publicly available to facilitate future research.

Key Insights and Ideas

  • Self-supervision is key for unlabeled data: The ability to learn meaningful similarity representations without explicit labels is a major advantage for real-world applications.
  • Hierarchical inference is crucial for long documents: Breaking down the problem into sentence and paragraph levels allows for processing documents of arbitrary length, overcoming the limitations of standard Transformer architectures.
  • Contrastive loss for semantic orthogonality: The specific formulation of the contrastive loss, which encourages orthogonality rather than strict opposition for negative samples, proves more robust for real-world, often uncorrelated, sentence pairs.
  • Domain adaptation matters: Pre-training the language model on the specific corpus (as done in SDR's MLM loss) significantly improves performance compared to using off-the-shelf pre-trained models.

Key Results

  • State-of-the-art performance: SDR significantly outperforms baseline models (LDA, SBERT, Longformer) across all evaluated metrics (MPR, MRR, HR@10) on both the WVG and WWA datasets.
  • Substantial improvements: SDR shows absolute improvements of ~7-12% in MPR and ~11-13% in MRR compared to the best variants of other models.
  • SDR inference boosts baselines: Applying SDR's hierarchical inference method to other models (like BERT and Longformer) also leads to significant performance gains, highlighting the effectiveness of the inference strategy.
  • Qualitative success: SDR correctly identifies semantically similar documents, such as "Grand Theft Auto V" and "Mafia III," or "Sparkling wine" and "Champagne," while baselines like SBERT often fail to grasp the underlying topic.

Limitations and Future Work

  • Computational cost of training: While inference is efficient, the self-supervised training process for SDR might still be computationally intensive, especially for very large corpora.
  • Potential for further optimization: The paper suggests that future work could explore more advanced hierarchical structures or different self-supervised objectives.
  • Ablation study highlights importance: The ablation study clearly shows that each component of SDR (hierarchical inference, contrastive loss, global normalization, and domain-specific training) contributes significantly to its overall performance. The removal of hierarchical inference or the contrastive loss leads to the most substantial performance degradation.

Summary updated

BibTeX
@inproceedings{ginzburg2021self,
  author = {Dvir Ginzburg and Itzik Malkiel and Oren Barkan and Avi Caciularu and Noam Koenigstein},
  title = {{Self-Supervised Document Similarity Ranking via Contextualized Language Models and Hierarchical Inference}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2021},
  url = {https://openreview.net/forum?id=C5WDOlFj6eZ},
}
Figure