Spaces:
Running
Running
Sarisha Das commited on
Commit Β·
e47665d
1
Parent(s): bef14ab
restore deleted lines
Browse files- utils/bm25.py +13 -1
utils/bm25.py
CHANGED
|
@@ -357,7 +357,7 @@ def build_and_save(
|
|
| 357 |
|
| 358 |
# ββ load ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 359 |
|
| 360 |
-
def load(index_path: str | Path = "data/processed/bm25_index.pkl") -> BM25Retriever:
|
| 361 |
"""
|
| 362 |
Load a previously saved BM25Retriever from disk.
|
| 363 |
Call this in app.py instead of rebuilding every time.
|
|
@@ -368,8 +368,20 @@ def load(index_path: str | Path = "data/processed/bm25_index.pkl") -> BM25Retrie
|
|
| 368 |
f"BM25 index not found at '{index_path}'.\n"
|
| 369 |
"Run build_and_save() from your notebook first."
|
| 370 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
with open(index_path, "rb") as f:
|
| 372 |
retriever = pickle.load(f)
|
|
|
|
| 373 |
print(f"BM25 index loaded β {index_path}")
|
| 374 |
return retriever
|
| 375 |
|
|
|
|
| 357 |
|
| 358 |
# ββ load ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 359 |
|
| 360 |
+
def load(index_path: str | Path = "data/processed/tokenisation/bm25_index.pkl") -> BM25Retriever:
|
| 361 |
"""
|
| 362 |
Load a previously saved BM25Retriever from disk.
|
| 363 |
Call this in app.py instead of rebuilding every time.
|
|
|
|
| 368 |
f"BM25 index not found at '{index_path}'.\n"
|
| 369 |
"Run build_and_save() from your notebook first."
|
| 370 |
)
|
| 371 |
+
# Patch: pickle saved simple_tokenize under 'utils' top-level namespace,
|
| 372 |
+
# but it now lives in utils.bm25 β register it where pickle expects it
|
| 373 |
+
import sys
|
| 374 |
+
import types
|
| 375 |
+
from utils import bm25 as bm25_module
|
| 376 |
+
|
| 377 |
+
if "utils" not in sys.modules or not hasattr(sys.modules["utils"], "simple_tokenize"):
|
| 378 |
+
fake_utils = types.ModuleType("utils")
|
| 379 |
+
fake_utils.simple_tokenize = bm25_module.simple_tokenize
|
| 380 |
+
sys.modules["utils"] = fake_utils
|
| 381 |
+
|
| 382 |
with open(index_path, "rb") as f:
|
| 383 |
retriever = pickle.load(f)
|
| 384 |
+
|
| 385 |
print(f"BM25 index loaded β {index_path}")
|
| 386 |
return retriever
|
| 387 |
|