BaseReranker#
- class FlagEmbedding.inference.reranker.encoder_only.base.BaseReranker(model_name_or_path: str, use_fp16: bool = False, query_instruction_for_rerank: str | None = None, query_instruction_format: str = '{}{}', passage_instruction_for_rerank: str | None = None, passage_instruction_format: str = '{}{}', trust_remote_code: bool = False, cache_dir: str | None = None, devices: str | List[str] | List[int] | None = None, batch_size: int = 128, query_max_length: int | None = None, max_length: int = 512, normalize: bool = False, **kwargs: Any)[source]#
Base reranker class for encoder only models.
- Parameters:
model_name_or_path (str) – If it’s a path to a local model, it loads the model from the path. Otherwise tries to download and load a model from HuggingFace Hub with the name.
use_fp16 (bool, optional) – If true, use half-precision floating-point to speed up computation with a slight performance degradation. Defaults to
False
.query_instruction_for_rerank (Optional[str], optional) – Query instruction for retrieval tasks, which will be used with with
query_instruction_format
. Defaults toNone
.query_instruction_format (str, optional) – The template for
query_instruction_for_rerank
. Defaults to"{}{}"
.passage_instruction_format (str, optional) – The template for passage. Defaults to “{}{}”.
cache_dir (Optional[str], optional) – Cache directory for the model. Defaults to
None
.devices (Optional[Union[str, List[str], List[int]]], optional) – Devices to use for model inference. Defaults to
None
.batch_size (int, optional) – Batch size for inference. Defaults to
128
.query_max_length (Optional[int], optional) – Maximum length for queries. If not specified, will be 3/4 of
max_length
. Defaults toNone
.max_length (int, optional) – Maximum length of passages. Defaults to :data`512`.
normalize (bool, optional) – If True, use Sigmoid to normalize the results. Defaults to
False
.
Methods#
- class FlagEmbedding.inference.reranker.encoder_only.base.BaseReranker.compute_score_single_gpu(self, sentence_pairs: List[Tuple[str, str]] | Tuple[str, str], batch_size: int | None = None, query_max_length: int | None = None, max_length: int | None = None, normalize: bool | None = None, device: str | None = None, **kwargs: Any)#
_summary_
- Parameters:
sentence_pairs (Union[List[Tuple[str, str]], Tuple[str, str]]) – Input sentence pairs to compute scores.
batch_size (Optional[int], optional) – Number of inputs for each iter. Defaults to
None
.query_max_length (Optional[int], optional) – Maximum length of tokens of queries. Defaults to
None
.max_length (Optional[int], optional) – Maximum length of tokens. Defaults to
None
.normalize (Optional[bool], optional) – If True, use Sigmoid to normalize the results. Defaults to
None
.device (Optional[str], optional) – Device to use for computation. Defaults to
None
.
- Returns:
Computed scores of queries and passages.
- Return type:
List[float]