'Offline English dictation using a compact Citrinet CTC model.' import json from pathlib import Path from zipfile import ZipFile import numpy as np import onnx import onnxruntime as ort from onnx import numpy_helper BLANK = 1024 OUTPUT_HOP = 1280 def restore_encoder(archive, expose_hidden=False, transform=None): graph = onnx.load_model_from_string(archive.read("encoder.onnx")) manifest = json.loads(archive.read("quantization.json")) qdata = np.frombuffer(archive.read("weights.q4"), dtype=np.uint8) scales = np.frombuffer(archive.read("scales.f16"), dtype="> 4 values -= 8 row_scales = scales[scale_offset:scale_offset + count].astype(np.float32) dequantized = values.reshape(count, group_size) * row_scales[:, None] matrix = dequantized.reshape(rows, -1)[:, :columns].reshape(shape) graph.graph.initializer.append(numpy_helper.from_array(matrix, name)) byte_offset += nbytes scale_offset += count if byte_offset != len(qdata) or scale_offset != len(scales): raise ValueError("The packed model has extra data") if "int8_tensors" in manifest: qdata = np.frombuffer(archive.read("weights.i8"), dtype=np.int8) scales = np.frombuffer(archive.read("scales-i8.f16"), dtype="