DeAR-3B-Reranker-RankNet-v1 is a 3B parameter efficient neural reranker trained with RankNet loss and knowledge distillation. This model offers the best speed-performance tradeoff in the DeAR family, achieving competitive results with significantly faster inference than larger models.
Model Details
Model Type: Pointwise Reranker (Sequence Classification)
Base Model: LLaMA-3.2-3B
Parameters: 3 billion
Training Method: Knowledge Distillation + RankNet Loss
✅ Ultra Fast: 1.5s inference (1.5x faster than 8B models)
✅ Efficient: Runs on single 16GB GPU
✅ Strong Performance: Competitive with larger models
✅ Low Latency: Ideal for production deployments
✅ Small Footprint: Only 6GB model size
Speed-Performance Tradeoff: 95% accuracy at 1.5x speed!
Usage
Quick Start
python
1import torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
34# Load model5model_path ="abdoelsayed/dear-3b-reranker-ranknet-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 machine learning?"15document ="Machine learning is a subset of artificial intelligence..."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}")
Batch Reranking
python
1from typing import List, Tuple
23@torch.inference_mode()4defrerank(tokenizer, model, query:str, docs: List[Tuple[str,str]], batch_size:int=64):5"""
6 Rerank documents for a query.
78 Args:
9 docs: List of (title, text) tuples
1011 Returns:
12 List of (index, score) sorted by relevance
13 """14 device =next(model.parameters()).device
15 scores =[]1617for i inrange(0,len(docs), batch_size):18 batch = docs[i:i + batch_size]19 queries =[f"query: {query}"]*len(batch)20 documents =[f"document: {title}{text}"for title, text in batch]2122 inputs = tokenizer(23 queries,24 documents,25 return_tensors="pt",26 truncation=True,27 max_length=228,28 padding=True29)30 inputs ={k: v.to(device)for k, v in inputs.items()}3132 logits = model(**inputs).logits.squeeze(-1)33 scores.extend(logits.cpu().tolist())3435returnsorted(enumerate(scores), key=lambda x: x[1], reverse=True)363738# Example39query ="When did Thomas Edison invent the light bulb?"40docs =[41("","Lightning strike at Seoul National University"),42("","Thomas Edison tried to invent a device for car but failed"),43("","Coffee is good for diet"),44("","KEPCO fixes light problems"),45("","Thomas Edison invented the light bulb in 1879"),46]4748ranking = rerank(tokenizer, model, query, docs)49print(ranking)50# DeAR-P-3B-RL Output:51# [(4, -1.3046875), (1, -5.125), (3, -6.3125), (0, -6.4375), (2, -6.96875)]