opensi·si

This folder contains a script that demonstrate how to train Sparse Encoders for Information Retrieval. As a simple example, we will use the Quora Duplicate Questions dataset.…

Quora Duplicate Questions

This folder contains a script that demonstrate how to train Sparse Encoders for Information Retrieval. As a simple example, we will use the Quora Duplicate Questions dataset. It contains over 500,000 sentences with over 400,000 pairwise annotations whether two questions are a duplicate or not.

Models trained on this dataset can be used for mining duplicate questions, i.e., given a large set of sentences (in this case questions), identify all pairs that are duplicates using sparse vector similarity.

Training

For the complete example, see training_splade_quora.py that leverage the loss to train a splade model on this dataset.

Using the loss is easy and does not require tuning of any hyperparameters:

from datasets import load_dataset
from sentence_transformers.sparse_encoder.losses import SparseMultipleNegativesRankingLoss, SpladeLoss
# Assume 'model' is your SparseEncoder model

full_dataset = load_dataset("sentence-transformers/quora-duplicates", "triplet", split="train").select(
    range(100000)
)
dataset_dict = full_dataset.train_test_split(test_size=1_000, seed=12)
train_dataset = dataset_dict["train"]
eval_dataset = dataset_dict["test"]
# => Dataset({
#     features: ['anchor', 'positive', 'negative],
#     num_rows: 99000
# })

loss = SpladeLoss(
    model=model,
    loss=SparseMultipleNegativesRankingLoss(model=model),
    query_regularizer_weight=query_regularizer_weight,  # Weight for query loss
    document_regularizer_weight=document_regularizer_weight,  # Weight for document loss
)

Source and license

Source: Sentence Transformers documentation, adapted for this site. Licensing and attribution follow the terms of the upstream project.