---
language:
- en
license: apache-2.0
tags:
- cross-encoder
- sentence-transformers
- text-classification
- sentence-pair-classification
- semantic-similarity
- semantic-search
- retrieval
- reranking
- generated_from_trainer
- dataset_size:1047690
- loss:BinaryCrossEntropyLoss
base_model: Alibaba-NLP/gte-reranker-modernbert-base
datasets:
- aditeyabaral-redis/langcache-sentencepairs-v1
pipeline_tag: text-ranking
library_name: sentence-transformers
metrics:
- accuracy
- accuracy_threshold
- f1
- f1_threshold
- precision
- recall
- average_precision
model-index:
- name: Redis fine-tuned CrossEncoder model for semantic caching on LangCache
results:
- task:
type: cross-encoder-classification
name: Cross Encoder Classification
dataset:
name: val
type: val
metrics:
- type: accuracy
value: 0.773111243307555
name: Accuracy
- type: accuracy_threshold
value: 0.7637044787406921
name: Accuracy Threshold
- type: f1
value: 0.6950724637681159
name: F1
- type: f1_threshold
value: 0.04638597369194031
name: F1 Threshold
- type: precision
value: 0.6454912516823688
name: Precision
- type: recall
value: 0.7529042386185243
name: Recall
- type: average_precision
value: 0.7833280130154174
name: Average Precision
- task:
type: cross-encoder-classification
name: Cross Encoder Classification
dataset:
name: test
type: test
metrics:
- type: accuracy
value: 0.7230292965285952
name: Accuracy
- type: accuracy_threshold
value: 0.9352303147315979
name: Accuracy Threshold
- type: f1
value: 0.7144263194410831
name: F1
- type: f1_threshold
value: 0.9142870903015137
name: F1 Threshold
- type: precision
value: 0.6302559284880577
name: Precision
- type: recall
value: 0.8245437616387337
name: Recall
- type: average_precision
value: 0.6906882331078481
name: Average Precision
---
# Redis fine-tuned CrossEncoder model for semantic caching on LangCache
This is a [Cross Encoder](https://www.sbert.net/docs/cross_encoder/usage/usage.html) model finetuned from [Alibaba-NLP/gte-reranker-modernbert-base](https://huggingface.co/Alibaba-NLP/gte-reranker-modernbert-base) on the [LangCache Sentence Pairs (all)](https://huggingface.co/datasets/aditeyabaral-redis/langcache-sentencepairs-v1) dataset using the [sentence-transformers](https://www.SBERT.net) library. It computes scores for pairs of texts, which can be used for sentence pair classification.
## Model Details
### Model Description
- **Model Type:** Cross Encoder
- **Base model:** [Alibaba-NLP/gte-reranker-modernbert-base](https://huggingface.co/Alibaba-NLP/gte-reranker-modernbert-base)
- **Maximum Sequence Length:** 8192 tokens
- **Number of Output Labels:** 1 label
- **Training Dataset:**
- [LangCache Sentence Pairs (all)](https://huggingface.co/datasets/aditeyabaral-redis/langcache-sentencepairs-v1)
- **Language:** en
- **License:** apache-2.0
### 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("aditeyabaral-redis/langcache-reranker-v1-wdwr")
# Get scores for pairs of texts
pairs = [
["He said the foodservice pie business doesn 't fit the company 's long-term growth strategy .", '" The foodservice pie business does not fit our long-term growth strategy .'],
['Magnarelli said Racicot hated the Iraqi regime and looked forward to using his long years of training in the war .', 'His wife said he was " 100 percent behind George Bush " and looked forward to using his years of training in the war .'],
['The dollar was at 116.92 yen against the yen , flat on the session , and at 1.2891 against the Swiss franc , also flat .', 'The dollar was at 116.78 yen JPY = , virtually flat on the session , and at 1.2871 against the Swiss franc CHF = , down 0.1 percent .'],
['The AFL-CIO is waiting until October to decide if it will endorse a candidate .', 'The AFL-CIO announced Wednesday that it will decide in October whether to endorse a candidate before the primaries .'],
['No dates have been set for the civil or the criminal trial .', 'No dates have been set for the criminal or civil cases , but Shanley has pleaded not guilty .'],
]
scores = model.predict(pairs)
print(scores.shape)
# (5,)
# Or rank different texts based on similarity to a single text
ranks = model.rank(
"He said the foodservice pie business doesn 't fit the company 's long-term growth strategy .",
[
'" The foodservice pie business does not fit our long-term growth strategy .',
'His wife said he was " 100 percent behind George Bush " and looked forward to using his years of training in the war .',
'The dollar was at 116.78 yen JPY = , virtually flat on the session , and at 1.2871 against the Swiss franc CHF = , down 0.1 percent .',
'The AFL-CIO announced Wednesday that it will decide in October whether to endorse a candidate before the primaries .',
'No dates have been set for the criminal or civil cases , but Shanley has pleaded not guilty .',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
```
## Evaluation
### Metrics
#### Cross Encoder Classification
* Datasets: `val` and `test`
* Evaluated with [CrossEncoderClassificationEvaluator
](https://sbert.net/docs/package_reference/cross_encoder/evaluation.html#sentence_transformers.cross_encoder.evaluation.CrossEncoderClassificationEvaluator)
| Metric | val | test |
|:----------------------|:-----------|:-----------|
| accuracy | 0.7731 | 0.723 |
| accuracy_threshold | 0.7637 | 0.9352 |
| f1 | 0.6951 | 0.7144 |
| f1_threshold | 0.0464 | 0.9143 |
| precision | 0.6455 | 0.6303 |
| recall | 0.7529 | 0.8245 |
| **average_precision** | **0.7833** | **0.6907** |
## Training Details
### Training Dataset
#### LangCache Sentence Pairs (all)
* Dataset: [LangCache Sentence Pairs (all)](https://huggingface.co/datasets/aditeyabaral-redis/langcache-sentencepairs-v1)
* Size: 8,405 training samples
* Columns: sentence1
, sentence2
, and label
* Approximate statistics based on the first 1000 samples:
| | sentence1 | sentence2 | label |
|:--------|:-------------------------------------------------------------------------------------------------|:-------------------------------------------------------------------------------------------------|:------------------------------------------------|
| type | string | string | int |
| details |
He said the foodservice pie business doesn 't fit the company 's long-term growth strategy .
| " The foodservice pie business does not fit our long-term growth strategy .
| 1
|
| Magnarelli said Racicot hated the Iraqi regime and looked forward to using his long years of training in the war .
| His wife said he was " 100 percent behind George Bush " and looked forward to using his years of training in the war .
| 0
|
| The dollar was at 116.92 yen against the yen , flat on the session , and at 1.2891 against the Swiss franc , also flat .
| The dollar was at 116.78 yen JPY = , virtually flat on the session , and at 1.2871 against the Swiss franc CHF = , down 0.1 percent .
| 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
}
```
### Evaluation Dataset
#### LangCache Sentence Pairs (all)
* Dataset: [LangCache Sentence Pairs (all)](https://huggingface.co/datasets/aditeyabaral-redis/langcache-sentencepairs-v1)
* Size: 8,405 evaluation samples
* Columns: sentence1
, sentence2
, and label
* Approximate statistics based on the first 1000 samples:
| | sentence1 | sentence2 | label |
|:--------|:-------------------------------------------------------------------------------------------------|:-------------------------------------------------------------------------------------------------|:------------------------------------------------|
| type | string | string | int |
| details | He said the foodservice pie business doesn 't fit the company 's long-term growth strategy .
| " The foodservice pie business does not fit our long-term growth strategy .
| 1
|
| Magnarelli said Racicot hated the Iraqi regime and looked forward to using his long years of training in the war .
| His wife said he was " 100 percent behind George Bush " and looked forward to using his years of training in the war .
| 0
|
| The dollar was at 116.92 yen against the yen , flat on the session , and at 1.2891 against the Swiss franc , also flat .
| The dollar was at 116.78 yen JPY = , virtually flat on the session , and at 1.2871 against the Swiss franc CHF = , down 0.1 percent .
| 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`: 48
- `per_device_eval_batch_size`: 48
- `learning_rate`: 0.0002
- `weight_decay`: 0.01
- `num_train_epochs`: 20
- `warmup_ratio`: 0.1
- `load_best_model_at_end`: True
- `optim`: adamw_torch
- `push_to_hub`: True
- `hub_model_id`: aditeyabaral-redis/langcache-reranker-v1-wdwr
#### All Hyperparameters