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- jhu-clsp/rank1-training-data
|
5 |
+
base_model:
|
6 |
+
- jhu-clsp/rank1-7b
|
7 |
+
pipeline_tag: text-generation
|
8 |
+
tags:
|
9 |
+
- reranker
|
10 |
+
- retrieval
|
11 |
+
- quantized
|
12 |
+
- awq
|
13 |
+
language:
|
14 |
+
- en
|
15 |
+
---
|
16 |
+
|
17 |
+
# rank1-7b-awq: Quantized Model for Test-Time Compute Reranking
|
18 |
+
|
19 |
+
📄 [Paper](https://arxiv.org/abs/2502.18418) | 🚀 [GitHub Repository](https://github.com/orionw/rank1)
|
20 |
+
|
21 |
+
rank1-7b-awq is a quantized version of the rank1-7b model. This AWQ-quantized 7B parameter model maintains the reasoning capabilities of the original model while requiring less memory and providing faster inference. The model is trained from the Qwen2.5-7B base model and leverages test-time compute to generate reasoning chains before deciding if a document is relevant to a query.
|
22 |
+
|
23 |
+
## Model Description
|
24 |
+
|
25 |
+
rank1 introduces a novel approach to information retrieval by generating explicit reasoning chains before making relevance judgments. Unlike traditional rerankers that directly output scores, rank1:
|
26 |
+
|
27 |
+
1. Receives a query and document pair
|
28 |
+
2. Generates a reasoning chain within a `<think>...</think>` section
|
29 |
+
3. Makes a binary relevance judgment (`true` or `false`)
|
30 |
+
4. Returns a confidence score based on the logits of the true/false tokens
|
31 |
+
|
32 |
+
This approach helps the model break down complex relevance decisions into logical steps, improving performance across diverse retrieval tasks.
|
33 |
+
|
34 |
+
## Quantization Details
|
35 |
+
|
36 |
+
This model uses Activation-aware Weight Quantization (AWQ) to reduce the model size while maintaining performance. Compared to the full-precision model, this quantized version:
|
37 |
+
|
38 |
+
- Requires less GPU memory
|
39 |
+
- Offers faster inference times
|
40 |
+
- Maintains comparable accuracy on retrieval tasks
|
41 |
+
|
42 |
+
## Model Family
|
43 |
+
|
44 |
+
| Model | Base | Description |
|
45 |
+
|:------|:-----|:------------|
|
46 |
+
| [rank1-7b](https://huggingface.co/jhu-clsp/rank1-7b) | Qwen2.5-7B | Full-precision version (7B parameters) |
|
47 |
+
| [rank1-14b](https://huggingface.co/jhu-clsp/rank1-14b) | Qwen2.5-14B | Larger variant (14B parameters) |
|
48 |
+
| [rank1-32b](https://huggingface.co/jhu-clsp/rank1-32b) | Qwen2.5-32B | Largest variant (32B parameters) |
|
49 |
+
| [rank1-mistral-2501-24b](https://huggingface.co/jhu-clsp/rank1-mistral-2501-24b) | Mistral-Small 2501 24B | Trained from Mistral base |
|
50 |
+
| [rank1-llama3-8b](https://huggingface.co/jhu-clsp/rank1-llama3-8b) | Llama 3.1 8B | Trained from Llama 3.1 base |
|
51 |
+
|
52 |
+
### Quantized Variants
|
53 |
+
|
54 |
+
| Model | Description |
|
55 |
+
|:------|:------------|
|
56 |
+
| [rank1-7b-awq](https://huggingface.co/jhu-clsp/rank1-7b-awq) | Current model - Quantized version of rank1-7b |
|
57 |
+
| [rank1-14b-awq](https://huggingface.co/jhu-clsp/rank1-14b-awq) | Quantized version of rank1-14b |
|
58 |
+
| [rank1-32b-awq](https://huggingface.co/jhu-clsp/rank1-32b-awq) | Quantized version of rank1-32b |
|
59 |
+
| [rank1-mistral-2501-24b-awq](https://huggingface.co/jhu-clsp/rank1-mistral-2501-24b-awq) | Quantized version of rank1-mistral-24b |
|
60 |
+
| [rank1-llama3-8b-awq](https://huggingface.co/jhu-clsp/rank1-llama3-8b-awq) | Quantized version of rank1-llama3-8b |
|
61 |
+
|
62 |
+
## Associated Data and Resources
|
63 |
+
|
64 |
+
| Resource | Description |
|
65 |
+
|:---------|:------------|
|
66 |
+
| [rank1-r1-msmarco](https://huggingface.co/datasets/jhu-clsp/rank1-r1-msmarco) | All R1 output examples from MS MARCO |
|
67 |
+
| [rank1-training-data](https://huggingface.co/datasets/jhu-clsp/rank1-training-data) | Training data used for rank1 models |
|
68 |
+
| [rank1-run-files](https://huggingface.co/datasets/jhu-clsp/rank1-run-files) | Pre-computed run files for use in top 100 doc reranking |
|
69 |
+
| [GitHub Repository](https://github.com/orionw/rank1) | Official rank1 repository |
|
70 |
+
|
71 |
+
## Usage
|
72 |
+
Note that official usage is found on the Github and accounts for edge cases. But for simple use cases the minimal example below works.
|
73 |
+
|
74 |
+
<details>
|
75 |
+
<summary>Click to expand: Minimal example with vLLM</summary>
|
76 |
+
|
77 |
+
```python
|
78 |
+
from vllm import LLM, SamplingParams
|
79 |
+
import math
|
80 |
+
|
81 |
+
# Initialize the model with vLLM
|
82 |
+
model = LLM(
|
83 |
+
model="jhu-clsp/rank1-7b-awq",
|
84 |
+
tensor_parallel_size=1, # Number of GPUs
|
85 |
+
trust_remote_code=True,
|
86 |
+
max_model_len=16000, # Context length
|
87 |
+
gpu_memory_utilization=0.9,
|
88 |
+
dtype="auto", # Will use the appropriate quantized dtype
|
89 |
+
)
|
90 |
+
|
91 |
+
# Set up sampling parameters
|
92 |
+
sampling_params = SamplingParams(
|
93 |
+
temperature=0,
|
94 |
+
max_tokens=8192,
|
95 |
+
logprobs=20,
|
96 |
+
stop=["</think> true", "</think> false"],
|
97 |
+
skip_special_tokens=False
|
98 |
+
)
|
99 |
+
|
100 |
+
# Prepare the prompt
|
101 |
+
def create_prompt(query, document):
|
102 |
+
return (
|
103 |
+
"Determine if the following passage is relevant to the query. "
|
104 |
+
"Answer only with 'true' or 'false'.\n"
|
105 |
+
f"Query: {query}\n"
|
106 |
+
f"Passage: {document}\n"
|
107 |
+
"<think>"
|
108 |
+
)
|
109 |
+
|
110 |
+
# Example usage
|
111 |
+
query = "What are the effects of climate change?"
|
112 |
+
document = "Climate change leads to rising sea levels, extreme weather events, and disruptions to ecosystems. These effects are caused by increasing greenhouse gas concentrations in the atmosphere due to human activities."
|
113 |
+
|
114 |
+
# Generate prediction
|
115 |
+
prompt = create_prompt(query, document)
|
116 |
+
outputs = model.generate([prompt], sampling_params)
|
117 |
+
|
118 |
+
# Extract score
|
119 |
+
output = outputs[0].outputs[0]
|
120 |
+
text = output.text
|
121 |
+
final_logits = output.logprobs[-1]
|
122 |
+
|
123 |
+
# Get token IDs for "true" and "false" tokens
|
124 |
+
from transformers import AutoTokenizer
|
125 |
+
tokenizer = AutoTokenizer.from_pretrained("jhu-clsp/rank1-7b-awq")
|
126 |
+
true_token = tokenizer(" true", add_special_tokens=False).input_ids[0]
|
127 |
+
false_token = tokenizer(" false", add_special_tokens=False).input_ids[0]
|
128 |
+
|
129 |
+
# Calculate relevance score (probability of "true")
|
130 |
+
true_logit = final_logits[true_token].logprob
|
131 |
+
false_logit = final_logits[false_token].logprob
|
132 |
+
true_score = math.exp(true_logit)
|
133 |
+
false_score = math.exp(false_logit)
|
134 |
+
relevance_score = true_score / (true_score + false_score)
|
135 |
+
|
136 |
+
print(f"Reasoning chain: {text}")
|
137 |
+
print(f"Relevance score: {relevance_score}")
|
138 |
+
```
|
139 |
+
|
140 |
+
</details>
|
141 |
+
|
142 |
+
<details>
|
143 |
+
<summary>Click to expand: Usage with AutoGPTQ/AWQ</summary>
|
144 |
+
|
145 |
+
```python
|
146 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
147 |
+
import torch
|
148 |
+
|
149 |
+
# Load the tokenizer and quantized model
|
150 |
+
tokenizer = AutoTokenizer.from_pretrained("jhu-clsp/rank1-7b-awq")
|
151 |
+
model = AutoModelForCausalLM.from_pretrained(
|
152 |
+
"jhu-clsp/rank1-7b-awq",
|
153 |
+
device_map="auto",
|
154 |
+
trust_remote_code=True
|
155 |
+
)
|
156 |
+
|
157 |
+
# Prepare the prompt
|
158 |
+
query = "What are the effects of climate change?"
|
159 |
+
document = "Climate change leads to rising sea levels, extreme weather events, and disruptions to ecosystems. These effects are caused by increasing greenhouse gas concentrations in the atmosphere due to human activities."
|
160 |
+
|
161 |
+
prompt = f"Determine if the following passage is relevant to the query. Answer only with 'true' or 'false'.\nQuery: {query}\nPassage: {document}\n<think>"
|
162 |
+
|
163 |
+
# Generate the reasoning chain and relevance judgment
|
164 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
165 |
+
with torch.no_grad():
|
166 |
+
outputs = model.generate(
|
167 |
+
**inputs,
|
168 |
+
max_new_tokens=512,
|
169 |
+
temperature=0.0,
|
170 |
+
return_dict_in_generate=True,
|
171 |
+
output_scores=True,
|
172 |
+
pad_token_id=tokenizer.eos_token_id
|
173 |
+
)
|
174 |
+
|
175 |
+
# Process the output
|
176 |
+
generated_text = tokenizer.decode(outputs.sequences[0], skip_special_tokens=False)
|
177 |
+
reasoning_chain = generated_text.split("<think>")[1].split("</think>")[0].strip()
|
178 |
+
relevance_judgment = "true" if "true" in generated_text.split("</think>")[1].strip().lower() else "false"
|
179 |
+
|
180 |
+
print(f"Reasoning chain: {reasoning_chain}")
|
181 |
+
print(f"Relevance judgment: {relevance_judgment}")
|
182 |
+
```
|
183 |
+
|
184 |
+
</details>
|
185 |
+
|
186 |
+
## Performance
|
187 |
+
|
188 |
+
rank1-7b-awq demonstrates strong performance on retrieval benchmarks while offering faster inference and lower memory requirements than the full-precision model. The quantization process preserves the model's ability to "think through" relevance decisions, making it effective for nuanced topics.
|
189 |
+
|
190 |
+
For specific benchmark results and comparisons with other models, please refer to the paper and the official GitHub repository.
|
191 |
+
|
192 |
+
## Installation
|
193 |
+
|
194 |
+
Please see the Github for detailed installation instructions.
|
195 |
+
|
196 |
+
## MTEB Integration
|
197 |
+
|
198 |
+
rank1 is compatible with the [MTEB benchmarking framework](https://github.com/embeddings-benchmark/mteb):
|
199 |
+
|
200 |
+
```python
|
201 |
+
from mteb import MTEB
|
202 |
+
from rank1 import rank1 # From the official repo
|
203 |
+
|
204 |
+
# Initialize the model
|
205 |
+
model = rank1(
|
206 |
+
model_name_or_path="jhu-clsp/rank1-7b-awq",
|
207 |
+
num_gpus=1,
|
208 |
+
device="cuda",
|
209 |
+
quantized=True # Indicate that you're using the quantized version
|
210 |
+
)
|
211 |
+
|
212 |
+
# Run evaluation on specific tasks
|
213 |
+
evaluation = MTEB(tasks=["NevIR"])
|
214 |
+
results = evaluation.run(model)
|
215 |
+
```
|
216 |
+
|
217 |
+
## Citation
|
218 |
+
|
219 |
+
If you use rank1 in your research, please cite our work:
|
220 |
+
|
221 |
+
```bibtex
|
222 |
+
@misc{weller2025rank1testtimecomputereranking,
|
223 |
+
title={Rank1: Test-Time Compute for Reranking in Information Retrieval},
|
224 |
+
author={Orion Weller and Kathryn Ricci and Eugene Yang and Andrew Yates and Dawn Lawrie and Benjamin Van Durme},
|
225 |
+
year={2025},
|
226 |
+
eprint={2502.18418},
|
227 |
+
archivePrefix={arXiv},
|
228 |
+
primaryClass={cs.IR},
|
229 |
+
url={https://arxiv.org/abs/2502.18418},
|
230 |
+
}
|
231 |
+
```
|
232 |
+
|
233 |
+
## License
|
234 |
+
|
235 |
+
[MIT License](https://github.com/orionw/rank1/blob/main/LICENSE)
|