Text Ranking
sentence-transformers
Safetensors
English
modernbert
cross-encoder
text-classification
sentence-pair-classification
semantic-similarity
semantic-search
retrieval
reranking
Generated from Trainer
dataset_size:1452533
loss:MultipleNegativesRankingLoss
text-embeddings-inference
Instructions to use redis/langcache-reranker-v1-mnrl with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use redis/langcache-reranker-v1-mnrl with sentence-transformers:
from sentence_transformers import CrossEncoder model = CrossEncoder("redis/langcache-reranker-v1-mnrl") query = "Which planet is known as the Red Planet?" passages = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", "Saturn, famous for its rings, is sometimes mistaken for the Red Planet." ] scores = model.predict([(query, passage) for passage in passages]) print(scores) - Notebooks
- Google Colab
- Kaggle
| 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:1452533 | |
| - loss:MultipleNegativesRankingLoss | |
| base_model: Alibaba-NLP/gte-reranker-modernbert-base | |
| datasets: | |
| - redis/langcache-sentencepairs-v1 | |
| pipeline_tag: text-ranking | |
| library_name: sentence-transformers | |
| # 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 (subsets=['all'], train+val=True)](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) <!-- at revision f7481e6055501a30fb19d090657df9ec1f79ab2c --> | |
| - **Maximum Sequence Length:** 8192 tokens | |
| - **Number of Output Labels:** 1 label | |
| - **Training Dataset:** | |
| - [LangCache Sentence Pairs (subsets=['all'], train+val=True)](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("redis/langcache-reranker-v1-softmnrl-triplet") | |
| # Get scores for pairs of texts | |
| pairs = [ | |
| [' What high potential jobs are there other than computer science?', ' What high potential jobs are there other than computer science?'], | |
| [' Would India ever be able to develop a missile system like S300 or S400 missile?', ' Would India ever be able to develop a missile system like S300 or S400 missile?'], | |
| [' water from the faucet is being drunk by a yellow dog', 'A yellow dog is drinking water from the faucet'], | |
| [' water from the faucet is being drunk by a yellow dog', 'The yellow dog is drinking water from a bottle'], | |
| ['! colspan = `` 14 `` `` Players who appeared for Colchester who left during the season ``', '! colspan = `` 14 `` `` Players who appeared for Colchester who left during the season ``'], | |
| ] | |
| scores = model.predict(pairs) | |
| print(scores.shape) | |
| # (5,) | |
| # Or rank different texts based on similarity to a single text | |
| ranks = model.rank( | |
| ' What high potential jobs are there other than computer science?', | |
| [ | |
| ' What high potential jobs are there other than computer science?', | |
| ' Would India ever be able to develop a missile system like S300 or S400 missile?', | |
| 'A yellow dog is drinking water from the faucet', | |
| 'The yellow dog is drinking water from a bottle', | |
| '! colspan = `` 14 `` `` Players who appeared for Colchester who left during the season ``', | |
| ] | |
| ) | |
| # [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...] | |
| ``` | |
| <!-- | |
| ### Direct Usage (Transformers) | |
| <details><summary>Click to see the direct usage in Transformers</summary> | |
| </details> | |
| --> | |
| <!-- | |
| ### Downstream Usage (Sentence Transformers) | |
| You can finetune this model on your own dataset. | |
| <details><summary>Click to expand</summary> | |
| </details> | |
| --> | |
| <!-- | |
| ### Out-of-Scope Use | |
| *List how the model may foreseeably be misused and address what users ought not to do with the model.* | |
| --> | |
| <!-- | |
| ## Bias, Risks and Limitations | |
| *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.* | |
| --> | |
| <!-- | |
| ### Recommendations | |
| *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.* | |
| --> | |
| ## Training Details | |
| ### Training Dataset | |
| #### LangCache Sentence Pairs (subsets=['all'], train+val=True) | |
| * Dataset: [LangCache Sentence Pairs (subsets=['all'], train+val=True)](https://huggingface.co/datasets/aditeyabaral-redis/langcache-sentencepairs-v1) | |
| * Size: 1,452,533 training samples | |
| * Columns: <code>anchor</code>, <code>positive</code>, and <code>negative_1</code> | |
| * Approximate statistics based on the first 1000 samples: | |
| | | anchor | positive | negative_1 | | |
| |:--------|:-------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------| | |
| | type | string | string | string | | |
| | details | <ul><li>min: 24 characters</li><li>mean: 114.25 characters</li><li>max: 268 characters</li></ul> | <ul><li>min: 19 characters</li><li>mean: 114.1 characters</li><li>max: 226 characters</li></ul> | <ul><li>min: 4 characters</li><li>mean: 93.04 characters</li><li>max: 234 characters</li></ul> | | |
| * Samples: | |
| | anchor | positive | negative_1 | | |
| |:-----------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------| | |
| | <code> Any Canadian teachers (B.Ed. holders) teaching in U.S. schools?</code> | <code> Any Canadian teachers (B.Ed. holders) teaching in U.S. schools?</code> | <code>Are there many Canadians living and working illegally in the United States?</code> | | |
| | <code> Are there any underlying psychological tricks/tactics that are used when designing the lines for rides at amusement parks?</code> | <code> Are there any underlying psychological tricks/tactics that are used when designing the lines for rides at amusement parks?</code> | <code>Is there any tricks for straight lines mcqs?</code> | | |
| | <code> Can I pay with a debit card on PayPal?</code> | <code> Can I pay with a debit card on PayPal?</code> | <code>Can you transfer PayPal funds onto a debit card/credit card?</code> | | |
| * Loss: [<code>MultipleNegativesRankingLoss</code>](https://sbert.net/docs/package_reference/cross_encoder/losses.html#multiplenegativesrankingloss) with these parameters: | |
| ```json | |
| { | |
| "scale": 20.0, | |
| "num_negatives": 1, | |
| "activation_fn": "torch.nn.modules.activation.Sigmoid" | |
| } | |
| ``` | |
| ### Evaluation Dataset | |
| #### LangCache Sentence Pairs (split=test) | |
| * Dataset: [LangCache Sentence Pairs (split=test)](https://huggingface.co/datasets/aditeyabaral-redis/langcache-sentencepairs-v1) | |
| * Size: 110,066 evaluation samples | |
| * Columns: <code>anchor</code>, <code>positive</code>, and <code>negative_1</code> | |
| * Approximate statistics based on the first 1000 samples: | |
| | | anchor | positive | negative_1 | | |
| |:--------|:-----------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------| | |
| | type | string | string | string | | |
| | details | <ul><li>min: 3 characters</li><li>mean: 97.95 characters</li><li>max: 314 characters</li></ul> | <ul><li>min: 3 characters</li><li>mean: 97.03 characters</li><li>max: 314 characters</li></ul> | <ul><li>min: 11 characters</li><li>mean: 74.49 characters</li><li>max: 295 characters</li></ul> | | |
| * Samples: | |
| | anchor | positive | negative_1 | | |
| |:----------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------| | |
| | <code> What high potential jobs are there other than computer science?</code> | <code> What high potential jobs are there other than computer science?</code> | <code>Why IT or Computer Science jobs are being over rated than other Engineering jobs?</code> | | |
| | <code> Would India ever be able to develop a missile system like S300 or S400 missile?</code> | <code> Would India ever be able to develop a missile system like S300 or S400 missile?</code> | <code>Should India buy the Russian S400 air defence missile system?</code> | | |
| | <code> water from the faucet is being drunk by a yellow dog</code> | <code>A yellow dog is drinking water from the faucet</code> | <code>Do you get more homework in 9th grade than 8th?</code> | | |
| * Loss: [<code>MultipleNegativesRankingLoss</code>](https://sbert.net/docs/package_reference/cross_encoder/losses.html#multiplenegativesrankingloss) with these parameters: | |
| ```json | |
| { | |
| "scale": 20.0, | |
| "num_negatives": 1, | |
| "activation_fn": "torch.nn.modules.activation.Sigmoid" | |
| } | |
| ``` | |
| ### Framework Versions | |
| - Python: 3.12.3 | |
| - Sentence Transformers: 5.1.0 | |
| - Transformers: 4.56.0 | |
| - PyTorch: 2.8.0+cu128 | |
| - Accelerate: 1.10.1 | |
| - Datasets: 4.0.0 | |
| - Tokenizers: 0.22.0 | |
| ## Citation | |
| ### BibTeX | |
| #### Sentence Transformers | |
| ```bibtex | |
| @inproceedings{reimers-2019-sentence-bert, | |
| title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks", | |
| author = "Reimers, Nils and Gurevych, Iryna", | |
| booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing", | |
| month = "11", | |
| year = "2019", | |
| publisher = "Association for Computational Linguistics", | |
| url = "https://arxiv.org/abs/1908.10084", | |
| } | |
| ``` | |
| <!-- | |
| ## Glossary | |
| *Clearly define terms in order to be accessible across audiences.* | |
| --> | |
| <!-- | |
| ## Model Card Authors | |
| *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.* | |
| --> | |
| <!-- | |
| ## Model Card Contact | |
| *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.* | |
| --> |