espnet3.systems.base.inference_runner.InferenceRunner
About 1 min
espnet3.systems.base.inference_runner.InferenceRunner
class espnet3.systems.base.inference_runner.InferenceRunner(provider: EnvironmentProvider, , idx_key: str = 'idx', hyp_key: str | Sequence[str] = 'hyp', ref_key: str | Sequence[str] = 'ref', **kwargs)
Bases: BaseRunner
Inference runner with strict output-format validation.
This runner implements forward to call a recipe-provided output function. The key names are configurable via idx_key and hyp_key/ref_key. hyp_key and ref_key may be a single string or a list of strings to support multiple hypothesis/reference fields.
Output format requirements: : - The result is a dict with exactly the configured keys.
idx_keyvalue is a scalar (list/tuple is not allowed).hyp_keyandref_keyvalues may be scalars or lists/tuples. If lists are returned, each entry is written to its own SCP file (e.g.,hyp0.scp,hyp1.scp).
Initialize the inference runner with output key settings.
static forward(idx, dataset=None, model=None, **kwargs)
Run inference for one dataset item and return output dict.
- Parameters:
- idx – Integer index into the dataset.
- dataset – Dataset providing inference entries.
- model – Inference model callable on the configured input.
- **kwargs – Expects
input_keyandoutput_fn_path.
- Returns: Dict containing
idxand output fields for a single item, or a list of dicts for batched inputs (as returned byoutput_fn). - Raises:
- RuntimeError – If required I/O settings are missing.
- KeyError – If required input keys are missing from the dataset item(s).
- RuntimeError – If batched inference fails; includes guidance to disable batching when unsupported.
Notes
input_keymay be a string or a list/tuple of strings.- Batched inputs are passed to the model as lists per key; padding is the model’s responsibility.
Examples
>>> # Single-item inference
>>> out = InferenceRunner.forward(
... 0, dataset=dataset, model=model,
... input_key="speech", output_fn_path="m.mod.out_fn"
... )
>>> # Batched inference
>>> out = InferenceRunner.forward(
... [0, 1], dataset=dataset, model=model,
... input_key=["speech", "text"], output_fn_path="m.mod.out_fn"
... )