Skip to main content

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()))

Project details


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)

Uploaded Source

Built Distributions

knlm-0.1.0-cp37-cp37m-win_amd64.whl (186.2 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

knlm-0.1.0-cp37-cp37m-win32.whl (162.7 kB view hashes)

Uploaded CPython 3.7m Windows x86

knlm-0.1.0-cp36-cp36m-win_amd64.whl (186.2 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

knlm-0.1.0-cp36-cp36m-win32.whl (162.7 kB view hashes)

Uploaded CPython 3.6m Windows x86

knlm-0.1.0-cp35-cp35m-win_amd64.whl (186.2 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

knlm-0.1.0-cp35-cp35m-win32.whl (162.7 kB view hashes)

Uploaded CPython 3.5m Windows x86

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page