---
language:
- en
tags:
- sentence-transformers
- cross-encoder
- text-classification
- generated_from_trainer
- dataset_size:942069
- loss:CrossEntropyLoss
base_model: distilbert/distilroberta-base
datasets:
- sentence-transformers/all-nli
pipeline_tag: text-classification
library_name: sentence-transformers
metrics:
- f1_macro
- f1_micro
- f1_weighted
co2_eq_emissions:
emissions: 5.804161792857238
energy_consumed: 0.01493216343846247
source: codecarbon
training_type: fine-tuning
on_cloud: false
cpu_model: 13th Gen Intel(R) Core(TM) i7-13700K
ram_total_size: 31.777088165283203
hours_used: 0.058
hardware_used: 1 x NVIDIA GeForce RTX 3090
model-index:
- name: CrossEncoder based on distilbert/distilroberta-base
results:
- task:
type: cross-encoder-classification
name: Cross Encoder Classification
dataset:
name: AllNLI dev
type: AllNLI-dev
metrics:
- type: f1_macro
value: 0.8495346395196971
name: F1 Macro
- type: f1_micro
value: 0.851
name: F1 Micro
- type: f1_weighted
value: 0.8494545162410544
name: F1 Weighted
- task:
type: cross-encoder-classification
name: Cross Encoder Classification
dataset:
name: AllNLI test
type: AllNLI-test
metrics:
- type: f1_macro
value: 0.7574494684363943
name: F1 Macro
- type: f1_micro
value: 0.7575803825803826
name: F1 Micro
- type: f1_weighted
value: 0.7582587136974347
name: F1 Weighted
---
# CrossEncoder based on distilbert/distilroberta-base
This is a [Cross Encoder](https://www.sbert.net/docs/cross_encoder/usage/usage.html) model finetuned from [distilbert/distilroberta-base](https://huggingface.co/distilbert/distilroberta-base) on the [all-nli](https://huggingface.co/datasets/sentence-transformers/all-nli) dataset using the [sentence-transformers](https://www.SBERT.net) library. It computes scores for pairs of texts, which can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
## Model Details
### Model Description
- **Model Type:** Cross Encoder
- **Base model:** [distilbert/distilroberta-base](https://huggingface.co/distilbert/distilroberta-base)
- **Maximum Sequence Length:** 514 tokens
- **Training Dataset:**
- [all-nli](https://huggingface.co/datasets/sentence-transformers/all-nli)
- **Language:** en
### Model Sources
- **Documentation:** [Sentence Transformers Documentation](https://sbert.net)
- **Documentation:** [Cross Encoder Documentation](https://www.sbert.net/docs/cross_encoder/usage/usage.html)
- **Repository:** [Sentence Transformers on GitHub](https://github.com/UKPLab/sentence-transformers)
- **Hugging Face:** [Cross Encoders on Hugging Face](https://huggingface.co/models?library=sentence-transformers&other=cross-encoder)
## Usage
### Direct Usage (Sentence Transformers)
First install the Sentence Transformers library:
```bash
pip install -U sentence-transformers
```
Then you can load this model and run inference.
```python
from sentence_transformers import CrossEncoder
# Download from the 🤗 Hub
model = CrossEncoder("tomaarsen/reranker-distilroberta-base-nli")
# Get scores for pairs...
pairs = [
['Two women are embracing while holding to go packages.', 'The sisters are hugging goodbye while holding to go packages after just eating lunch.'],
['Two women are embracing while holding to go packages.', 'Two woman are holding packages.'],
['Two women are embracing while holding to go packages.', 'The men are fighting outside a deli.'],
['Two young children in blue jerseys, one with the number 9 and one with the number 2 are standing on wooden steps in a bathroom and washing their hands in a sink.', 'Two kids in numbered jerseys wash their hands.'],
['Two young children in blue jerseys, one with the number 9 and one with the number 2 are standing on wooden steps in a bathroom and washing their hands in a sink.', 'Two kids at a ballgame wash their hands.'],
]
scores = model.predict(pairs)
print(scores.shape)
# [5]
# ... or rank different texts based on similarity to a single text
ranks = model.rank(
'Two women are embracing while holding to go packages.',
[
'The sisters are hugging goodbye while holding to go packages after just eating lunch.',
'Two woman are holding packages.',
'The men are fighting outside a deli.',
'Two kids in numbered jerseys wash their hands.',
'Two kids at a ballgame wash their hands.',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
```
## Evaluation
### Metrics
#### Cross Encoder Classification
* Datasets: `AllNLI-dev` and `AllNLI-test`
* Evaluated with [CEClassificationEvaluator
](https://sbert.net/docs/package_reference/cross_encoder/evaluation.html#sentence_transformers.cross_encoder.evaluation.CEClassificationEvaluator)
| Metric | AllNLI-dev | AllNLI-test |
|:-------------|:-----------|:------------|
| **f1_macro** | **0.8495** | **0.7574** |
| f1_micro | 0.851 | 0.7576 |
| f1_weighted | 0.8495 | 0.7583 |
## Training Details
### Training Dataset
#### all-nli
* Dataset: [all-nli](https://huggingface.co/datasets/sentence-transformers/all-nli) at [d482672](https://huggingface.co/datasets/sentence-transformers/all-nli/tree/d482672c8e74ce18da116f430137434ba2e52fab)
* Size: 942,069 training samples
* Columns: premise
, hypothesis
, and label
* Approximate statistics based on the first 1000 samples:
| | premise | hypothesis | label |
|:--------|:------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------|:-------------------------------------------------------------------|
| type | string | string | int |
| details |
A person on a horse jumps over a broken down airplane.
| A person is training his horse for a competition.
| 1
|
| A person on a horse jumps over a broken down airplane.
| A person is at a diner, ordering an omelette.
| 2
|
| A person on a horse jumps over a broken down airplane.
| A person is outdoors, on a horse.
| 0
|
* Loss: [CrossEntropyLoss
](https://sbert.net/docs/package_reference/cross_encoder/losses.html#crossentropyloss)
### Evaluation Dataset
#### all-nli
* Dataset: [all-nli](https://huggingface.co/datasets/sentence-transformers/all-nli) at [d482672](https://huggingface.co/datasets/sentence-transformers/all-nli/tree/d482672c8e74ce18da116f430137434ba2e52fab)
* Size: 19,657 evaluation samples
* Columns: premise
, hypothesis
, and label
* Approximate statistics based on the first 1000 samples:
| | premise | hypothesis | label |
|:--------|:------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------|:-------------------------------------------------------------------|
| type | string | string | int |
| details | Two women are embracing while holding to go packages.
| The sisters are hugging goodbye while holding to go packages after just eating lunch.
| 1
|
| Two women are embracing while holding to go packages.
| Two woman are holding packages.
| 0
|
| Two women are embracing while holding to go packages.
| The men are fighting outside a deli.
| 2
|
* Loss: [CrossEntropyLoss
](https://sbert.net/docs/package_reference/cross_encoder/losses.html#crossentropyloss)
### Training Hyperparameters
#### Non-Default Hyperparameters
- `eval_strategy`: steps
- `per_device_train_batch_size`: 64
- `per_device_eval_batch_size`: 64
- `num_train_epochs`: 1
- `warmup_ratio`: 0.1
- `bf16`: True
#### All Hyperparameters