Registry / ai-ml / kenlm
library0.3.0pypypiunverified

KenLM is a Python bindings package for the KenLM language model toolkit. It provides efficient querying of n-gram language models (ARPA format) for tasks like speech recognition, machine translation, and text generation. The current version is 0.3.0, with irregular release cadence.

pip install kenlm
INSTALL
IMPORT
SIG · KENLM
K
kenlm
ai-mlpythonv0.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Model
import kenlm model = kenlm.Model('model.arpa')
from kenlm import Model
Model class is not directly importable from kenlm; use kenlm.Model.

Load an ARPA format language model and score a sentence.

import kenlm model = kenlm.Model('test.arpa') score = model.score('hello world', bos=True, eos=True) print(f'Score: {score}') full_scores = list(model.full_scores('hello world', bos=True, eos=True)) print(f'Full scores: {full_scores}')
Debug
Known issues
gotchaThe Model class is not directly importable; use `import kenlm` then `kenlm.Model`.
fix
Always use `import kenlm; model = kenlm.Model('path')`.
affects: all
gotchaFull scores are returned as a generator; must be converted to list for indexing.
fix
Use `list(model.full_scores(...))` to access individual n-gram scores.
affects: all
breakingPrecompiled wheels on PyPI do not support arm64 (Apple Silicon) or manyLinux aarch64. Users must compile from source.
fix
Install Cython and build from source on arm64/aarch64: `pip install cython; pip install kenlm --no-binary kenlm`.
affects: <=0.3.0
Upgrade
Version history
0.3.0latest on PyPI · released Apr 7, 2025
Audit
Dependencies
cythonoptionalRequired to build from source if precompiled wheels are unavailable.
Agent activity
4 hits · last 30 days
node
4
Resources

No resource links recorded.

kenlm — pip install kenlm · libregistry