DeAR-3B-Reranker-CE-v1 is a 3B parameter efficient neural reranker trained with Binary Cross-Entropy loss and knowledge distillation. This model provides fast, reliable reranking for production environments where speed and efficiency are critical.
Model Details
Model Type: Pointwise Reranker (Binary Classification)
Base Model: LLaMA-3.2-3B
Parameters: 3 billion
Training Method: Knowledge Distillation + Binary Cross-Entropy
✅ Ultra Fast: 1.5s inference (best in DeAR family)
✅ Memory Efficient: Runs on single 16GB GPU
✅ Production Ready: Stable training with BCE loss
✅ Cost Effective: Lower computational costs
✅ Binary Classification: Probabilistic relevance scores
Usage
Quick Start
python
1import torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
34# Load model5model_path ="abdoelsayed/dear-3b-reranker-ce-v1"6tokenizer = AutoTokenizer.from_pretrained(model_path)7model = AutoModelForSequenceClassification.from_pretrained(8 model_path,9 torch_dtype=torch.bfloat16
10)11model.eval().cuda()1213# Score a query-document pair14query ="What is llama?"15document ="The llama is a domesticated South American camelid..."1617inputs = tokenizer(18f"query: {query}",19f"document: {document}",20 return_tensors="pt",21 truncation=True,22 max_length=228,23 padding="max_length"24)25inputs ={k: v.cuda()for k, v in inputs.items()}2627with torch.no_grad():28 score = model(**inputs).logits.squeeze().item()2930print(f"Relevance score: {score}")
Efficient Batch Processing
python
1import torch
2from typing import List, Tuple
34@torch.inference_mode()5deffast_rerank(tokenizer, model, query:str, docs: List[Tuple[str,str]], batch_size:int=128):6"""Fast reranking optimized for 3B model."""7 device =next(model.parameters()).device
8 scores =[]910for i inrange(0,len(docs), batch_size):11 batch = docs[i:i + batch_size]1213# Prepare batch14 queries =[f"query: {query}"]*len(batch)15 documents =[f"document: {t}{p}"for t, p in batch]1617# Tokenize18 inputs = tokenizer(19 queries,20 documents,21 return_tensors="pt",22 truncation=True,23 max_length=228,24 padding=True25)26 inputs ={k: v.to(device)for k, v in inputs.items()}2728# Score29 logits = model(**inputs).logits.squeeze(-1)30 scores.extend(logits.cpu().tolist())3132# Rank33returnsorted(enumerate(scores), key=lambda x: x[1], reverse=True)343536# Example37query ="When did Thomas Edison invent the light bulb?"38docs =[39("","Thomas Edison invented the light bulb in 1879"),40("","Coffee is good for diet"),41("","Lightning strike at Seoul National University"),42]4344ranking = fast_rerank(tokenizer, model, query, docs, batch_size=128)45print(ranking)46# DeAR-P-3B-BC Output:47# [(0, -6.0625), (2, -11.125), (1, -12.0625)]
Production Optimization
python
1# Optimize for maximum throughput2model = AutoModelForSequenceClassification.from_pretrained(3"abdoelsayed/dear-3b-reranker-ce-v1",4 torch_dtype=torch.bfloat16,5 device_map="auto"6)7model.eval()89# Compile for 20-30% speedup (PyTorch 2.0+)10ifhasattr(torch,'compile'):11 model = torch.compile(model, mode="max-autotune")1213# Use larger batches for throughput14batch_size =128# 3B can handle larger batches