Text Ranking
sentence-transformers
Safetensors
English
modernbert
ecommerce
e-commerce
retail
marketplace
shopping
amazon
ebay
alibaba
google
rakuten
bestbuy
walmart
flipkart
wayfair
shein
target
etsy
shopify
taobao
asos
carrefour
costco
overstock
pretraining
encoder
language-modeling
foundation-model
text-embeddings-inference
File size: 5,128 Bytes
2a04709 019d030 2a04709 029e74f 64ee61a 2a04709 09c4529 2a04709 09c4529 2a04709 09c4529 2a04709 09c4529 2a04709 09c4529 2a04709 09c4529 2a04709 09c4529 4c017ac 2a04709 09c4529 2a04709 09c4529 2a04709 4c017ac 2a04709 4c017ac 09c4529 2a04709 09c4529 2a04709 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | ---
license: apache-2.0
language:
- en
tags:
- ecommerce
- e-commerce
- retail
- marketplace
- shopping
- amazon
- ebay
- alibaba
- google
- rakuten
- bestbuy
- walmart
- flipkart
- wayfair
- shein
- target
- etsy
- shopify
- taobao
- asos
- carrefour
- costco
- overstock
- pretraining
- encoder
- language-modeling
- foundation-model
base_model:
- thebajajra/RexBERT-mini
pipeline_tag: text-ranking
library_name: sentence-transformers
datasets:
- thebajajra/Amazebay-Relevance
---
<p align="center">
<img src="https://cdn-uploads.huggingface.co/production/uploads/6893dd21467f7d2f5f358a95/apOIbl5PdJuRk-tQMdDc8.png" alt="RexReranker">
</p>
<p align="center">
</p>
[](https://huggingface.co/collections/thebajajra/rexreranker)
[](https://huggingface.co/datasets/thebajajra/Amazebay-Relevance)
[](https://huggingface.co/datasets/thebajajra/eress)
[](https://github.com/bajajra/RexRerankers)
[](https://huggingface.co/blog/thebajajra/rexrerankers)
# RexReranker Mini
State-of-the-art **e-commerce** neural reranker based on RexBERT-mini that predicts relevance scores, given a search query and product details.
## Features
- **Output**: Predicts a probability score between 0.0 and 1.0
- **CrossEncoder Compatible**: Works directly with Sentence Transformers CrossEncoder
- **Mean Pooling**: Uses mean pooling over all tokens for robust representations
## Installation
```bash
pip install transformers sentence-transformers torch
```
## Quick Start
### 1. Using HuggingFace Transformers
```python
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
model_id = "thebajajra/RexReranker-mini"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id)
device = "cuda" if torch.cuda.is_available() else "cpu"
model = model.to(device).eval()
query = "best laptop for programming"
title = "MacBook Pro M3"
description = "Powerful laptop with M3 chip, 16GB RAM, perfect for developers and creative professionals"
inputs = tokenizer(
f"Query: {query}",
f"Title: {title}\nDescription: {description}",
return_tensors="pt",
truncation=True,
max_length=min(model.config.max_position_embeddings, 7999),
).to(device)
with torch.no_grad():
outputs = model(**inputs)
score = outputs.logits.squeeze(-1) # shape: [batch]
print(f"Relevance Score: {score[0].item():.4f}")
```
### 2. Using Sentence Transformers CrossEncoder
```python
from sentence_transformers import CrossEncoder
# Load as CrossEncoder
model = CrossEncoder(
"thebajajra/RexReranker-mini",
trust_remote_code=True
)
# Single prediction
query = "best laptop for programming"
document = "MacBook Pro M3 - Powerful laptop with M3 chip for developers"
score = model.predict([(query, document)])[0]
print(f"Score: {score:.4f}")
```
### 3. Batch Reranking with CrossEncoder
```python
from sentence_transformers import CrossEncoder
model = CrossEncoder("thebajajra/RexReranker-mini", trust_remote_code=True)
query = "best laptop for programming"
documents = [
"MacBook Pro M3 - Powerful laptop with M3 chip for developers",
"Gaming Mouse RGB - High precision gaming mouse with 16000 DPI",
"ThinkPad X1 Carbon - Business ultrabook with long battery life",
"Mechanical Keyboard - Cherry MX switches for typing comfort",
"Dell XPS 15 - Premium laptop with 4K OLED display",
]
# Get scores for all documents
pairs = [(query, doc) for doc in documents]
scores = model.predict(pairs)
# Print ranked results
print(f"Query: {query}\n")
for doc, score in sorted(zip(documents, scores), key=lambda x: x[1], reverse=True):
print(f" {score:.4f} | {doc[:60]}")
```
### 4. Using CrossEncoder's rank() Method
```python
from sentence_transformers import CrossEncoder
model = CrossEncoder("thebajajra/RexReranker-mini", trust_remote_code=True)
query = "wireless headphones with noise cancellation"
documents = [
"Sony WH-1000XM5 - Industry-leading noise cancellation headphones",
"Apple AirPods Max - Premium over-ear headphones with spatial audio",
"Bose QuietComfort 45 - Comfortable wireless noise cancelling headphones",
"JBL Tune 750BTNC - Affordable wireless headphones with ANC",
"Logitech Gaming Headset - Wired gaming headphones with microphone",
]
# Rank documents
results = model.rank(query, documents, top_k=3)
print(f"Query: {query}\n")
print("Top 3 Results:")
for result in results:
idx = result['corpus_id']
score = result['score']
print(f" {score:.4f} | {documents[idx][:60]}")
```
## Input Format
The model expects query-document pairs formatted as:
| Field | Format |
|-------|--------|
| Text A (Query) | `Query: {your search query}` |
| Text B (Document) | `Title: {document title}\nDescription: {document description}` | |