File size: 694 Bytes
2f3ecc3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

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