We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In flag_reranker.py from FlagReranker class library code.
flag_reranker.py
FlagReranker
@torch.no_grad() def compute_score(self, sentence_pairs: Union[List[Tuple[str, str]], Tuple[str, str]], batch_size: int = 256, max_length: int = 512, normalize: bool = False) -> List[float]: if self.num_gpus > 0: batch_size = batch_size * self.num_gpus assert isinstance(sentence_pairs, list) if isinstance(sentence_pairs[0], str): sentence_pairs = [sentence_pairs] all_scores = [] for start_index in tqdm(range(0, len(sentence_pairs), batch_size), desc="Compute Scores", disable=len(sentence_pairs) < 128): sentences_batch = sentence_pairs[start_index:start_index + batch_size] inputs = self.tokenizer( sentences_batch, padding=True, truncation=True, return_tensors='pt', max_length=max_length, ).to(self.device) scores = self.model(**inputs, return_dict=True).logits.view(-1, ).float() all_scores.extend(scores.cpu().numpy().tolist()) if normalize: all_scores = [sigmoid(score) for score in all_scores] if len(all_scores) == 1: return all_scores[0] return all_scores
It supports batch_size already. Real model computation happens in here.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
In
flag_reranker.py
fromFlagReranker
class library code.It supports batch_size already. Real model computation happens in here.
The text was updated successfully, but these errors were encountered: