Character-Level N-Gram Model
Chlengmo: ("Kling-mo") A lean, simple, fast character-level n-gram model. Faster than NLTK. Zero dependencies.
Sample Usage
# retrieve corpus from NLTK
# NOTE: NLTK is not a dependency, only using it to fetch a training corpus.
filename = "melville-moby_dick.txt"
text = gutenberg.raw(filename)
start = "Call me Ishmael"
start_idx = text.index(start)
text = text[start_idx:]
# 15-gram model
model = Chlengmo(n=15).fit(text)
model.generate(length=981, prompt="Call me ", seed=42)
Call me Ishmael . Some years ago -- never mind how long precisely -- who knows ? Certain I am , however , the sperm whale ' s food ; and , also , calling to mind the regular , ascertained seasons for hunting him in particular that , in the internal parts of the vessel ; the becharmed crew maintaining the profoundest homage ; yea , an all - abounding adoration ! for almost all the tapers , lamps , and candles that burn round the globe , by girdling it with guineas , one to every three parts of an inch ; stabbing him in the ventricles of his heart . He was in Radney the chief mate , said ,--" Take the rope , sir -- I give it into thy hands , Starbuck watched the Pequod ' s jaw - bone tiller had several times descended from heaven by the way of this fire - ship on the sea . A short space elapsed , and up into this noiselessness came Ahab alone from his cabin . He was a small , short , youngish man , sprinkled all over his face with freckles , and wearing redundant yellow hair .
Unit Tests
# from inside the tests/ subfolder
cd tests/
# create virtual environment
virtualenv .venv
. .venv/bin/activate
# install unit test dependencies
python3 -m pip install -r requirements.txt
# run unit tests
pytest
# run coverage report
coverage run -m pytest
coverage report
coverage html
open htmlcov/index.html
# cleanup
deactivate
rm -rf .venv
Notebooks
REF: https://janakiev.com/blog/jupyter-virtual-envs/
# from inside the notebooks/ subfolder
cd notebooks/
# create virtual environment
virtualenv .venv
. .venv/bin/activate
# install notebook dependencies
python3 -m pip install -r requirements.txt
# create jupyter kernel
python3 -m pip install ipykernel
python3 -m ipykernel install --user --name=.venv
# exit virtual environment & run jupyter
deactivate
PYTHONPATH=../ jupyter notebook
# cleanup
rm -rf .venv
Metadata
Release files for chlengmo 0.0.4
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 |
|---|---|---|---|---|
| chlengmo-0.0.4.tar.gz | 4.4 kB | Without provenance | Details for chlengmo-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chlengmo-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for chlengmo-0.0.4-py3-none-any.whl |
Total release size: 9.2 kB
Release files / chlengmo-0.0.4.tar.gz
| Download URL | chlengmo-0.0.4.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7daf05845bf31dfa63752f962bd13f16ca3cf58504b5ce01a678c34f9a99c8ef
|
|
BLAKE2b-256 checksum How to use checksums |
9825ae8fca879361ebc78c9e2d6c7f1df8066a0fe0b76cba98d92975feab13b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / chlengmo-0.0.4-py3-none-any.whl
| Download URL | chlengmo-0.0.4-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
042b0c3fd8a2760a9c1775bb423f0ed7e9c4455bd4fd03090704b6f36fae57a4
|
|
BLAKE2b-256 checksum How to use checksums |
ae13d455373557b30fbb8df66b2911991dfe1aee0e47e0173280dd9fa8d7aeae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for chlengmo 0.0.4
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.