Given two sentence (premise and hypothesis), Natural Language Inference (NLI) is the task of deciding if the premise entails the hypothesis, if they are contradiction, or if…
Natural Language Inference
Given two sentence (premise and hypothesis), Natural Language Inference (NLI) is the task of deciding if the premise entails the hypothesis, if they are contradiction, or if they are neutral. Commonly used NLI dataset are SNLI and MultiNLI.
Conneau et al. showed that NLI data can be quite useful when training Sentence Embedding methods. We also found this in our Sentence-BERT-Paper and often use NLI as a first fine-tuning step for sparse encoder methods.
To train on NLI, see the following example file:
- train_splade_nli.py:
Data
We combine SNLI and MultiNLI into a dataset we call AllNLI. These two datasets contain sentence pairs and one of three labels: entailment, neutral, contradiction:
| Sentence A (Premise) | Sentence B (Hypothesis) | Label |
|---|---|---|
| A soccer game with multiple males playing. | Some men are playing a sport. | entailment |
| An older and younger man smiling. | Two men are smiling and laughing at the cats playing on the floor. | neutral |
| A man inspects the uniform of a figure in some East Asian country. | The man is sleeping. | contradiction |
We format AllNLI in a few different subsets, compatible with different loss functions. For the train_splade_nli.py script, the data is typically processed into (anchor, positive) pairs for the ranking loss component. For example, entailment pairs from NLI can serve as (anchor, positive) pairs.
SpladeLoss
Ranking Component: SparseMultipleNegativesRankingLoss
The underlying ranking loss operates on sentence pairs [(a1, b1), ..., (an, bn)] where (ai, bi) are similar sentences (e.g., premise and its entailed hypothesis) and (ai, bj) for i != j are treated as dissimilar sentences (in-batch negatives). The loss minimizes the distance (or maximizes similarity) between (ai, bi) while simultaneously maximizing the distance (or minimizing similarity) between (ai, bj) for all i != j.
Using this with NLI data means defining entailment pairs as positive pairs. For example, ("A soccer game with multiple males playing.", "Some men are playing a sport.") should be close in the sparse vector space.
Sparsity Regularization
A key part of SpladeLoss is the regularization (e.g., FLOPS regularization via document_regularizer_weight) applied to the term weights in the sparse output vectors. This encourages the model to select only the most important terms for representation, leading to very sparse vectors, which is beneficial for efficient retrieval.
Source and license
Source: Sentence Transformers documentation, adapted for this site. Licensing and attribution follow the terms of the upstream project.