KenLM-V1 / load_decoder.py
VynoDePal's picture
Publish v1.0.0: KenLM-V1 frozen profiles
2f3ecc3 verified
Raw
History Blame Contribute Delete
694 Bytes
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