Modified Kneser-ney Smoothing Language Model
Project description
== knlm ==
Modified Kneser-Ney smoothing language model module for Python
=== Installation ===
pip install knlm
pip3 install knlm
=== Example ===
from knlm import KneserNey
mode = 'build'
if mode == 'build':
# build model from corpus text. order = 3, word size = 4 byte
mdl = KneserNey(3, 4)
for line in open('corpus.txt', encoding='utf-8'):
mdl.train(line.lower().strip().split())
mdl.optimize()
mdl.save('language.model')
else:
# load model from binary file
mdl = KneserNey.load('language.model')
print('Loaded')
print('Order: %d, Vocab Size: %d, Vocab Width: %d' % (mdl.order, mdl.vocabs, mdl._wsize))
# evaluate sentence score
print(mdl.evaluateSent('I love kiwi .'.split()))
print(mdl.evaluateSent('ego kiwi amo .'.split()))
# evaluate scores for each word
print(mdl.evaluateEachWord('I love kiwi .'.split()))
print(mdl.evaluateEachWord('ego kiwi amo .'.split()))
Modified Kneser-Ney smoothing language model module for Python
=== Installation ===
pip install knlm
pip3 install knlm
=== Example ===
from knlm import KneserNey
mode = 'build'
if mode == 'build':
# build model from corpus text. order = 3, word size = 4 byte
mdl = KneserNey(3, 4)
for line in open('corpus.txt', encoding='utf-8'):
mdl.train(line.lower().strip().split())
mdl.optimize()
mdl.save('language.model')
else:
# load model from binary file
mdl = KneserNey.load('language.model')
print('Loaded')
print('Order: %d, Vocab Size: %d, Vocab Width: %d' % (mdl.order, mdl.vocabs, mdl._wsize))
# evaluate sentence score
print(mdl.evaluateSent('I love kiwi .'.split()))
print(mdl.evaluateSent('ego kiwi amo .'.split()))
# evaluate scores for each word
print(mdl.evaluateEachWord('I love kiwi .'.split()))
print(mdl.evaluateEachWord('ego kiwi amo .'.split()))
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
knlm-0.1.0.tar.gz
(10.8 kB
view hashes)
Built Distributions
knlm-0.1.0-cp37-cp37m-win_amd64.whl
(186.2 kB
view hashes)
knlm-0.1.0-cp37-cp37m-win32.whl
(162.7 kB
view hashes)
knlm-0.1.0-cp36-cp36m-win_amd64.whl
(186.2 kB
view hashes)
knlm-0.1.0-cp36-cp36m-win32.whl
(162.7 kB
view hashes)
knlm-0.1.0-cp35-cp35m-win_amd64.whl
(186.2 kB
view hashes)
knlm-0.1.0-cp35-cp35m-win32.whl
(162.7 kB
view hashes)
Close
Hashes for knlm-0.1.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6b356b4f5a3526d3b6fc6cb00979ecaf3c5a4cf9da256e841c524da7f0df981 |
|
MD5 | f4baf7ebd2290086e7f6a5b68c03b935 |
|
BLAKE2b-256 | 9457c622d0944ed5e9059c437793fbe4b015a03144fbaac32486addfed66cb59 |
Close
Hashes for knlm-0.1.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea10fe7b605723f49188fbfae63f4a8ea48bf094d9e1ab973c42e5b6e3feedee |
|
MD5 | f5e500f90f860da9852efcadb85bc435 |
|
BLAKE2b-256 | d4a065ddabc370965dc886006bd9b8f1dde2c99b791a42586526e3337abe2d4e |
Close
Hashes for knlm-0.1.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78cbf3a82d5b22967905bc23cf8cf49a539dcf2b14541d00b09314864824da38 |
|
MD5 | 4e83764b35571d7c57ccf4e2837e75c7 |
|
BLAKE2b-256 | bad3c01a2869b07022ffd0f36dda8e5f43c8c9ec900202bc157be24553227b01 |