{"library":"pyctcdecode","title":"pyctcdecode","description":"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.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pyctcdecode","pip install pyctcdecode[kenlm]"],"cli":null},"imports":["from pyctcdecode import BeamSearchDecoderCTC","from pyctcdecode import LanguageModel","from pyctcdecode.alphabet import Alphabet","from pyctcdecode.alphabet import BLANK_TOKEN","from pyctcdecode.alphabet import get_alphabet"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from pyctcdecode import BeamSearchDecoderCTC\nfrom pyctcdecode.alphabet import BLANK_TOKEN, get_alphabet\nimport numpy as np\n\n# Define your model's alphabet. The BLANK_TOKEN must be the first element.\n# This example uses a common alphabet for English speech recognition.\nlabels = [BLANK_TOKEN] + list(\"abcdefghijklmnopqrstuvwxyz '\")\nalphabet = get_alphabet(labels)\n\n# Create dummy CTC output (logits) for demonstration.\n# In a real scenario, these would come from your deep learning model.\n# Shape: (time_steps, alphabet_size)\ntime_steps = 50\nlogits = np.random.rand(time_steps, len(labels)).astype(np.float32)\n\n# Initialize the decoder without a language model.\n# For better accuracy, integrate with a KenLM language model (see warnings).\ndecoder = BeamSearchDecoderCTC(alphabet)\n\n# Decode the logits. The decode method returns a list of hypotheses.\n# We take the first (most probable) one.\nhypotheses = decoder.decode(logits)\ndecoded_text = hypotheses[0]\n\nprint(f\"Decoded text (example): {decoded_text}\")\n","lang":"python","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}