Skip to main content

Crate kenlm

Crate kenlm 

Source
Expand description

Safe Rust bindings for KenLM language model inference.

The crate compiles KenLM’s query-only C++ sources and exposes a small Rust API for loading ARPA or binary models, scoring sentences, inspecting vocabulary membership, and doing explicit stateful scoring.

§Safety model

The public API is safe Rust. C++ exceptions are caught in the C++ shim and converted into KenlmError values. Opaque State values carry an internal model identity token, so stateful scoring rejects states created by a different Model before calling into KenLM. The raw KenLM model handle is owned by Model and released exactly once in Drop.

Structs§

Config
Runtime loading options for KenLM models.
FullScore
Detailed score metadata for one state transition.
Model
A KenLM model loaded from an ARPA or KenLM binary file.
State
Opaque KenLM state memory used for incremental scoring.
TokenScore
Sentence-level per-token score, including OOV metadata.

Enums§

ArpaLoadComplain
How loudly KenLM should complain about loading ARPA instead of binary data.
KenlmError
Errors returned by the KenLM bindings.
LoadMethod
How KenLM should bring binary model data into memory.

Type Aliases§

Result
Crate-local result type.
WordIndex
KenLM vocabulary index.