Spaces:
Sleeping
Sleeping
Kurt
commited on
Commit
·
e62249b
1
Parent(s):
131f55f
toll5
Browse files
app.py
CHANGED
@@ -641,23 +641,23 @@ demo: Optional[gr.Interface] = None # Assign your gradio demo to this variable
|
|
641 |
return_type = List[Hit]
|
642 |
|
643 |
## YOUR_CODE_STARTS_HERE
|
644 |
-
|
645 |
documents=iter(sciq.corpus),
|
646 |
ndocs=12160,
|
647 |
show_progress_bar=True,
|
648 |
k1=best_k1,
|
649 |
b=best_b
|
650 |
)
|
651 |
-
|
652 |
|
653 |
def search(query: str) -> List[Hit]:
|
654 |
-
|
655 |
-
result =
|
656 |
|
657 |
l : return_type = []
|
658 |
for cid, score in result.items():
|
659 |
-
docid =
|
660 |
-
text =
|
661 |
|
662 |
l.append(Hit(cid=cid, score=score, text=text))
|
663 |
|
|
|
641 |
return_type = List[Hit]
|
642 |
|
643 |
## YOUR_CODE_STARTS_HERE
|
644 |
+
bm25_index = BM25Index.build_from_documents(
|
645 |
documents=iter(sciq.corpus),
|
646 |
ndocs=12160,
|
647 |
show_progress_bar=True,
|
648 |
k1=best_k1,
|
649 |
b=best_b
|
650 |
)
|
651 |
+
bm25_index.save("output/bm25_index")
|
652 |
|
653 |
def search(query: str) -> List[Hit]:
|
654 |
+
bm25_index = CSCBM25Retriever(index_dir="output/bm25_index")
|
655 |
+
result = bm25_index.retrieve(query)
|
656 |
|
657 |
l : return_type = []
|
658 |
for cid, score in result.items():
|
659 |
+
docid = bm25_index.index.cid2docid[cid]
|
660 |
+
text = bm25_index.index.doc_texts[docid]
|
661 |
|
662 |
l.append(Hit(cid=cid, score=score, text=text))
|
663 |
|