From 46caf6ae72ce36b56604921bfd0dac045bda7b00 Mon Sep 17 00:00:00 2001 From: Stephen Hu Date: Mon, 21 Jul 2025 10:22:20 +0800 Subject: [PATCH] Refactor improve codes for ranker (#8936) ### What problem does this PR solve? Use the normalize method directly ### Type of change - [x] Refactoring --- rag/llm/rerank_model.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/rag/llm/rerank_model.py b/rag/llm/rerank_model.py index 4c21fd270..a638375f6 100644 --- a/rag/llm/rerank_model.py +++ b/rag/llm/rerank_model.py @@ -32,11 +32,6 @@ from api.utils.file_utils import get_home_cache_dir from api.utils.log_utils import log_exception from rag.utils import num_tokens_from_string, truncate - -def sigmoid(x): - return 1 / (1 + np.exp(-x)) - - class Base(ABC): def __init__(self, key, model_name): pass @@ -133,10 +128,9 @@ class DefaultRerank(Base): def _compute_batch_scores(self, batch_pairs, max_length=None): if max_length is None: - scores = self._model.compute_score(batch_pairs) + scores = self._model.compute_score(batch_pairs, normalize=True) else: - scores = self._model.compute_score(batch_pairs, max_length=max_length) - scores = sigmoid(np.array(scores)) + scores = self._model.compute_score(batch_pairs, max_length=max_length, normalize=True) if not isinstance(scores, Iterable): scores = [scores] return scores