---
language:
- en
tags:
- sentence-transformers
- cross-encoder
- text-classification
- generated_from_trainer
- dataset_size:5749
- loss:BinaryCrossEntropyLoss
base_model: distilbert/distilroberta-base
datasets:
- sentence-transformers/stsb
pipeline_tag: text-classification
library_name: sentence-transformers
metrics:
- pearson
- spearman
co2_eq_emissions:
emissions: 2.6550346776830636
energy_consumed: 0.006830514578476734
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.031
hardware_used: 1 x NVIDIA GeForce RTX 3090
model-index:
- name: CrossEncoder based on distilbert/distilroberta-base
results:
- task:
type: cross-encoder-correlation
name: Cross Encoder Correlation
dataset:
name: stsb validation
type: stsb-validation
metrics:
- type: pearson
value: 0.877295960646044
name: Pearson
- type: spearman
value: 0.8754151440157509
name: Spearman
- task:
type: cross-encoder-correlation
name: Cross Encoder Correlation
dataset:
name: stsb test
type: stsb-test
metrics:
- type: pearson
value: 0.8503341584157813
name: Pearson
- type: spearman
value: 0.8388642249054395
name: Spearman
---
# 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 [stsb](https://huggingface.co/datasets/sentence-transformers/stsb) 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:**
- [stsb](https://huggingface.co/datasets/sentence-transformers/stsb)
- **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-stsb")
# Get scores for pairs...
pairs = [
['A man with a hard hat is dancing.', 'A man wearing a hard hat is dancing.'],
['A young child is riding a horse.', 'A child is riding a horse.'],
['A man is feeding a mouse to a snake.', 'The man is feeding a mouse to the snake.'],
['A woman is playing the guitar.', 'A man is playing guitar.'],
['A woman is playing the flute.', 'A man is playing a flute.'],
]
scores = model.predict(pairs)
print(scores.shape)
# [5]
# ... or rank different texts based on similarity to a single text
ranks = model.rank(
'A man with a hard hat is dancing.',
[
'A man wearing a hard hat is dancing.',
'A child is riding a horse.',
'The man is feeding a mouse to the snake.',
'A man is playing guitar.',
'A man is playing a flute.',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
```
## Evaluation
### Metrics
#### Cross Encoder Correlation
* Datasets: `stsb-validation` and `stsb-test`
* Evaluated with [CECorrelationEvaluator
](https://sbert.net/docs/package_reference/cross_encoder/evaluation.html#sentence_transformers.cross_encoder.evaluation.CECorrelationEvaluator)
| Metric | stsb-validation | stsb-test |
|:-------------|:----------------|:-----------|
| pearson | 0.8773 | 0.8503 |
| **spearman** | **0.8754** | **0.8389** |
## Training Details
### Training Dataset
#### stsb
* Dataset: [stsb](https://huggingface.co/datasets/sentence-transformers/stsb) at [ab7a5ac](https://huggingface.co/datasets/sentence-transformers/stsb/tree/ab7a5ac0e35aa22088bdcf23e7fd99b220e53308)
* Size: 5,749 training samples
* Columns: sentence1
, sentence2
, and score
* Approximate statistics based on the first 1000 samples:
| | sentence1 | sentence2 | score |
|:--------|:------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------|:---------------------------------------------------------------|
| type | string | string | float |
| details |
A plane is taking off.
| An air plane is taking off.
| 1.0
|
| A man is playing a large flute.
| A man is playing a flute.
| 0.76
|
| A man is spreading shreded cheese on a pizza.
| A man is spreading shredded cheese on an uncooked pizza.
| 0.76
|
* Loss: [BinaryCrossEntropyLoss
](https://sbert.net/docs/package_reference/sentence_transformer/losses.html#binarycrossentropyloss)
### Evaluation Dataset
#### stsb
* Dataset: [stsb](https://huggingface.co/datasets/sentence-transformers/stsb) at [ab7a5ac](https://huggingface.co/datasets/sentence-transformers/stsb/tree/ab7a5ac0e35aa22088bdcf23e7fd99b220e53308)
* Size: 1,500 evaluation samples
* Columns: sentence1
, sentence2
, and score
* Approximate statistics based on the first 1000 samples:
| | sentence1 | sentence2 | score |
|:--------|:------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------|:---------------------------------------------------------------|
| type | string | string | float |
| details | A man with a hard hat is dancing.
| A man wearing a hard hat is dancing.
| 1.0
|
| A young child is riding a horse.
| A child is riding a horse.
| 0.95
|
| A man is feeding a mouse to a snake.
| The man is feeding a mouse to the snake.
| 1.0
|
* Loss: [BinaryCrossEntropyLoss
](https://sbert.net/docs/package_reference/sentence_transformer/losses.html#binarycrossentropyloss)
### Training Hyperparameters
#### Non-Default Hyperparameters
- `eval_strategy`: steps
- `per_device_train_batch_size`: 64
- `per_device_eval_batch_size`: 64
- `num_train_epochs`: 4
- `warmup_ratio`: 0.1
- `bf16`: True
#### All Hyperparameters