Skip to main content

Modified Kneser-ney Smoothing Language Model

Project description


Modified Kneser-Ney smoothing language model module for Python


$ pip install knlm
$ pip3 install knlm


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'):
    # load model from binary file
    mdl = KneserNey.load('language.model')
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.2.tar.gz (10.8 kB view hashes)

Uploaded source

Built Distributions

knlm-0.1.2-cp37-cp37m-win_amd64.whl (185.6 kB view hashes)

Uploaded 3 7

knlm-0.1.2-cp37-cp37m-win32.whl (162.4 kB view hashes)

Uploaded 3 7

knlm-0.1.2-cp36-cp36m-win_amd64.whl (185.6 kB view hashes)

Uploaded 3 6

knlm-0.1.2-cp36-cp36m-win32.whl (162.4 kB view hashes)

Uploaded 3 6

knlm-0.1.2-cp35-cp35m-win_amd64.whl (185.6 kB view hashes)

Uploaded 3 5

knlm-0.1.2-cp35-cp35m-win32.whl (162.4 kB view hashes)

Uploaded 3 5

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page