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
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.2.tar.gz
(10.8 kB
view hashes)
Built Distributions
knlm-0.1.2-cp37-cp37m-win_amd64.whl
(185.6 kB
view hashes)
knlm-0.1.2-cp37-cp37m-win32.whl
(162.4 kB
view hashes)
knlm-0.1.2-cp36-cp36m-win_amd64.whl
(185.6 kB
view hashes)
knlm-0.1.2-cp36-cp36m-win32.whl
(162.4 kB
view hashes)
knlm-0.1.2-cp35-cp35m-win_amd64.whl
(185.6 kB
view hashes)
knlm-0.1.2-cp35-cp35m-win32.whl
(162.4 kB
view hashes)
Close
Hashes for knlm-0.1.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 748296ad60328472334a60a0a472b5106735400304c836d152b60e003bb64a39 |
|
MD5 | cc5702eda288c046e99fd51be6e02fe6 |
|
BLAKE2b-256 | 0e9dce9c73fbae1189ce2692435d7847b44e282687e917281eaa7a122d9e9ebe |
Close
Hashes for knlm-0.1.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 599a06f68ef58d8b5fcc2098e02f47d1eebf0f6d33bb11b97fbb3a21fa66c51b |
|
MD5 | a705b3a6d0e89b888a41c8ee3588bea6 |
|
BLAKE2b-256 | d1996622b4a66b40b0365e09a89d0f0f92a18a062c004d2cac11e7afcf637933 |
Close
Hashes for knlm-0.1.2-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f5471db52e5e5ffe2e1d5eb390346d3c0707cb8806d6a14a4955612ae3de472 |
|
MD5 | d8a8b531741b5fc4734c7f1309ccfee3 |
|
BLAKE2b-256 | 5b44dbc7b3a03055c9338f35604e930a4643478ee67818f4475622d6f7de6a76 |