Registry / ai-ml / kaldialign

kaldialign

JSON →
library0.11.0pypypi✓ verified 85d ago

kaldialign is a Python package that provides wrappers for Kaldi's core alignment and edit distance computation functions. It directly incorporates Kaldi's C++ code via pybind11 to ensure identical Word Error Rate (WER) and alignment results as Kaldi, addressing inconsistencies found in other Levenshtein implementations. Currently at version 0.9.3, it receives regular updates focusing on performance enhancements and broader platform compatibility through pre-built wheels.

pip install kaldialign
INSTALL
IMPORT
SIG · KALDIALIGN
K
kaldialign
ai-mlpythonv0.11.0
Install
1.6s avg
Import
91ms
Disk
16MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.11.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.091s · 19MB
16MB installed
● package 16MB
Code
Verified usage

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

align
from kaldialign import align
edit_distance
from kaldialign import edit_distance
bootstrap_wer_ci
from kaldialign import bootstrap_wer_ci

This quickstart demonstrates the core `align` and `edit_distance` functions, as well as the `bootstrap_wer_ci` method for calculating Word Error Rate confidence intervals. The `epsilon_symbol` for `align` must be a character not present in either sequence to represent insertions/deletions.

from kaldialign import align, edit_distance, bootstrap_wer_ci # Example 1: Basic Alignment ref_seq = ['hello', 'world', 'this', 'is', 'a', 'test'] hyp_seq = ['hello', 'this', 'was', 'a', 'test'] epsilon_symbol = '*' alignment = align(ref_seq, hyp_seq, epsilon_symbol) print(f"Alignment: {alignment}") # Expected: [('hello', 'hello'), ('world', '*'), ('*', 'this'), ('this', 'was'), ('is', '*'), ('a', 'a'), ('test', 'test')] # Example 2: Edit Distance (Insertions, Deletions, Substitutions) ed_results = edit_distance(ref_seq, hyp_seq) print(f"Edit Distance: {ed_results}") # Expected: {'ins': 1, 'del': 2, 'sub': 1, 'total': 4} # Example 3: Bootstrapping WER Confidence Intervals (since v0.8.0) # ref and hyp should be lists of lists of words (representing sentences) # E.g., [['sentence', 'one'], ['sentence', 'two']] and [['sentece', 'one'], ['sentence', 'too']] ref_utterances = [['the', 'quick', 'brown', 'fox'], ['jumps', 'over', 'the', 'lazy', 'dog']] hyp_utterances = [['the', 'quik', 'brown', 'fox'], ['jump', 'over', 'the', 'lazi', 'dog']] wer_ci = bootstrap_wer_ci(ref_utterances, hyp_utterances) print(f"WER 95% Confidence Interval: {wer_ci}")
Debug
Known issues
gotchaWhen using `align()`, the `epsilon` parameter must be a 'null' symbol (e.g., `'*'`) that is guaranteed not to appear in any of the input sequence elements (words/characters). If `epsilon` is present in the sequences, it can lead to incorrect alignment results.
fix
Choose an `epsilon` symbol (like `*` or `_`) that is unique and known not to exist in your reference or hypothesis sequences.
affects: All versions
gotchaThe `bootstrap_wer_ci` function, introduced in v0.8.0 and significantly optimized in v0.9.0, now performs its core computation in C++ for a 15x speed improvement. While this boosts performance, it means that the underlying logic for bootstrapping cannot be directly inspected or modified via Python.
fix
Be aware that the implementation is now C++-based. Rely on the provided Python interface for its functionality.
affects: >=0.9.0
gotchaFor computing WER or alignments using `sclite` style weights (insertion/deletion cost 3, substitution cost 4), you must explicitly pass `sclite_mode=True` to the `align()` or `edit_distance()` functions. The default behavior aligns with standard Kaldi weights.
fix
If `sclite`-style scoring is required, ensure your function call includes `sclite_mode=True`, e.g., `edit_distance(ref, hyp, sclite_mode=True)`.
affects: >=0.7.0
Errors
Common errors & fixes
CMake Error at CMakeLists.txt:...
This error typically occurs when attempting to install `kaldialign` from source without a properly configured C++ compiler and CMake build system. A specific bug related to `CMakeLists.txt` not being found was fixed in v0.4.0, but general build environment issues can still lead to this.
fix
For most users, `pip install kaldialign` should download a pre-built wheel, avoiding compilation. If building from source is necessary, ensure you have CMake and a C++ compiler (like GCC or Clang) installed and accessible in your system's PATH.
ImportError: cannot import name 'align' from 'kaldialign'
This indicates that the `kaldialign` Python package, or its underlying C++ extensions, were not correctly installed or are not accessible in your current Python environment. This can happen due to partial installations, conflicting packages, or environment issues.
fix
Try reinstalling the package in a clean virtual environment: `python -m venv .venv && source .venv/bin/activate && pip install --no-cache-dir kaldialign`. If errors persist, check the full installation log for compilation failures.
Upgrade
Version history
0.11.0latest on PyPI · released Jun 11, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
kaldialign — pip install kaldialign · libregistry