A 4-bit NF4 quantized version of
cross-encoder/ms-marco-MiniLM-L-6-v2 for passage reranking, using
bitsandbytes quantization.
4-bit NF4 quantization preserves near-identical quality across all three benchmarks:
1from transformers import AutoModelForSequenceClassification, AutoTokenizer
2import torch
3
4model = AutoModelForSequenceClassification.from_pretrained(
5 "MO7YW4NG/ms-marco-MiniLM-L-6-v2-4bit-nf4",
6 device_map="auto",
7)
8tokenizer = AutoTokenizer.from_pretrained(
9 "MO7YW4NG/ms-marco-MiniLM-L-6-v2-4bit-nf4",
10)
11
12query = "What is the impact of climate change on coral reefs?"
13passage = "Rising ocean temperatures cause widespread coral bleaching events..."
14
15inputs = tokenizer(
16 query, passage,
17 return_tensors="pt",
18 truncation=True,
19 max_length=512,
20 padding=True,
21).to(model.device)
22
23with torch.no_grad():
24 score = model(**inputs).logits.squeeze().item()
25print(f"Relevance score: {score:.4f}")
1from sentence_transformers.cross_encoder import CrossEncoder
2
3model = CrossEncoder(
4 "MO7YW4NG/ms-marco-MiniLM-L-6-v2-4bit-nf4",
5 max_length=512,
6)
7
8query = "What is the impact of climate change on coral reefs?"
9passages = [
10 "Rising ocean temperatures cause widespread coral bleaching events...",
11 "The history of marine biology dates back to ancient Greece...",
12]
13
14pairs = [[query, p] for p in passages]
15scores = model.predict(pairs)
16print(scores)
1@misc{ms-marco-MiniLM-L-6-v2,
2 title={MS MARCO Cross-Encoder MiniLM-L-6-v2},
3 author={Nils Reimers},
4 url={https://huggingface.co/cross-encoder/ms-marco-MiniLM-L-6-v2},
5}