A fast Character-Level N-Gram Model
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file chlengmo-0.0.4.tar.gz
.
File metadata
- Download URL: chlengmo-0.0.4.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7daf05845bf31dfa63752f962bd13f16ca3cf58504b5ce01a678c34f9a99c8ef |
|
MD5 | 8fcb8df2128c320a54f256dadd032e4a |
|
BLAKE2b-256 | 9825ae8fca879361ebc78c9e2d6c7f1df8066a0fe0b76cba98d92975feab13b2 |
File details
Details for the file chlengmo-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: chlengmo-0.0.4-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 042b0c3fd8a2760a9c1775bb423f0ed7e9c4455bd4fd03090704b6f36fae57a4 |
|
MD5 | 1cf4403085377f2ea52628d192cad14a |
|
BLAKE2b-256 | ae13d455373557b30fbb8df66b2911991dfe1aee0e47e0173280dd9fa8d7aeae |