11from typing import Optional
22
3- from rank_llm .data import Result
3+ from rank_llm .data import Result
44from rank_llm .rerank import PromptMode
55from rank_llm .rerank .listwise import RankListwiseOSLLM
66
77
88class RankKReranker (RankListwiseOSLLM ):
99 def __init__ (
10- self ,
11- model : str = "hltcoe/Rank-K-32B" ,
12- context_size : int = 4096 ,
13- prompt_mode : PromptMode = PromptMode .RANK_GPT ,
14- prompt_template_path : Optional [str ] = "src/rank_llm/rerank/prompt_templates/rank_k_template.yaml" ,
15- num_few_shot_examples : int = 0 ,
16- device : str = "cuda" ,
17- num_gpus : int = 1 ,
18- variable_passages : bool = True ,
19- window_size : int = 20 ,
20- use_alpha : bool = False
10+ self ,
11+ model : str = "hltcoe/Rank-K-32B" ,
12+ context_size : int = 4096 ,
13+ prompt_mode : PromptMode = PromptMode .RANK_GPT ,
14+ prompt_template_path : Optional [
15+ str
16+ ] = "src/rank_llm/rerank/prompt_templates/rank_k_template.yaml" ,
17+ num_few_shot_examples : int = 0 ,
18+ device : str = "cuda" ,
19+ num_gpus : int = 1 ,
20+ variable_passages : bool = True ,
21+ window_size : int = 20 ,
22+ use_alpha : bool = False ,
2123 ) -> None :
2224 super ().__init__ (
2325 model = model ,
2426 context_size = context_size ,
2527 prompt_mode = prompt_mode ,
2628 prompt_template_path = prompt_template_path ,
27- num_few_shot_examples = num_few_shot_examples ,
28- device = device ,
29+ num_few_shot_examples = num_few_shot_examples ,
30+ device = device ,
2931 num_gpus = num_gpus ,
30- variable_passages = variable_passages ,
32+ variable_passages = variable_passages ,
3133 is_thinking = True ,
3234 reasoning_token_budget = 10000 ,
3335 window_size = window_size ,
34- use_alpha = use_alpha )
35-
36+ use_alpha = use_alpha ,
37+ )
38+
3639 def receive_permutation (
37- self , result : Result , permutation : str , rank_start : int , rank_end : int , logging : bool = False
40+ self ,
41+ result : Result ,
42+ permutation : str ,
43+ rank_start : int ,
44+ rank_end : int ,
45+ logging : bool = False ,
3846 ) -> Result :
3947 """
4048 Processes and applies a permutation to the ranking results.
@@ -54,13 +62,14 @@ def receive_permutation(
5462 Result: The updated result object with the new ranking order applied.
5563
5664 Note:
57- This function assumes that the permutation string has reasoning generated by Rank-K-32B preceding
65+ This function assumes that the permutation string has reasoning generated by Rank-K-32B preceding
5866 the sequence of integers separated by spaces.
59- The function would take the last line of input, and call receive_permutation function from
60- the superclass.
67+ The function would take the last line of input, and call receive_permutation function from
68+ the superclass.
6169 """
6270
6371 # Remove all the reasoning, and take only the order
6472 permutation = permutation .strip ().split ("\n " )[- 1 ]
65- return super ().receive_permutation (result , permutation , rank_start , rank_end , logging )
66-
73+ return super ().receive_permutation (
74+ result , permutation , rank_start , rank_end , logging
75+ )
0 commit comments