abdoelsayed commited on
Commit
400a0bd
·
verified ·
1 Parent(s): 31fe04b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +285 -190
README.md CHANGED
@@ -1,202 +1,297 @@
1
  ---
2
- base_model: meta-llama/Llama-3.1-8B-Instruct
 
 
3
  library_name: peft
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
-
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
 
11
 
12
  ## Model Details
13
 
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
-
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  ## Training Details
77
 
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
200
- ### Framework versions
201
-
202
- - PEFT 0.15.0
 
1
  ---
2
+ language:
3
+ - en
4
+ license: mit
5
  library_name: peft
6
+ tags:
7
+ - reranking
8
+ - information-retrieval
9
+ - listwise
10
+ - lora
11
+ - peft
12
+ - generative
13
+ base_model: meta-llama/Llama-3.1-8B
14
+ datasets:
15
+ - abdoelsayed/DeAR-COT
16
+ pipeline_tag: text-generation
17
  ---
18
 
19
+ # DeAR-8B-Reranker-Listwise-LoRA-v1
 
 
20
 
21
+ ## Model Description
22
 
23
+ **DeAR-8B-Reranker-Listwise-LoRA-v1** is a LoRA adapter for listwise neural reranking. This adapter enables generative document ranking with Chain-of-Thought reasoning while requiring only ~100MB storage. It achieves near full-model performance on complex ranking tasks.
24
 
25
  ## Model Details
26
 
27
+ - **Model Type:** LoRA Adapter for Listwise Reranking
28
+ - **Base Model:** meta-llama/Llama-3.1-8B
29
+ - **Adapter Size:** ~100MB
30
+ - **Training Method:** LoRA with Supervised Fine-tuning + CoT
31
+ - **LoRA Rank:** 16
32
+ - **LoRA Alpha:** 32
33
+ - **Framework:** LLaMA-Factory
34
+
35
+ ## Key Features
36
+
37
+ **Lightweight:** Only 100MB vs 16GB full model
38
+ **CoT Reasoning:** Generates ranking explanations
39
+ **Listwise:** Considers document relationships
40
+ ✅ **State-of-the-Art:** Outperforms GPT-4 on NovelEval
41
+ **Efficient:** Faster training and deployment
42
+
43
+
44
+
45
+ ## Usage
46
+
47
+ ### Load with PEFT
48
+
49
+ ```python
50
+ import torch
51
+ from transformers import AutoTokenizer
52
+ from peft import AutoPeftModelForCausalLM
53
+
54
+ # Load LoRA adapter (automatically loads base model)
55
+ adapter_path = "abdoelsayed/dear-8b-reranker-listwise-lora-v1"
56
+ dtype = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float16
57
+
58
+ tokenizer = AutoTokenizer.from_pretrained(adapter_path, use_fast=True)
59
+ model = AutoPeftModelForCausalLM.from_pretrained(
60
+ adapter_path,
61
+ torch_dtype=dtype,
62
+ device_map="auto",
63
+ trust_remote_code=True,
64
+ low_cpu_mem_usage=True
65
+ )
66
+
67
+ if tokenizer.pad_token is None:
68
+ tokenizer.pad_token = tokenizer.eos_token
69
+
70
+ # Prepare ranking prompt
71
+ query = "When did Thomas Edison invent the light bulb?"
72
+ documents = [
73
+ "Lightning strike at Seoul National University",
74
+ "Thomas Edison tried to invent a device for car but failed",
75
+ "Coffee is good for diet",
76
+ "KEPCO fixes light problems",
77
+ "Thomas Edison invented the light bulb in 1879",
78
+ ]
79
+
80
+ doc_list = "\n".join([f"[{i}] {doc}" for i, doc in enumerate(documents)])
81
+ prompt = f"""I will provide you with {len(documents)} passages, each indicated by a number identifier [].
82
+ Rank the passages based on their relevance to the search query: {query}.
83
+
84
+ {doc_list}
85
+
86
+ Search Query: {query}.
87
+ Rank the passages above based on their relevance to the search query. Output the ranking as a list of numbers."""
88
+
89
+ # Generate ranking
90
+ inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=2048)
91
+ inputs = {k: v.to(model.device) for k, v in inputs.items()}
92
+
93
+ with torch.no_grad():
94
+ outputs = model.generate(
95
+ **inputs,
96
+ max_new_tokens=50,
97
+ temperature=0.7,
98
+ do_sample=False,
99
+ pad_token_id=tokenizer.pad_token_id
100
+ )
101
+
102
+ ranking = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
103
+ print(f"Ranking: {ranking}")
104
+ # Output: [4] > [1] > [0] > [3] > [2]
105
+ ```
106
+
107
+ ### 4-bit Quantization (Low Memory)
108
+
109
+ ```python
110
+ from peft import AutoPeftModelForCausalLM
111
+
112
+ # Load with 4-bit quantization
113
+ model = AutoPeftModelForCausalLM.from_pretrained(
114
+ adapter_path,
115
+ load_in_4bit=True,
116
+ bnb_4bit_compute_dtype=torch.bfloat16,
117
+ device_map="auto",
118
+ trust_remote_code=True
119
+ )
120
+ ```
121
+
122
+ ### Complete Reranking Pipeline
123
+
124
+ ```python
125
+ import re
126
+ from typing import List
127
+
128
+ class ListwiseLoRAReranker:
129
+ def __init__(self, adapter_path: str):
130
+ self.tokenizer = AutoTokenizer.from_pretrained(adapter_path, use_fast=True)
131
+ self.model = AutoPeftModelForCausalLM.from_pretrained(
132
+ adapter_path,
133
+ torch_dtype=torch.bfloat16,
134
+ device_map="auto",
135
+ low_cpu_mem_usage=True
136
+ )
137
+
138
+ if self.tokenizer.pad_token is None:
139
+ self.tokenizer.pad_token = self.tokenizer.eos_token
140
+
141
+ def create_prompt(self, query: str, documents: List[str]) -> str:
142
+ doc_list = "\n".join([f"[{i}] {doc[:300]}" for i, doc in enumerate(documents)])
143
+ return f"""I will provide you with {len(documents)} passages, each indicated by a number identifier [].
144
+ Rank the passages based on their relevance to the search query: {query}.
145
+
146
+ {doc_list}
147
+
148
+ Search Query: {query}.
149
+ Rank the passages above based on their relevance to the search query. Output the ranking as a list of numbers."""
150
+
151
+ def parse_ranking(self, text: str, num_docs: int) -> List[int]:
152
+ numbers = re.findall(r'\[(\d+)\]', text)
153
+ ranking = [int(n) for n in numbers if int(n) < num_docs]
154
+
155
+ # Add missing docs
156
+ for i in range(num_docs):
157
+ if i not in ranking:
158
+ ranking.append(i)
159
+
160
+ return ranking[:num_docs]
161
+
162
+ def rerank(self, query: str, documents: List[str]) -> List[int]:
163
+ prompt = self.create_prompt(query, documents)
164
+ inputs = self.tokenizer(prompt, return_tensors="pt", truncation=True, max_length=2048)
165
+ inputs = {k: v.to(self.model.device) for k, v in inputs.items()}
166
+
167
+ with torch.no_grad():
168
+ outputs = self.model.generate(
169
+ **inputs,
170
+ max_new_tokens=50,
171
+ do_sample=False,
172
+ pad_token_id=self.tokenizer.pad_token_id
173
+ )
174
+
175
+ output_text = self.tokenizer.decode(
176
+ outputs[0][inputs['input_ids'].shape[1]:],
177
+ skip_special_tokens=True
178
+ )
179
+
180
+ return self.parse_ranking(output_text, len(documents))
181
+
182
+ # Usage
183
+ reranker = ListwiseLoRAReranker("abdoelsayed/dear-8b-reranker-listwise-lora-v1")
184
+ ranking = reranker.rerank(query, documents)
185
+ print(f"Ranked indices: {ranking}")
186
+ ```
187
 
188
  ## Training Details
189
 
190
+ ### LoRA Configuration
191
+ ```yaml
192
+ lora_rank: 16
193
+ lora_alpha: 32
194
+ target_modules:
195
+ - q_proj
196
+ - v_proj
197
+ - k_proj
198
+ - o_proj
199
+ - gate_proj
200
+ - up_proj
201
+ - down_proj
202
+ lora_dropout: 0.05
203
+ task_type: CAUSAL_LM
204
+ ```
205
+
206
+ ### Training Setup
207
+ - **Framework:** LLaMA-Factory
208
+ - **Dataset:** [DeAR-COT](https://huggingface.co/datasets/abdoelsayed/DeAR-COT)
209
+ - **Learning Rate:** 1e-5
210
+ - **Batch Size:** 4
211
+ - **Gradient Accumulation:** 4
212
+ - **Epochs:** 2
213
+ - **Max Length:** 2048
214
+ - **GPUs:** 4x A100 (80GB)
215
+ - **Training Time:** ~24 hours (3x faster than full)
216
+ - **Memory:** ~50GB per GPU
217
+
218
+ ## Advantages of LoRA
219
+
220
+ | Feature | LoRA | Full Model |
221
+ |---------|------|------------|
222
+ | Storage | 100MB | 16GB |
223
+ | Training Time | 24h | 72h |
224
+ | Training Memory | 50GB | 70GB |
225
+ | Performance | 99% | 100% |
226
+ | Deployment | Fast | Slow |
227
+
228
+ ## Performance Comparison
229
+
230
+ ### TREC Deep Learning
231
+
232
+ | Method | DL19 | DL20 | Avg |
233
+ |--------|------|------|-----|
234
+ | LoRA | 77.6 | 75.3 | 76.5 |
235
+ | Full | 77.9 | 75.6 | 76.8 |
236
+ | RankGPT-4 | 75.6 | 70.6 | 73.1 |
237
+
238
+ ### NovelEval
239
+
240
+ | Method | NDCG@10 |
241
+ |--------|---------|
242
+ | **LoRA** | **90.6** |
243
+ | Full | 91.0 |
244
+ | GPT-4 | 87.9 |
245
+
246
+ ## When to Use
247
+
248
+ **Best for:**
249
+ - Resource-constrained environments
250
+ - ✅ Multiple domain-specific versions
251
+ - Fast experimentation
252
+ - ✅ Complex reasoning queries
253
+
254
+ **Use full model for:**
255
+ - Absolute maximum performance
256
+ - ❌ Single production deployment
257
+
258
+ ## Limitations
259
+
260
+ - Slightly lower performance (-0.3 NDCG@10)
261
+ - Still slower than pointwise models (~11s)
262
+ - Limited to ~20-50 documents per query
263
+ - Requires base model for inference
264
+
265
+ ## Related Models
266
+
267
+ **Full Version:**
268
+ - [DeAR-8B-Listwise](https://huggingface.co/abdoelsayed/dear-8b-reranker-listwise-v1)
269
+
270
+ **Other LoRA:**
271
+ - [DeAR-8B-RankNet-LoRA](https://huggingface.co/abdoelsayed/dear-8b-reranker-ranknet-lora-v1)
272
+ - [DeAR-8B-CE-LoRA](https://huggingface.co/abdoelsayed/dear-8b-reranker-ce-lora-v1)
273
+
274
+ **Resources:**
275
+ - [DeAR-COT Dataset](https://huggingface.co/datasets/abdoelsayed/DeAR-COT)
276
+ - [Teacher Model](https://huggingface.co/abdoelsayed/llama2-13b-rankllama-teacher)
277
+
278
+ ## Citation
279
+
280
+ ```bibtex
281
+ @article{abdallah2025dear,
282
+ title={DeAR: Dual-Stage Document Reranking with Reasoning Agents via LLM Distillation},
283
+ author={Abdallah, Abdelrahman and Mozafari, Jamshid and Piryani, Bhawna and Jatowt, Adam},
284
+ journal={arXiv preprint arXiv:2508.16998},
285
+ year={2025}
286
+ }
287
+ ```
288
+
289
+ ## License
290
+
291
+ MIT License
292
+
293
+ ## More Information
294
+
295
+ - **GitHub:** [DataScienceUIBK/DeAR-Reranking](https://github.com/DataScienceUIBK/DeAR-Reranking)
296
+ - **Paper:** [arXiv:2508.16998](https://arxiv.org/abs/2508.16998)
297
+ - **Collection:** [DeAR Models](https://huggingface.co/collections/abdoelsayed/dear-reranking)