pyctcdecode is a Python library that provides a standalone beam search decoder for CTC (Connectionist Temporal Classification) models. It allows for efficient decoding of CTC outputs and seamlessly integrates with KenLM language models to improve speech recognition accuracy. The current version is 0.5.0, and it follows an active release cadence, with updates addressing features, performance, and bug fixes.
pip install pyctcdecodeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `BeamSearchDecoderCTC` with a custom alphabet and decode dummy CTC logits. It shows the basic usage without a language model. For real-world applications, integrating with a KenLM language model is highly recommended for improved accuracy.
For common Linux distributions, ensure development headers for `boost`, `zlib`, `bzip2`, and `cmake` are installed. For example: `sudo apt-get install libboost-all-dev liblzma-dev libbz2-dev cmake`. Then retry `pip install pyctcdecode[kenlm]` or consult KenLM's specific build instructions if issues persist.
Always construct your alphabet list by placing `BLANK_TOKEN` (or an empty string) as the first element. Example: `labels = [BLANK_TOKEN] + list('abc')`. Ensure the total length of the alphabet matches your model's CTC output dimension.Ensure the `.arpa` file exists and is accessible. Verify its format using KenLM's tools if possible. For very large models, consider reducing the beam width or using a smaller language model for initial testing to mitigate performance issues.
Install with KenLM support using `pip install pyctcdecode[kenlm]`. If this fails, review system dependencies for KenLM (Boost, Zlib, Bzip2, CMake) as described in the warnings.
Install Boost development headers on your system (e.g., `sudo apt-get install libboost-all-dev` on Debian/Ubuntu, or `brew install boost` on macOS). Ensure `cmake` is also installed. If Boost is in a non-standard location, you might need to manually set environment variables like `BOOST_ROOT` or `BOOST_INCLUDEDIR`.
Verify that your `labels` list used to create the `alphabet` has the `BLANK_TOKEN` (or an empty string) as its first element, and that the total length of your alphabet exactly matches the last dimension of your CTC model's output logits.