---
language:
- en
tags:
- sentence-transformers
- cross-encoder
- reranker
- generated_from_trainer
- dataset_size:5749
- loss:BinaryCrossEntropyLoss
base_model: distilbert/distilroberta-base
datasets:
- sentence-transformers/stsb
pipeline_tag: text-ranking
library_name: sentence-transformers
metrics:
- pearson
- spearman
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.8864227817727027
name: Pearson
- type: spearman
value: 0.8837678149208236
name: Spearman
- task:
type: cross-encoder-correlation
name: Cross Encoder Correlation
dataset:
name: stsb test
type: stsb-test
metrics:
- type: pearson
value: 0.8503521391700528
name: Pearson
- type: spearman
value: 0.8403655772346184
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 text reranking and semantic search.
## Model Details
### Model Description
- **Model Type:** Cross Encoder
- **Base model:** [distilbert/distilroberta-base](https://huggingface.co/distilbert/distilroberta-base)
- **Maximum Sequence Length:** 512 tokens
- **Number of Output Labels:** 1 label
- **Supported Modality:** Text
- **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/huggingface/sentence-transformers)
- **Hugging Face:** [Cross Encoders on Hugging Face](https://huggingface.co/models?library=sentence-transformers&other=cross-encoder)
### Full Model Architecture
```
CrossEncoder(
(0): Transformer({'transformer_task': 'sequence-classification', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'logits'}}, 'module_output_name': 'scores', 'architecture': 'RobertaForSequenceClassification'})
)
```
## 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("omkar334/reranker-distilroberta-base-stsb")
# Get scores for pairs of inputs
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)
# [0.9598 0.9533 0.9566 0.3766 0.4535]
# 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 [CrossEncoderCorrelationEvaluator](https://sbert.net/docs/package_reference/cross_encoder/evaluation.html#sentence_transformers.cross_encoder.evaluation.CrossEncoderCorrelationEvaluator)
| Metric | stsb-validation | stsb-test |
|:-------------|:----------------|:-----------|
| pearson | 0.8864 | 0.8504 |
| **spearman** | **0.8838** | **0.8404** |
## 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 100 samples:
| | sentence1 | sentence2 | score |
|:---------|:---------------------------------------------------------------------------------|:---------------------------------------------------------------------------------|:---------------------------------------------------------------|
| type | string | string | float |
| modality | text | text | |
| 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/cross_encoder/losses.html#binarycrossentropyloss) with these parameters:
```json
{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": null
}
```
### 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 100 samples:
| | sentence1 | sentence2 | score |
|:---------|:----------------------------------------------------------------------------------|:---------------------------------------------------------------------------------|:---------------------------------------------------------------|
| type | string | string | float |
| modality | text | text | |
| 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/cross_encoder/losses.html#binarycrossentropyloss) with these parameters:
```json
{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": null
}
```
### Training Hyperparameters
#### Non-Default Hyperparameters
- `per_device_train_batch_size`: 64
- `num_train_epochs`: 4
- `warmup_steps`: 0.1
- `bf16`: True
- `per_device_eval_batch_size`: 64
#### All Hyperparameters