BagModels
BagModels is a repository of various bag of words (BoW) algorithms in machine learning. Currently it includes OkapiBM25. More coming soon.
BM25 is a text retrieval function that can find similar documents or rank search in a set of documents based on the query terms appearing in each document irrespective of their proximity to each other. It is an improved and more generalised version of TF-IDF algorithm in NLP.
Installation
It can be installed using pip:
pip install bagmodels
Getting started
Basic usage
import re
from bagmodels import BM25
# Load corpus
corpus = list({
"Yo, I love NLP model",
"I like algorithms",
"I love ML!"
})
# Clean manually if needed or pass custom tokenizer to BM25
corpus = [re.sub(r",|!", " ", doc).strip() for doc in corpus]
# Initialize model
model = BM25(corpus=corpus)
# Similarity
model.similarity("I love NLP model", "I like NLP model") # 0.775
model.similarity("I love blah", "I love algorithms") # 0.446
Save and reuse models
# libaries imported and corpus already loaded before it
model = BM25(corpus=corpus)
# write to save path
model.save("output/bm25_v1.jbl")
# load again
model = BM25.load("output/bm25_v1.jbl")
# add documents if required
model.resume(corpus=additonal_corpus)
# predict / search / find / retrieve like
model.similarity(doc_a, doc_b)
Coming soon
Please feel free to open an issue to request a feature or discuss any changes. Pull requests are most welcome.
I am trying to actively add the following:
- OkapiBM25
- BM25 variations
- MultiThreading
Metadata
Release files for bagmodels 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bagmodels-0.1.5.tar.gz | 5.8 kB | Without provenance | Details for bagmodels-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bagmodels-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for bagmodels-0.1.5-py3-none-any.whl |
Total release size: 12.4 kB
Release files / bagmodels-0.1.5.tar.gz
| Download URL | bagmodels-0.1.5.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4e62e85b3fd2709f522be2274156ea174ec0ef43fbe232a7f5673e2c87b3b7bf
|
|
BLAKE2b-256 checksum How to use checksums |
85ab4375930b04565164e60aceae51146e9628f1a68916d2c01cb39d67cf71d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.13
|
Release files / bagmodels-0.1.5-py3-none-any.whl
| Download URL | bagmodels-0.1.5-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
19c74c5738736e5c2f503bc59357d98a89d0d4f7ba8f360972c2a634ebf9873d
|
|
BLAKE2b-256 checksum How to use checksums |
a99232d4b985d1477c5b48195b9af8890641c88e95cdd0ae7d659947d2aad253
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.13
|
Security for bagmodels 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.