flashrag-dev 0.1.3.dev20241120__tar.gz → 0.1.3.dev20241122__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. {flashrag-dev-0.1.3.dev20241120/flashrag_dev.egg-info → flashrag-dev-0.1.3.dev20241122}/PKG-INFO +1 -1
  2. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/dataset/dataset.py +3 -1
  3. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/generator/generator.py +2 -2
  4. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/pipeline/active_pipeline.py +26 -24
  5. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/retriever/index_builder.py +6 -1
  6. flashrag-dev-0.1.3.dev20241122/flashrag/version.py +1 -0
  7. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122/flashrag_dev.egg-info}/PKG-INFO +1 -1
  8. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag_dev.egg-info/requires.txt +6 -6
  9. flashrag-dev-0.1.3.dev20241120/flashrag/version.py +0 -1
  10. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/LICENSE +0 -0
  11. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/README.md +0 -0
  12. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/__init__.py +0 -0
  13. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/config/__init__.py +0 -0
  14. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/config/basic_config.yaml +0 -0
  15. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/config/config.py +0 -0
  16. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/dataset/__init__.py +0 -0
  17. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/dataset/utils.py +0 -0
  18. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/evaluator/__init__.py +0 -0
  19. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/evaluator/_bleu.py +0 -0
  20. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/evaluator/evaluator.py +0 -0
  21. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/evaluator/metrics.py +0 -0
  22. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/evaluator/utils.py +0 -0
  23. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/generator/__init__.py +0 -0
  24. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/generator/fid.py +0 -0
  25. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/generator/openai_generator.py +0 -0
  26. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/generator/stop_word_criteria.py +0 -0
  27. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/generator/utils.py +0 -0
  28. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/judger/__init__.py +0 -0
  29. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/judger/judger.py +0 -0
  30. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/pipeline/__init__.py +0 -0
  31. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/pipeline/branching_pipeline.py +0 -0
  32. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/pipeline/pipeline.py +0 -0
  33. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/pipeline/replug_utils.py +0 -0
  34. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/prompt/__init__.py +0 -0
  35. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/prompt/base_prompt.py +0 -0
  36. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/prompt/selfask_examplars.py +0 -0
  37. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/prompt/trace_examplars.py +0 -0
  38. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/refiner/__init__.py +0 -0
  39. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/refiner/kg_refiner.py +0 -0
  40. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/refiner/llmlingua_compressor.py +0 -0
  41. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/refiner/refiner.py +0 -0
  42. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/refiner/selective_context_compressor.py +0 -0
  43. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/retriever/__init__.py +0 -0
  44. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/retriever/__main__.py +0 -0
  45. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/retriever/encoder.py +0 -0
  46. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/retriever/reranker.py +0 -0
  47. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/retriever/retriever.py +0 -0
  48. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/retriever/utils.py +0 -0
  49. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/utils/__init__.py +0 -0
  50. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/utils/constants.py +0 -0
  51. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/utils/pred_parse.py +0 -0
  52. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag/utils/utils.py +0 -0
  53. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag_dev.egg-info/SOURCES.txt +0 -0
  54. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag_dev.egg-info/dependency_links.txt +0 -0
  55. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/flashrag_dev.egg-info/top_level.txt +0 -0
  56. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/pyproject.toml +0 -0
  57. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/setup.cfg +0 -0
  58. {flashrag-dev-0.1.3.dev20241120 → flashrag-dev-0.1.3.dev20241122}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: flashrag-dev
3
- Version: 0.1.3.dev20241120
3
+ Version: 0.1.3.dev20241122
4
4
  Summary: A library for efficient Retrieval-Augmented Generation research
5
5
  Home-page: https://github.com/RUC-NLPIR/FlashRAG
6
6
  Author: Jiajie Jin, Yutao Zhu, Chenghao Zhang, Xinyu Yang, Zhicheng Dou
@@ -176,7 +176,9 @@ class Dataset:
176
176
  save_data = [item.to_dict() for item in self.data]
177
177
  def custom_serializer(obj):
178
178
  if isinstance(obj, np.float32):
179
- return float(obj)
179
+ return float(obj)
180
+ if isinstance(obj, np.bool_):
181
+ return str(obj)
180
182
  raise TypeError(f"Type {type(obj)} not serializable")
181
183
  with open(save_path, "w", encoding="utf-8") as f:
182
184
  json.dump(save_data, f, indent=4, default=custom_serializer)
@@ -176,14 +176,14 @@ class VLLMGenerator(BaseGenerator):
176
176
  gpu_memory_utilization=gpu_memory_utilization,
177
177
  enable_lora=True,
178
178
  max_lora_rank=64,
179
- max_logprobs=32016,
179
+ max_logprobs=130000,
180
180
  )
181
181
  else:
182
182
  self.model = LLM(
183
183
  self.model_path,
184
184
  tensor_parallel_size=tensor_parallel_size,
185
185
  gpu_memory_utilization=gpu_memory_utilization,
186
- max_logprobs=32016,
186
+ max_logprobs=130000,
187
187
  )
188
188
  self.tokenizer = AutoTokenizer.from_pretrained(self.model_path, trust_remote_code=True)
189
189
 
@@ -137,6 +137,7 @@ class SelfRAGPipeline(BasicPipeline):
137
137
  self.ret_tokens, self.rel_tokens, self.grd_tokens, self.ut_tokens = self.load_special_tokens(
138
138
  tokenizer, use_grounding=use_grounding, use_utility=use_utility
139
139
  )
140
+ self.vocab_size = tokenizer.vocab_size + len(tokenizer.added_tokens_decoder)
140
141
 
141
142
  def load_special_tokens(self, tokenizer, use_grounding, use_utility):
142
143
  ret_tokens = {token: tokenizer.convert_tokens_to_ids(token) for token in self.retrieval_tokens_names}
@@ -162,27 +163,25 @@ class SelfRAGPipeline(BasicPipeline):
162
163
  """Calculate whether a retrieve is required based on the output probability of
163
164
  the special token in the model"""
164
165
 
165
- if self.mode != "always_retrieve":
166
+ if self.mode == "always_retrieve":
167
+ retrieval_flags = [True] * len(input_prompts)
168
+
169
+ elif self.mode == "no_retrieval":
170
+ retrieval_flags = [False] * len(input_prompts)
171
+
172
+ else:
166
173
  # result for total batch
167
- all_pred_token_ids = []
168
174
  all_pred_text = []
169
175
  all_pred_log_probs = []
170
- preds = self.generator.generate(input_prompts, return_raw_output=True, logprobs=32000)
176
+ # For vllm, requesting too many logprobes can seriously affect speed
177
+ # 20 probs is enough for calculate
178
+ preds = self.generator.generate(input_prompts, return_raw_output=True, logprobs=20, max_tokens=1, skip_special_tokens=False)
171
179
  for single_pred in preds:
172
- pred_token_ids = single_pred.outputs[0].token_ids
173
180
  pred_text = single_pred.outputs[0].text
174
181
  pred_log_probs = single_pred.outputs[0].logprobs
175
- all_pred_token_ids.append(pred_token_ids)
176
182
  all_pred_text.append(pred_text)
177
183
  all_pred_log_probs.append(pred_log_probs)
178
184
 
179
- if self.mode == "always_retrieve":
180
- retrieval_flags = [True] * len(input_prompts)
181
-
182
- elif self.mode == "no_retrieval":
183
- retrieval_flags = [False] * len(input_prompts)
184
-
185
- else:
186
185
  retrieval_flags = []
187
186
  for idx, single_pred in enumerate(preds):
188
187
  if self.threshold is not None:
@@ -190,8 +189,9 @@ class SelfRAGPipeline(BasicPipeline):
190
189
  for tok, tok_id in self.ret_tokens.items():
191
190
  if tok_id not in all_pred_log_probs[idx][0]:
192
191
  score_dict[tok] = -100
193
- prob = all_pred_log_probs[idx][0][tok_id].logprob
194
- score_dict[tok] = float(prob)
192
+ else:
193
+ prob = all_pred_log_probs[idx][0][tok_id].logprob
194
+ score_dict[tok] = np.exp(prob)
195
195
  do_retrieve = (
196
196
  score_dict["[Retrieval]"] / (score_dict["[Retrieval]"] + score_dict["[No Retrieval]"])
197
197
  > self.threshold
@@ -417,7 +417,7 @@ class SelfRAGPipeline(BasicPipeline):
417
417
  else:
418
418
  aug_prompts = [prompt + prev_generation]
419
419
 
420
- item_pred = self.generator.generate(aug_prompts, return_raw_output=True)
420
+ item_pred = self.generator.generate(aug_prompts, return_raw_output=True, logprobs=5)
421
421
  _, preds, scores, overall_score_dict = self.critic_preds(item_pred)
422
422
 
423
423
  for i, (pred, p_score) in enumerate(zip(preds, scores)):
@@ -602,15 +602,17 @@ class SelfRAGPipeline(BasicPipeline):
602
602
 
603
603
  return dataset
604
604
 
605
- def run(self, dataset, do_eval=True, pred_process_fun=None, batch_size=256, long_form=False):
606
- all_dataset_list = []
605
+ def run(self, dataset, do_eval=True, pred_process_fun=None, long_form=False):
607
606
  run_func = self.run_batch_pred_long_form if long_form else self.run_batch_pred
608
- # to avoid oom
609
- for batch_dataset in tqdm(get_batch_dataset(dataset, batch_size=batch_size), desc="Batch dataset: "):
610
- batch_dataset = run_func(batch_dataset)
611
- all_dataset_list.append(batch_dataset)
612
- dataset = merge_batch_dataset(all_dataset_list)
613
-
607
+
608
+ # # to avoid oom, split the total dataset into small batches
609
+ # all_dataset_list = []
610
+ # for batch_dataset in tqdm(get_batch_dataset(dataset, batch_size=batch_size), desc="Batch dataset: "):
611
+ # batch_dataset = run_func(batch_dataset)
612
+ # all_dataset_list.append(batch_dataset)
613
+ # dataset = merge_batch_dataset(all_dataset_list)
614
+
615
+ dataset = run_func(dataset)
614
616
  dataset = self.evaluate(dataset, do_eval=do_eval, pred_process_fun=pred_process_fun)
615
617
  return dataset
616
618
 
@@ -645,7 +647,7 @@ class SelfRAGPipeline(BasicPipeline):
645
647
  item.update_output("prompt", prompt_list)
646
648
  all_input_list += prompt_list
647
649
 
648
- batch_pred = self.generator.generate(all_input_list, return_raw_output=True, logprobs=32016)
650
+ batch_pred = self.generator.generate(all_input_list, return_raw_output=True, logprobs=5)
649
651
 
650
652
  # parse output based on retrieval flag
651
653
  pred_idx = 0
@@ -165,14 +165,19 @@ class Index_Builder:
165
165
  """Building BM25 index based on bm25s library."""
166
166
 
167
167
  import bm25s
168
+ import Stemmer
168
169
 
169
170
  self.save_dir = os.path.join(self.save_dir, 'bm25')
170
171
  os.makedirs(self.save_dir, exist_ok=True)
171
172
 
172
173
  corpus = datasets.load_dataset("json", data_files=self.corpus_path, split="train")
173
174
  corpus_text = corpus['contents']
175
+ stemmer = Stemmer.Stemmer('english')
176
+ tokenizer = bm25s.tokenization.Tokenizer(stemmer=stemmer)
177
+ corpus_tokens = tokenizer.tokenize(corpus_text, return_as='tuple')
178
+
174
179
  retriever = bm25s.BM25(corpus=corpus, backend='numba')
175
- retriever.index(corpus_text)
180
+ retriever.index(corpus_tokens)
176
181
  retriever.save(self.save_dir,corpus=corpus)
177
182
 
178
183
  print("Finish!")
@@ -0,0 +1 @@
1
+ __version__ = "0.1.3dev20241122"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: flashrag-dev
3
- Version: 0.1.3.dev20241120
3
+ Version: 0.1.3.dev20241122
4
4
  Summary: A library for efficient Retrieval-Augmented Generation research
5
5
  Home-page: https://github.com/RUC-NLPIR/FlashRAG
6
6
  Author: Jiajie Jin, Yutao Zhu, Chenghao Zhang, Xinyu Yang, Zhicheng Dou
@@ -7,12 +7,12 @@ peft
7
7
  PyYAML
8
8
  rank_bm25
9
9
  rouge
10
- spacy>=3.6.1
10
+ spacy==3.6.1
11
11
  tiktoken
12
12
  torch
13
13
  tqdm
14
14
  transformers>=4.40.0
15
- bm25s[full]
15
+ bm25s[core]==0.2.0
16
16
  fschat
17
17
  streamlit
18
18
 
@@ -26,12 +26,12 @@ peft
26
26
  PyYAML
27
27
  rank_bm25
28
28
  rouge
29
- spacy>=3.6.1
29
+ spacy==3.6.1
30
30
  tiktoken
31
31
  torch
32
32
  tqdm
33
33
  transformers>=4.40.0
34
- bm25s[full]
34
+ bm25s[core]==0.2.0
35
35
  fschat
36
36
  streamlit
37
37
 
@@ -45,12 +45,12 @@ peft
45
45
  PyYAML
46
46
  rank_bm25
47
47
  rouge
48
- spacy>=3.6.1
48
+ spacy==3.6.1
49
49
  tiktoken
50
50
  torch
51
51
  tqdm
52
52
  transformers>=4.40.0
53
- bm25s[full]
53
+ bm25s[core]==0.2.0
54
54
  fschat
55
55
  streamlit
56
56
  pyserini
@@ -1 +0,0 @@
1
- __version__ = "0.1.3dev20241120"