Spaces:
Runtime error
Runtime error
Fixed indentation at line 88
Browse files
simple_search_engine/search_engine.py
CHANGED
|
@@ -85,11 +85,11 @@ class SimpleSearchEngine:
|
|
| 85 |
print("BM25 index built.")
|
| 86 |
|
| 87 |
def _minmax_normalize(self, scores: np.ndarray):
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
|
| 94 |
def search_bm25(self, query: str, top_k: int = 5):
|
| 95 |
if self.bm25 is None:
|
|
|
|
| 85 |
print("BM25 index built.")
|
| 86 |
|
| 87 |
def _minmax_normalize(self, scores: np.ndarray):
|
| 88 |
+
min_s = scores.min()
|
| 89 |
+
max_s = scores.max()
|
| 90 |
+
if max_s == min_s:
|
| 91 |
+
return np.zeros_like(scores)
|
| 92 |
+
return (scores - min_s) / (max_s - min_s)
|
| 93 |
|
| 94 |
def search_bm25(self, query: str, top_k: int = 5):
|
| 95 |
if self.bm25 is None:
|