| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| from pyctcdecode import build_ctcdecoder | |
| def load_decoder(repo_dir, labels, language, domain, profile="current_model_036878"): | |
| root = Path(repo_dir) | |
| config = json.loads((root / "profiles" / f"{profile}.json").read_text()) | |
| group = f"{language}|{domain}" | |
| route = config["routes"][group] | |
| unigrams = (root / route["unigrams"]).read_text(encoding="utf-8").splitlines() | |
| decoder = build_ctcdecoder( | |
| labels, | |
| str(root / route["binary"]), | |
| unigrams=unigrams, | |
| alpha=float(route["alpha"]), | |
| beta=float(route["beta"]), | |
| ) | |
| return decoder, int(route["beam"]), route | |