---
tags:
- sentence-transformers
- cross-encoder
- reranker
- generated_from_trainer
- dataset_size:8000
- loss:BinaryCrossEntropyLoss
base_model: BAAI/bge-reranker-v2-m3
pipeline_tag: text-ranking
library_name: sentence-transformers
metrics:
- accuracy
- accuracy_threshold
- f1
- f1_threshold
- precision
- recall
- average_precision
model-index:
- name: CrossEncoder based on BAAI/bge-reranker-v2-m3
results:
- task:
type: cross-encoder-binary-classification
name: Cross Encoder Binary Classification
dataset:
name: validation
type: validation
metrics:
- type: accuracy
value: 0.9366666666666666
name: Accuracy
- type: accuracy_threshold
value: 0.783203125
name: Accuracy Threshold
- type: f1
value: 0.9389067524115757
name: F1
- type: f1_threshold
value: 0.783203125
name: F1 Threshold
- type: precision
value: 0.906832298136646
name: Precision
- type: recall
value: 0.9733333333333334
name: Recall
- type: average_precision
value: 0.9587180157254458
name: Average Precision
- task:
type: cross-encoder-binary-classification
name: Cross Encoder Binary Classification
dataset:
name: train subset
type: train_subset
metrics:
- type: accuracy
value: 0.908
name: Accuracy
- type: accuracy_threshold
value: 0.9296875
name: Accuracy Threshold
- type: f1
value: 0.9132075471698113
name: F1
- type: f1_threshold
value: 0.84765625
name: F1 Threshold
- type: precision
value: 0.8897058823529411
name: Precision
- type: recall
value: 0.937984496124031
name: Recall
- type: average_precision
value: 0.9411597379663916
name: Average Precision
---
# CrossEncoder based on BAAI/bge-reranker-v2-m3
This is a [Cross Encoder](https://www.sbert.net/docs/cross_encoder/usage/usage.html) model finetuned from [BAAI/bge-reranker-v2-m3](https://huggingface.co/BAAI/bge-reranker-v2-m3) 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:** [BAAI/bge-reranker-v2-m3](https://huggingface.co/BAAI/bge-reranker-v2-m3)
- **Maximum Sequence Length:** 1024 tokens
- **Number of Output Labels:** 1 label
### 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)
## 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("cross_encoder_model_id")
# Get scores for pairs of texts
pairs = [
['What was the 2011 Census population of this village and civil parish in Lincolnshire, where Regents Academy is based?', 'Manby. Manby is a village and civil parish in the East Lindsey district of Lincolnshire, England, and lies approximately 5 mi east from Louth. The 2001 Census recorded a village population of 833, reducing to 759 at the 2011 Census.'],
['Piña colada and Aperol Spritz can both be described as what kind of drink?', '2-Acetylpyridine. 2-Acetylpyridine is an organic compound with the formula CH3COC5H4N. It is a viscous colorless liquid that is widely used as a flavoring substance. It is found in malt and produced by the Maillard reaction and by nixtamalization. It contributes to the flavor of corn tortillas, popcorn, and beer.'],
['What song by a Barbadian singer was covered by Marié Christina Digby?', 'Umbrella (song). "Umbrella" is a song by Barbadian singer Rihanna from her third studio album "Good Girl Gone Bad" (2007). It features American rapper Jay-Z, who co-wrote the song with its producers Tricky Stewart and Kuk Harrell, with additional writing from The-Dream. The song was originally written with Britney Spears in mind, but her label rejected it. "Umbrella" is a pop, hip hop and R&B song referring to a romantic and platonic relationship and the strength of that relationship.'],
["When was the Roman politician and general died during who's reign Gaius Nasennius were soldiers?", "Narses. Narses (also sometimes written Nerses; Armenian: Նարսես ; Greek: Ναρσής ; 478–573) was, with Belisarius, one of the great generals in the service of the Byzantine Emperor Justinian I during the Roman reconquest that took place during Justinian's reign. A Romanized Armenian, Narses spent most of his life as an important eunuch in the palace of the emperors in Constantinople."],
['California Tortilla was voted as having the best burritos in both 2009 and 2010 by a magazine founded in what year?', 'California Tortilla. California Tortilla, also known as CalTort, is a chain of franchised fast casual Mexican-style restaurants, the first of which was opened in August 1995 in Bethesda, Maryland by business partners Pam Felix and Alan Cohen. The chain\'s menu, which features Mission burritos, is comparable to that of its competitors, such as Baja Fresh and Chipotle Mexican Grill. A typical restaurant has 2500 sqft with seating for 75 people. California Tortilla was voted by readers of "Washingtonian" magazine as having the best burritos in both 2009 and 2010, and "best Mexican" in 2014 and 2015. The chain sold its 5 millionth burrito on August 22, 2007.'],
]
scores = model.predict(pairs)
print(scores.shape)
# (5,)
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'What was the 2011 Census population of this village and civil parish in Lincolnshire, where Regents Academy is based?',
[
'Manby. Manby is a village and civil parish in the East Lindsey district of Lincolnshire, England, and lies approximately 5 mi east from Louth. The 2001 Census recorded a village population of 833, reducing to 759 at the 2011 Census.',
'2-Acetylpyridine. 2-Acetylpyridine is an organic compound with the formula CH3COC5H4N. It is a viscous colorless liquid that is widely used as a flavoring substance. It is found in malt and produced by the Maillard reaction and by nixtamalization. It contributes to the flavor of corn tortillas, popcorn, and beer.',
'Umbrella (song). "Umbrella" is a song by Barbadian singer Rihanna from her third studio album "Good Girl Gone Bad" (2007). It features American rapper Jay-Z, who co-wrote the song with its producers Tricky Stewart and Kuk Harrell, with additional writing from The-Dream. The song was originally written with Britney Spears in mind, but her label rejected it. "Umbrella" is a pop, hip hop and R&B song referring to a romantic and platonic relationship and the strength of that relationship.',
"Narses. Narses (also sometimes written Nerses; Armenian: Նարսես ; Greek: Ναρσής ; 478–573) was, with Belisarius, one of the great generals in the service of the Byzantine Emperor Justinian I during the Roman reconquest that took place during Justinian's reign. A Romanized Armenian, Narses spent most of his life as an important eunuch in the palace of the emperors in Constantinople.",
'California Tortilla. California Tortilla, also known as CalTort, is a chain of franchised fast casual Mexican-style restaurants, the first of which was opened in August 1995 in Bethesda, Maryland by business partners Pam Felix and Alan Cohen. The chain\'s menu, which features Mission burritos, is comparable to that of its competitors, such as Baja Fresh and Chipotle Mexican Grill. A typical restaurant has 2500 sqft with seating for 75 people. California Tortilla was voted by readers of "Washingtonian" magazine as having the best burritos in both 2009 and 2010, and "best Mexican" in 2014 and 2015. The chain sold its 5 millionth burrito on August 22, 2007.',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
```
## Evaluation
### Metrics
#### Cross Encoder Binary Classification
* Datasets: `validation` and `train_subset`
* Evaluated with [CEBinaryClassificationEvaluator](https://sbert.net/docs/package_reference/cross_encoder/evaluation.html#sentence_transformers.cross_encoder.evaluation.CEBinaryClassificationEvaluator)
| Metric | validation | train_subset |
|:----------------------|:-----------|:-------------|
| accuracy | 0.9367 | 0.908 |
| accuracy_threshold | 0.7832 | 0.9297 |
| f1 | 0.9389 | 0.9132 |
| f1_threshold | 0.7832 | 0.8477 |
| precision | 0.9068 | 0.8897 |
| recall | 0.9733 | 0.938 |
| **average_precision** | **0.9587** | **0.9412** |
## Training Details
### Training Dataset
#### Unnamed Dataset
* Size: 8,000 training samples
* Columns: sentence_0, sentence_1, and label
* Approximate statistics based on the first 1000 samples:
| | sentence_0 | sentence_1 | label |
|:--------|:-------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------|:---------------------------------------------------------------|
| type | string | string | float |
| details |
What was the 2011 Census population of this village and civil parish in Lincolnshire, where Regents Academy is based? | Manby. Manby is a village and civil parish in the East Lindsey district of Lincolnshire, England, and lies approximately 5 mi east from Louth. The 2001 Census recorded a village population of 833, reducing to 759 at the 2011 Census. | 1.0 |
| Piña colada and Aperol Spritz can both be described as what kind of drink? | 2-Acetylpyridine. 2-Acetylpyridine is an organic compound with the formula CH3COC5H4N. It is a viscous colorless liquid that is widely used as a flavoring substance. It is found in malt and produced by the Maillard reaction and by nixtamalization. It contributes to the flavor of corn tortillas, popcorn, and beer. | 0.0 |
| What song by a Barbadian singer was covered by Marié Christina Digby? | Umbrella (song). "Umbrella" is a song by Barbadian singer Rihanna from her third studio album "Good Girl Gone Bad" (2007). It features American rapper Jay-Z, who co-wrote the song with its producers Tricky Stewart and Kuk Harrell, with additional writing from The-Dream. The song was originally written with Britney Spears in mind, but her label rejected it. "Umbrella" is a pop, hip hop and R&B song referring to a romantic and platonic relationship and the strength of that relationship. | 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
- `eval_strategy`: steps
- `per_device_train_batch_size`: 2
- `per_device_eval_batch_size`: 2
#### All Hyperparameters