mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-13 03:09:04 +08:00
fix bge rerank normalize issue (#988)
### What problem does this PR solve? ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
parent
843720f958
commit
77363a0875
@ -24,6 +24,8 @@ import numpy as np
|
|||||||
from api.utils.file_utils import get_home_cache_dir
|
from api.utils.file_utils import get_home_cache_dir
|
||||||
from rag.utils import num_tokens_from_string, truncate
|
from rag.utils import num_tokens_from_string, truncate
|
||||||
|
|
||||||
|
def sigmoid(x):
|
||||||
|
return 1 / (1 + np.exp(-x))
|
||||||
|
|
||||||
class Base(ABC):
|
class Base(ABC):
|
||||||
def __init__(self, key, model_name):
|
def __init__(self, key, model_name):
|
||||||
@ -69,6 +71,7 @@ class DefaultRerank(Base):
|
|||||||
res = []
|
res = []
|
||||||
for i in range(0, len(pairs), batch_size):
|
for i in range(0, len(pairs), batch_size):
|
||||||
scores = self._model.compute_score(pairs[i:i + batch_size], max_length=2048)
|
scores = self._model.compute_score(pairs[i:i + batch_size], max_length=2048)
|
||||||
|
scores = sigmoid(np.array(scores))
|
||||||
res.extend(scores)
|
res.extend(scores)
|
||||||
return np.array(res), token_count
|
return np.array(res), token_count
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user