This is a BM25S index created with the bm25s library (version 0.2.5), an ultra-fast implementation of BM25. It can be used for lexical retrieval tasks.
1pip install"bm25s==0.2.5"23# Include extra dependencies like stemmer4pip install"bm25s[full]==0.2.5"56# For huggingface hub usage7pip install huggingface_hub
Loading a bm25s index
You can use this index for information retrieval tasks. Here is an example:
python
1import bm25s
2from bm25s.hf import BM25HF
34# Load the index5retriever = BM25HF.load_from_hub("tien314/bm25s-version2")67# You can retrieve now8query ="a cat is a feline"9results = retriever.retrieve(bm25s.tokenize(query), k=3)
Saving a bm25s index
You can save a bm25s index to the Hugging Face Hub. Here is an example:
python
1import bm25s
2from bm25s.hf import BM25HF
34corpus =[5"a cat is a feline and likes to purr",6"a dog is the human's best friend and loves to play",7"a bird is a beautiful animal that can fly",8"a fish is a creature that lives in water and swims",9]1011retriever = BM25HF(corpus=corpus)12retriever.index(bm25s.tokenize(corpus))1314token =None# You can get a token from the Hugging Face website15retriever.save_to_hub("tien314/bm25s-version2", token=token)
Advanced usage
You can leverage more advanced features of the BM25S library during load_from_hub:
python
1# Load corpus and index in memory-map (mmap=True) to reduce memory2retriever = BM25HF.load_from_hub("tien314/bm25s-version2", load_corpus=True, mmap=True)34# Load a different branch/revision5retriever = BM25HF.load_from_hub("tien314/bm25s-version2", revision="main")67# Change directory where the local files should be downloaded8retriever = BM25HF.load_from_hub("tien314/bm25s-version2", local_dir="/path/to/dir")910# Load private repositories with a token:11retriever = BM25HF.load_from_hub("tien314/bm25s-version2", token=token)
Tokenizer
If you have saved a Tokenizer object with the index using the following approach: