Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:FlagOpen FlagEmbedding AbsReranker Compute Score

From Leeroopedia


Template:Implementation

Signature

def compute_score(
    self,
    sentence_pairs: Union[List[Tuple[str, str]], Tuple[str, str]],
    **kwargs
) -> numpy.ndarray:

Import:

from FlagEmbedding import FlagAutoReranker

Use via reranker instance.

I/O

Input:

  • sentence_pairs — list of (query, passage) tuples

Output:

  • numpy.ndarray of float scores

kwargs:

  • batch_size (int) — number of pairs per batch
  • max_length (int) — maximum token length for input
  • normalize (bool) — whether to normalize scores

Internal Behavior

Internally calls get_detailed_inputs() to apply instructions, then dispatches to compute_score_single_gpu() on one device or encode_multi_process() across multiple GPUs.

Examples

Basic reranker scoring:

from FlagEmbedding import FlagAutoReranker

reranker = FlagAutoReranker.from_finetuned("BAAI/bge-reranker-v2-m3")
pairs = [
    ("What is deep learning?", "Deep learning is a subset of machine learning."),
    ("What is deep learning?", "The weather is sunny today.")
]
scores = reranker.compute_score(pairs)
print(scores)

Normalized scores:

scores = reranker.compute_score(pairs, normalize=True)
print(scores)  # scores mapped to [0, 1]

Batch scoring:

large_pairs = [("query", f"passage_{i}") for i in range(1000)]
scores = reranker.compute_score(large_pairs, batch_size=64, max_length=512)
print(scores.shape)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment