DeAR-Reranking
Collection
DeAR (Deep Agent Rank): Dual-Stage Document Reranking with Reasoning Agents Accepted at EMNLP Findings 2025
β’
12 items
β’
Updated
β’
1
DeAR-8B-Reranker-CE-v1 is an 8B parameter neural reranker trained with Binary Cross-Entropy loss and knowledge distillation. This model uses a classification-based approach to document reranking and is optimized for both accuracy and inference speed.
β
Classification-based: Binary relevance prediction with probabilistic outputs
β
Fast Inference: 2.2s average latency on standard GPU
β
Strong Baseline: Competitive performance across benchmarks
β
CoT Enhanced: Trained with Chain-of-Thought reasoning from teacher
| Benchmark | NDCG@10 |
|---|---|
| TREC DL19 | 73.9 |
| TREC DL20 | 72.1 |
| BEIR (Avg) | 44.8 |
| MS MARCO Dev | 68.5 |
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
# Load model
model_path = "abdoelsayed/dear-8b-reranker-ce-v1"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForSequenceClassification.from_pretrained(
model_path,
torch_dtype=torch.bfloat16
)
model.eval().cuda()
# Score a query-document pair
query = "What is llama?"
document = "The llama is a domesticated South American camelid..."
inputs = tokenizer(
f"query: {query}",
f"document: {document}",
return_tensors="pt",
truncation=True,
max_length=228,
padding="max_length"
)
inputs = {k: v.cuda() for k, v in inputs.items()}
with torch.no_grad():
score = model(**inputs).logits.squeeze().item()
print(f"Relevance score: {score}")
import torch
from typing import List, Tuple
from transformers import AutoTokenizer, AutoModelForSequenceClassification
def load_reranker(model_path: str, device: str = "cuda"):
"""Load the reranker model and tokenizer."""
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForSequenceClassification.from_pretrained(
model_path,
torch_dtype=torch.bfloat16
)
# Configure padding token
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
tokenizer.pad_token_id = tokenizer.eos_token_id
tokenizer.padding_side = "right"
model.eval()
model.to(device)
return tokenizer, model
@torch.inference_mode()
def rerank(
tokenizer,
model,
query: str,
documents: List[Tuple[str, str]], # (title, text)
batch_size: int = 64
) -> List[Tuple[int, float]]:
"""
Rerank documents for a query.
Returns:
List of (doc_index, score) sorted by relevance (descending)
"""
device = next(model.parameters()).device
scores = []
for i in range(0, len(documents), batch_size):
batch = documents[i:i + batch_size]
# Prepare batch
queries = [f"query: {query}"] * len(batch)
docs = [f"document: {title} {text}" for title, text in batch]
inputs = tokenizer(
queries,
docs,
return_tensors="pt",
truncation=True,
max_length=228,
padding=True,
return_attention_mask=True
)
inputs = {k: v.to(device) for k, v in inputs.items()}
# Score batch
logits = model(**inputs).logits.squeeze(-1)
scores.extend(logits.cpu().tolist())
# Rank by score
ranked = sorted(enumerate(scores), key=lambda x: x[1], reverse=True)
return ranked
# Example
tokenizer, model = load_reranker("abdoelsayed/dear-8b-reranker-ce-v1")
query = "When did Thomas Edison invent the light bulb?"
documents = [
("", "Lightning strike at Seoul National University"),
("", "Thomas Edison tried to invent a device for car but failed"),
("", "Coffee is good for diet"),
("", "KEPCO fixes light problems"),
("", "Thomas Edison invented the light bulb in 1879"),
]
ranking = rerank(tokenizer, model, query, documents)
print(ranking)
# Output: [(4, -2.015625), (1, -5.6875), (2, -6.375), (0, -6.5), (3, -6.78125)]
# Document at index 4 is most relevant
{
"base_model": "meta-llama/Llama-3.1-8B",
"teacher_model": "abdoelsayed/llama2-13b-rankllama-teacher",
"loss": "Binary Cross-Entropy",
"distillation": {
"temperature": 2.0,
"alpha": 0.1
},
"optimizer": "AdamW",
"learning_rate": 1e-4,
"batch_size": 2,
"gradient_accumulation": 2,
"epochs": 2,
"max_length": 228,
"q_max_len": 32,
"p_max_len": 196,
"warmup_ratio": 0.1,
"weight_decay": 0.01,
"bf16": true
}
Binary Cross-Entropy with Knowledge Distillation:
L_total = (1 - Ξ±) * BCE(y_pred, y_true) + Ξ± * KL(Ο(z_s/T), Ο(z_t/T))
where:
- BCE: Binary cross-entropy loss
- KL: KL divergence
- z_s: Student logits
- z_t: Teacher logits
- T: Temperature (2.0)
- Ξ±: Distillation weight (0.1)
- Ο: Sigmoid function
| Dataset | NDCG@10 | NDCG@20 | MRR@10 | MAP |
|---|---|---|---|---|
| DL19 | 73.90 | 69.82 | 87.3 | 44.92 |
| DL20 | 72.10 | 68.45 | 85.1 | 42.67 |
| Dataset | NDCG@10 | NDCG@100 |
|---|---|---|
| MS MARCO | 68.5 | 75.2 |
| NQ | 51.8 | 69.4 |
| HotpotQA | 61.2 | 74.8 |
| FiQA | 46.8 | 62.3 |
| ArguAna | 58.9 | 71.5 |
| SciFact | 73.1 | 82.6 |
| TREC-COVID | 84.7 | 88.3 |
| NFCorpus | 39.4 | 51.7 |
| Average | 44.8 | 68.2 |
| Metric | Value |
|---|---|
| Inference Time (batch=64) | 2.2s |
| Throughput | ~45 docs/sec |
| GPU Memory (inference) | 18GB |
| Model Size (BF16) | 16GB |
| Model | Loss | DL19 | DL20 | BEIR Avg | Speed (s) |
|---|---|---|---|---|---|
| DeAR-8B-CE | BCE | 73.9 | 72.1 | 44.8 | 2.2 |
| DeAR-8B-RankNet | RankNet | 74.5 | 72.8 | 45.2 | 2.2 |
| MonoT5-3B | - | 71.8 | 68.9 | 43.5 | 3.5 |
| Teacher-13B | - | 73.8 | 71.2 | 44.8 | 5.8 |
Key Observations:
Input Format: "query: [QUERY] document: [TITLE] [TEXT]"
β
Tokenization (max_length=228)
β
LLaMA-3.1-8B Transformer
β
[CLS] Token Pooling
β
Linear(hidden_size β 1)
β
Sigmoid (optional)
β
Relevance Score
Best for:
Consider alternatives for:
Recommendations:
To fine-tune on your own data:
from transformers import AutoModelForSequenceClassification, Trainer, TrainingArguments
model = AutoModelForSequenceClassification.from_pretrained(
"abdoelsayed/dear-8b-reranker-ce-v1",
num_labels=1
)
training_args = TrainingArguments(
output_dir="./finetuned-model",
learning_rate=5e-6, # Lower LR for fine-tuning
per_device_train_batch_size=4,
num_train_epochs=1,
bf16=True,
logging_steps=100,
)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=your_dataset,
)
trainer.train()
DeAR Family (8B):
Other Sizes:
Resources:
@article{abdallah2025dear,
title={DeAR: Dual-Stage Document Reranking with Reasoning Agents via LLM Distillation},
author={Abdallah, Abdelrahman and Mozafari, Jamshid and Piryani, Bhawna and Jatowt, Adam},
journal={arXiv preprint arXiv:2508.16998},
year={2025}
}
MIT License
Base model
meta-llama/Llama-3.1-8B