Skip to navigation

nemo_curator.stages.audio.inference.asr.stage

View as Markdown

Generic audio ASR Curator stage with a pluggable adapter.

Curator-side glue validates I/O, resolves per-task language, and writes predictions. The concrete adapter is resolved at runtime from adapter_target via hydra.utils.get_class.

Module Contents

Classes

NameDescription
ASRStageAudio speech-recognition stage with a pluggable adapter.

Functions

NameDescription
_set_note-

Data

_CHANNEL_FIRST_DIMENSIONS

_LANG_CODE_TO_NAME

_MONO_DIMENSIONS

_NOTES_KEY

_PADDED_SECONDS_ABS_TOL

_PADDED_SECONDS_REL_TOL

_SKIP_ME_KEY

API

class nemo_curator.stages.audio.inference.asr.stage.ASRStage(
adapter_target: str,
model_id: str,
max_audio_sec_per_actor: float,
name: str = 'ASR_inference',
audio_filepath_key: str = 'resampled_audio_filepath',
waveform_key: str | None = None,
sample_rate_key: str = 'sampling_rate',
target_sample_rate: int = 16000,
keep_waveform: bool = False,
source_lang_key: str = 'source_lang',
default_language: str | None = None,
supported_language_codes: list[str] | None = None,
pred_text_key: str = 'pred_text',
language_key: str | None = None,
extras_key: str | None = None,
skip_me_key: str = _SKIP_ME_KEY,
notes_key: str = _NOTES_KEY,
unsupported_language_marks_skip: bool = True,
unsupported_language_skip_reason: str | None = None,
preserve_existing_skip: bool = False,
missing_language_is_unsupported: bool = False,
skip_if_output_exists: bool = False,
fail_on_audio_error: bool = False,
prefetch_fail_on_error: bool = True,
adapter_kwargs: dict[str, typing.Any] = dict(),
resources: nemo_curator.stages.resources.Resources = (lambda: Resources(gpus=1.0...,
batch_size: int = 32,
max_inference_duration_s: float = 2400.0,
local_bucketing: bool = False,
num_workers_override: int | None = None
)
Dataclass

Bases: AdapterInferenceStage[ASRAdapter]

Audio speech-recognition stage with a pluggable adapter.

The stage writes pred_text_key and optional control columns _skipme and additional_notes. When extras_key is configured, it also writes non-empty adapter metadata as one nested dictionary under that key.

Audio longer than max_inference_duration_s is always split into model-safe segments and stitched back to one result per parent row. Every segment prepared by one backend-provided process_batch call is packed into adapter calls bounded by max_audio_sec_per_actor. Enabling local_bucketing first orders those segments by duration to reduce GPU padding; disabling it preserves their input order.

adapter_kwargs
dict[str, Any] = field(default_factory=dict)
adapter_target
str
audio_filepath_key
str = 'resampled_audio_filepath'
batch_size
int = 32
default_language
str | None = None
extras_key
str | None = None
fail_on_audio_error
bool = False
keep_waveform
bool = False
language_key
str | None = None
local_bucketing
bool = False
max_audio_sec_per_actor
float
max_inference_duration_s
float = 2400.0
missing_language_is_unsupported
bool = False
model_id
str
name
str = 'ASR_inference'
notes_key
str = _NOTES_KEY
num_workers_override
int | None = None
pred_text_key
str = 'pred_text'
prefetch_fail_on_error
bool = True
preserve_existing_skip
bool = False
resources
Resources
sample_rate_key
str = 'sampling_rate'
skip_if_output_exists
bool = False
skip_me_key
str = _SKIP_ME_KEY
source_lang_key
str = 'source_lang'
supported_language_codes
list[str] | None = None
target_sample_rate
int = 16000
unsupported_language_marks_skip
bool = True
unsupported_language_skip_reason
str | None = None
waveform_key
str | None = None
nemo_curator.stages.audio.inference.asr.stage.ASRStage.__post_init__() -> None
nemo_curator.stages.audio.inference.asr.stage.ASRStage._build_items(
) -> list[dict[str, typing.Any]]
nemo_curator.stages.audio.inference.asr.stage.ASRStage._create_adapter() -> nemo_curator.models.asr.base.ASRAdapter

Construct the configured ASR adapter.

nemo_curator.stages.audio.inference.asr.stage.ASRStage._fits_audio_budget(
padded_seconds: float
) -> bool

Treat representation-level equality as within the configured budget.

nemo_curator.stages.audio.inference.asr.stage.ASRStage._is_language_supported(
item: dict[str, typing.Any]
) -> bool
nemo_curator.stages.audio.inference.asr.stage.ASRStage._load_audio(
audio_filepath: str
) -> tuple[numpy.ndarray, int]
staticmethod

Open one resampled file inside the ASR worker.

torchaudio.load returns channel-first audio. Resampled pipeline inputs are normally mono, so squeezing removes that singleton channel; multichannel inputs remain channel-first for _prepare_waveform to downmix.

nemo_curator.stages.audio.inference.asr.stage.ASRStage._normalise_supported_language_codes(
value: object
) -> set[str] | None
staticmethod

Normalize an optional adapter-specific supported-language allowlist.

nemo_curator.stages.audio.inference.asr.stage.ASRStage._pack_duration_sorted(
indexed_items: list[tuple[int, dict[str, typing.Any], float]]
) -> list[tuple[list[int], list[dict[str, typing.Any]]]]

Find the exact lexicographic optimum over sorted contiguous spans.

nemo_curator.stages.audio.inference.asr.stage.ASRStage._pack_in_order(
indexed_items: list[tuple[int, dict[str, typing.Any], float]]
) -> list[tuple[list[int], list[dict[str, typing.Any]]]]

Greedily preserve input order while enforcing padded capacity.

nemo_curator.stages.audio.inference.asr.stage.ASRStage._partition_inference_tasks(
) -> tuple[list[nemo_curator.tasks.AudioTask], int]
nemo_curator.stages.audio.inference.asr.stage.ASRStage._plan_adapter_batches(
items: list[dict[str, typing.Any]]
) -> list[tuple[list[int], list[dict[str, typing.Any]]]]

Optimally pack one finite segment list under the padded-audio budget.

The proxy cost of an adapter call is its longest audio duration times its item count. This models the padded tensor work more closely than a sum of unpadded durations. With local bucketing enabled, dynamic programming over the stable duration order first minimizes adapter-call count and then total padded seconds. The budget is enforced in both modes.

nemo_curator.stages.audio.inference.asr.stage.ASRStage._prepare_waveform(
waveform: object,
sample_rate: object
) -> numpy.ndarray

Return contiguous mono float32 samples at target_sample_rate.

nemo_curator.stages.audio.inference.asr.stage.ASRStage._resolve_language(
) -> str | None
nemo_curator.stages.audio.inference.asr.stage.ASRStage._resolve_language_code(
) -> str | None
nemo_curator.stages.audio.inference.asr.stage.ASRStage._resolve_skip_reason(
) -> str

Return the configured machine-readable reason for a skipped result.

nemo_curator.stages.audio.inference.asr.stage.ASRStage._run_adapter_batches(
items: list[dict[str, typing.Any]]

Run capacity-bounded adapter calls and restore segment order.

nemo_curator.stages.audio.inference.asr.stage.ASRStage._stitch_chunk_results(
staticmethod

Join ordered chunk outputs into one parent-row result.

nemo_curator.stages.audio.inference.asr.stage.ASRStage._validate_max_audio_sec_per_actor(
value: object
) -> float
staticmethod
nemo_curator.stages.audio.inference.asr.stage.ASRStage._write_language_result(
item: dict[str, typing.Any],
) -> None

Write the configured language output or routing notes.

nemo_curator.stages.audio.inference.asr.stage.ASRStage.assemble(
items: list[dict[str, typing.Any]],

Write adapter results to tasks.

nemo_curator.stages.audio.inference.asr.stage.ASRStage.num_workers() -> int | None

Return an explicit backend worker count when configured.

nemo_curator.stages.audio.inference.asr.stage.ASRStage.outputs() -> tuple[list[str], list[str]]
nemo_curator.stages.audio.inference.asr.stage.ASRStage.process(
nemo_curator.stages.audio.inference.asr.stage.ASRStage.process_batch(

Run one ASR batch.

nemo_curator.stages.audio.inference.asr.stage.ASRStage.run_inference(
items: list[dict[str, typing.Any]]

Transcribe one stage batch via the adapter.

nemo_curator.stages.audio.inference.asr.stage._set_note(
task_data: dict[str, typing.Any],
stage_name: str,
value: str,
notes_key: str = _NOTES_KEY
) -> None
nemo_curator.stages.audio.inference.asr.stage._CHANNEL_FIRST_DIMENSIONS = 2
nemo_curator.stages.audio.inference.asr.stage._LANG_CODE_TO_NAME: dict[str, str] = {'ar': 'Arabic', 'bg': 'Bulgarian', 'bn': 'Bengali', 'cs': 'Czech', 'da': 'Danis...
nemo_curator.stages.audio.inference.asr.stage._MONO_DIMENSIONS = 1
nemo_curator.stages.audio.inference.asr.stage._NOTES_KEY = 'additional_notes'
nemo_curator.stages.audio.inference.asr.stage._PADDED_SECONDS_ABS_TOL = 1e-09
nemo_curator.stages.audio.inference.asr.stage._PADDED_SECONDS_REL_TOL = 1e-12
nemo_curator.stages.audio.inference.asr.stage._SKIP_ME_KEY = '_skipme'