Download tests/test_bm25.py from Snapkitty/sovlm: direct link, hf CLI and curl.
- Browser
- Download file 665 Bytes
-
https://huggingface.co/Snapkitty/sovlm/resolve/main/tests/test_bm25.py
- Command line
-
hf download hf://Snapkitty/sovlm/tests/test_bm25.py
-
curl -L -o test_bm25.py https://huggingface.co/Snapkitty/sovlm/resolve/main/tests/test_bm25.py
665 Bytes
| from sovlm.dictionary import Dictionary | |
| from sovlm.inverted_index import InvertedIndex | |
| from sovlm.corpus import tokenize | |
| def test_bm25_retrieval(): | |
| d = Dictionary() | |
| inv = InvertedIndex() | |
| chunks = [ | |
| "the cat sat on the mat", | |
| "the dog ran in the park", | |
| "quantum mechanics governs atomic transitions", | |
| ] | |
| for i, text in enumerate(chunks): | |
| ids = [d.add(tok) for tok in tokenize(text)] | |
| inv.add_chunk(i, text, ids) | |
| d.freeze() | |
| query = [d["the"], d["cat"]] | |
| results = inv.retrieve(query, top_k=2) | |
| assert len(results) > 0 | |
| assert results[0][1] == 0 # chunk 0 has "cat" | |