KevinHuSh commited on
Commit
c07cfc8
·
1 Parent(s): eefeab4

fix bge rerank normalize issue (#988)

Browse files

### What problem does this PR solve?


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

Files changed (1) hide show
  1. rag/llm/rerank_model.py +3 -0
rag/llm/rerank_model.py CHANGED
@@ -24,6 +24,8 @@ import numpy as np
24
  from api.utils.file_utils import get_home_cache_dir
25
  from rag.utils import num_tokens_from_string, truncate
26
 
 
 
27
 
28
  class Base(ABC):
29
  def __init__(self, key, model_name):
@@ -69,6 +71,7 @@ class DefaultRerank(Base):
69
  res = []
70
  for i in range(0, len(pairs), batch_size):
71
  scores = self._model.compute_score(pairs[i:i + batch_size], max_length=2048)
 
72
  res.extend(scores)
73
  return np.array(res), token_count
74
 
 
24
  from api.utils.file_utils import get_home_cache_dir
25
  from rag.utils import num_tokens_from_string, truncate
26
 
27
+ def sigmoid(x):
28
+ return 1 / (1 + np.exp(-x))
29
 
30
  class Base(ABC):
31
  def __init__(self, key, model_name):
 
71
  res = []
72
  for i in range(0, len(pairs), batch_size):
73
  scores = self._model.compute_score(pairs[i:i + batch_size], max_length=2048)
74
+ scores = sigmoid(np.array(scores))
75
  res.extend(scores)
76
  return np.array(res), token_count
77