espnet3.systems.base.inference_runner.InferenceRunner
espnet3.systems.base.inference_runner.InferenceRunner
class espnet3.systems.base.inference_runner.InferenceRunner(provider: EnvironmentProvider, idx_key: str = 'utt_id', 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. idx_key is the key used to map each inference result to its source dataset index when writing SCP files.
Output format requirements: : - The result is a dict with the configured keys plus any extra fields.
- A sample identifier key must exist under
idx_keyso SCP outputs can map each result back to the corresponding dataset sample. - The sample identifier must be a single value, not a list or tuple.
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.
- Parameters:
- provider – Environment provider that supplies dataset/model/env.
- idx_key – Output dict key used as the sample identifier written in the first column of each SCP line. This ties each inference result back to its dataset sample. Defaults to
"utt_id". - hyp_key – Hypothesis key or keys expected in the output dict.
- ref_key – Reference key or keys expected in the output dict.
- **kwargs – Forwarded to
BaseRunner.
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_keyand optionallyoutput_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 input 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"
... )resolve_idx_key(output: Dict[str, Any]) → str
Validate that the configured sample-identifier key exists in output.
