Skip to content

Commit

Permalink
fix bge rerank normalize issue (#988)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
  • Loading branch information
KevinHuSh authored May 30, 2024
1 parent 843720f commit 77363a0
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rag/llm/rerank_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from api.utils.file_utils import get_home_cache_dir
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):
Expand Down Expand Up @@ -69,6 +71,7 @@ def similarity(self, query: str, texts: list):
res = []
for i in range(0, len(pairs), batch_size):
scores = self._model.compute_score(pairs[i:i + batch_size], max_length=2048)
scores = sigmoid(np.array(scores))
res.extend(scores)
return np.array(res), token_count

Expand Down

0 comments on commit 77363a0

Please sign in to comment.