| import math | |
| import copy | |
| from tqdm import tqdm | |
| from typing import Optional, Tuple, List, Dict, Union, Any | |
| from ..utils import Result, batch_iterator | |
| from .base import RerankStrategy | |
| class Point(RerankStrategy): | |
| def run( | |
| self, | |
| init_results: List[Result], | |
| rank_start: int = 0, | |
| rank_end: int = None, | |
| batch_size: Optional[int] = 32, | |
| **kwargs | |
| ) -> List[Result]: | |
| results = [copy.deepcopy(result) for result in init_results] | |
| all_scores = {} | |
| for index, result in enumerate(results): | |
| ## Placeholder for scores | |
| result.hits = [hit for hit in result.hits[:rank_end]] | |
| all_scores[result.qid] = [0 for _ in result.hits] | |
| ## Create prompts for all pairs | |
| prompts = self._prompt_builder.create_prompt(result, rank_start=0, rank_end=rank_end) | |
| ## Iterate over pairs | |
| scores = [] | |
| for batch_prompts in batch_iterator(prompts, batch_size): | |
| batch_scores = self._llm.generate(batch_prompts, binary_probs=True) | |
| scores.extend(batch_scores) | |
| ## Score aggregation | |
| for i, score in enumerate(scores): | |
| all_scores[result.qid][i] = score | |
| ## Update results with scores | |
| reranked_results = self._result_parser.parse( | |
| [all_scores[result.qid] for result in results], | |
| init_results | |
| ) | |
| return reranked_results | |
| def run_pass(self, **kwargs: Any): | |
| raise NotImplementedError("Point does not support `run_pass`. Use run instead.") | |
Xet Storage Details
- Size:
- 1.62 kB
- Xet hash:
- 5a8e81772ecbf3b288d6c7040fa9f9f9900d36b7eca5908b59f6aae933828e22
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.