Skip to navigation

nemo_curator.stages.audio.text_filtering

View as Markdown

Audio transcript filtering stages.

Submodules

Package Contents

Classes

NameDescription
AbbreviationConcatStageConcatenate spaced single-letter abbreviations in a transcript.
DisfluencyWerGuardStageRestore the original prediction when disfluency removal diverges.
RegexSubstitutionStageApply an ordered YAML list of regex substitutions to one transcript field.
SelectBestPredictionStageChoose one stable transcript from primary, recovery, or reference text.
WhisperHallucinationStageFlag transcripts that show common ASR hallucination patterns.

API

class nemo_curator.stages.audio.text_filtering.AbbreviationConcatStage(
text_key: str = 'text',
output_text_key: str = 'text',
skip_me_key: str = '_skipme',
notes_key: str = 'additional_notes',
source_lang_key: str = 'source_lang',
default_language: str = 'en',
name: str = 'AbbreviationConcat',
resources: nemo_curator.stages.resources.Resources = (lambda: Resources(cpus=1.0...
)
Dataclass

Bases: ProcessingStage[AudioTask, AudioTask]

Concatenate spaced single-letter abbreviations in a transcript.

default_language
str = 'en'
name
str = 'AbbreviationConcat'
notes_key
str = 'additional_notes'
output_text_key
str = 'text'
resources
Resources
skip_me_key
str = '_skipme'
source_lang_key
str = 'source_lang'
text_key
str = 'text'
nemo_curator.stages.audio.text_filtering.AbbreviationConcatStage.inputs() -> tuple[list[str], list[str]]
nemo_curator.stages.audio.text_filtering.AbbreviationConcatStage.outputs() -> tuple[list[str], list[str]]
nemo_curator.stages.audio.text_filtering.AbbreviationConcatStage.process(
class nemo_curator.stages.audio.text_filtering.DisfluencyWerGuardStage(
ref_text_key: str = 'qwen3_prediction_s1',
hyp_text_key: str = 'qwen3_prediction_s2',
wer_key: str = 'disfluency_wer',
max_wer_pct: float = 50.0,
skip_me_key: str = '_skipme',
language_key: str = 'source_lang',
name: str = 'DisfluencyWerGuard',
resources: nemo_curator.stages.resources.Resources = (lambda: Resources(cpus=1.0...
)
Dataclass

Bases: ProcessingStage[AudioTask, AudioTask]

Restore the original prediction when disfluency removal diverges.

The stage compares ref_text_key with the disfluency-cleaned text at hyp_text_key. It uses character error rate (CER) for languages written without word-separating spaces and word error rate (WER) otherwise. If the selected error rate exceeds max_wer_pct, the cleaned prediction is replaced with the original prediction.

The selected rate is stored in the compatibility field wer_key even when CER is used, matching the reference pipeline contract.

hyp_text_key
str = 'qwen3_prediction_s2'
language_key
str = 'source_lang'
max_wer_pct
float = 50.0
name
str = 'DisfluencyWerGuard'
ref_text_key
str = 'qwen3_prediction_s1'
resources
Resources
skip_me_key
str = '_skipme'
wer_key
str = 'disfluency_wer'
nemo_curator.stages.audio.text_filtering.DisfluencyWerGuardStage.inputs() -> tuple[list[str], list[str]]
nemo_curator.stages.audio.text_filtering.DisfluencyWerGuardStage.outputs() -> tuple[list[str], list[str]]
nemo_curator.stages.audio.text_filtering.DisfluencyWerGuardStage.process(
class nemo_curator.stages.audio.text_filtering.RegexSubstitutionStage(
regex_params_yaml: str = '',
text_key: str = 'pred_text',
output_text_key: str = 'text',
skip_me_key: str = '_skipme',
name: str = 'RegexSubstitution',
resources: nemo_curator.stages.resources.Resources = (lambda: Resources(cpus=1.0...
)
Dataclass

Bases: ProcessingStage[AudioTask, AudioTask]

Apply an ordered YAML list of regex substitutions to one transcript field.

The YAML document must be a list. Each rule must define string pattern and repl values and may define a non-negative integer count limit. Rules run in file order before whitespace is collapsed. Rows carrying an existing skip reason are not normalized. The empty-result skip is set only when cleaning removes non-whitespace input; already-empty input remains unskipped.

_rules
list[dict[str, Any]]
name
str = 'RegexSubstitution'
output_text_key
str = 'text'
regex_params_yaml
str = ''
resources
Resources
skip_me_key
str = '_skipme'
text_key
str = 'pred_text'
nemo_curator.stages.audio.text_filtering.RegexSubstitutionStage.__post_init__() -> None
nemo_curator.stages.audio.text_filtering.RegexSubstitutionStage.inputs() -> tuple[list[str], list[str]]
nemo_curator.stages.audio.text_filtering.RegexSubstitutionStage.outputs() -> tuple[list[str], list[str]]
nemo_curator.stages.audio.text_filtering.RegexSubstitutionStage.process(
nemo_curator.stages.audio.text_filtering.RegexSubstitutionStage.setup(
_worker_metadata: object | None = None
) -> None
class nemo_curator.stages.audio.text_filtering.SelectBestPredictionStage(
primary_text_key: str = 'primary_model_prediction',
fallback_text_key: str = 'fallback_model_prediction',
asr_text_key: str | None = None,
output_key: str = 'best_prediction',
source_key: str = 'best_prediction_source',
notes_key: str = 'additional_notes',
skip_me_key: str = '_skipme',
duration_key: str = 'duration',
language_key: str = 'source_lang',
min_agreement_pct: float = 80.0,
agreement_wer_key: str = 'primary_fallback_agreement...,
metric_key: str = 'primary_fallback_agreement...,
primary_source_label: str = 'primary',
fallback_source_label: str = 'fallback',
reference_text_key: str | None = None,
use_reference_on_hallucination: bool = False,
force_reference: bool = False,
use_ground_truth_for_short_audio: bool = True,
short_audio_threshold: float = 1.0,
primary_model_type: str | None = None,
reference_source_label: str = 'reference',
ground_truth_source_label: str = 'ground_truth',
name: str = 'SelectBestPrediction',
resources: nemo_curator.stages.resources.Resources = (lambda: Resources(cpus=1.0...
)
Dataclass

Bases: ProcessingStage[AudioTask, AudioTask]

Choose one stable transcript from primary, recovery, or reference text.

Selection is ordered so explicit reference policies run before model recovery. Short Qwen-Omni clips can use reference text to avoid known sub-second hallucinations, and force_reference can make reference text authoritative for datasets whose model output is not trusted. Otherwise, the stage handles unsupported languages, recovered fallback predictions, reference recovery, cross-model agreement, and the normal primary result. Cross-model agreement uses character error rate (CER) for languages written without word-separating spaces and word error rate (WER) otherwise. The selected metric is recorded in metric_key. asr_text_key is a compatibility alias that overrides fallback_text_key when supplied.

agreement_wer_key
str = 'primary_fallback_agreement_wer'
asr_text_key
str | None = None
duration_key
str = 'duration'
fallback_source_label
str = 'fallback'
fallback_text_key
str = 'fallback_model_prediction'
force_reference
bool = False
ground_truth_source_label
str = 'ground_truth'
language_key
str = 'source_lang'
metric_key
str = 'primary_fallback_agreement_metric'
min_agreement_pct
float = 80.0
name
str = 'SelectBestPrediction'
notes_key
str = 'additional_notes'
output_key
str = 'best_prediction'
primary_model_type
str | None = None
primary_source_label
str = 'primary'
primary_text_key
str = 'primary_model_prediction'
reference_source_label
str = 'reference'
reference_text_key
str | None = None
resources
Resources
short_audio_threshold
float = 1.0
skip_me_key
str = '_skipme'
source_key
str = 'best_prediction_source'
use_ground_truth_for_short_audio
bool = True
use_reference_on_hallucination
bool = False
nemo_curator.stages.audio.text_filtering.SelectBestPredictionStage.inputs() -> tuple[list[str], list[str]]
nemo_curator.stages.audio.text_filtering.SelectBestPredictionStage.outputs() -> tuple[list[str], list[str]]
nemo_curator.stages.audio.text_filtering.SelectBestPredictionStage.process(
class nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage(
common_hall_file: str,
unique_words_threshold: float = 0.4,
long_word_threshold: int = 25,
agglutinative_long_word_threshold: int = 35,
long_word_rel_threshold: float = 3.0,
max_char_rate: float = 40.0,
language_key: str = 'language',
duration_key: str = 'duration',
text_key: str = 'pred_text',
skip_me_key: str = '_skipme',
notes_key: str = 'additional_notes',
overwrite: bool = False,
recovery_value: str = '',
name: str = 'WhisperHallucination',
resources: nemo_curator.stages.resources.Resources = (lambda: Resources(cpus=1.0...,
_PREFIX_MATCH_MIN_LEN: int = 8
)
Dataclass

Bases: ProcessingStage[AudioTask, AudioTask]

Flag transcripts that show common ASR hallucination patterns.

Four independent checks run, and any single hit flags the row:

  • Repeated n-grams: the unique-word ratio falls to or below unique_words_threshold, the signature of a decoder stuck in a loop.
  • Long word: a word at or over the language-appropriate absolute length bar, or one much longer than the next-longest word by long_word_rel_threshold.
  • Phrase match: the transcript is a known hallucination phrase or an approved continuation from common_hall_file (think “Thank you for watching” over silence).
  • High char rate: characters per second exceed max_char_rate, an impossible speaking rate, which catches dense text confabulated over a very short clip.

Repeated-word and long-word checks are disabled for languages written without word-separating spaces because whitespace tokenization treats an entire utterance as one word. Phrase and character-rate checks remain active for those languages.

When flagged, skip_me_key is set to "Hallucination:{name}" so the originating instance stays identifiable. An existing non-hallucination flag from some other filter is never clobbered. Setting overwrite=True turns the stage into a re-check that can also clear a previous hallucination flag when a second-pass transcript now looks clean, which is how an ASR recovery pass promotes its result.

recovery_value is a caller-selected note written only when overwrite=True clears an existing hallucination flag. For example, recovery_value="Recovered:ASR" produces the note "recovered:asr". Leaving it empty produces "recovered".

Run the bundled YAML from the Curator repository root over a JSONL manifest that already contains pred_text, _skipme, and duration:

.. code-block:: bash

python nemo_curator/config/run.py
—config-path ../../tutorials/audio/whisper_hallucination
—config-name pipeline
manifest_path=tests/fixtures/audio/text_filtering/whisper_hallucination_input.jsonl
output_path=/tmp/whisper_hallucination_output.jsonl

_PREFIX_MATCH_MIN_LEN
int = 8
_n_flagged
int = field(default=0, init=False, repr=False)
_n_processed
int = field(default=0, init=False, repr=False)
_phrases
set[str] = field(default_factory=set, init=False, repr=False)
agglutinative_long_word_threshold
int = 35
common_hall_file
str
duration_key
str = 'duration'
language_key
str = 'language'
long_word_rel_threshold
float = 3.0
long_word_threshold
int = 25
max_char_rate
float = 40.0
name
str = 'WhisperHallucination'
notes_key
str = 'additional_notes'
overwrite
bool = False
recovery_value
str = ''
resources
Resources
skip_me_key
str = '_skipme'
text_key
str = 'pred_text'
unique_words_threshold
float = 0.4
nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage._frequent_single_word(
text: str
) -> bool
nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage._high_char_rate(
words: list[str],
duration: float
) -> bool
nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage._is_agglutinative(
) -> bool
nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage._is_scriptio_continua(
) -> bool
nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage._long_word(
words: list[str],
threshold: int | None = None,
skip_relative: bool = False
) -> bool
nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage._normalize_corpus_phrase(
text: str
) -> str
staticmethod
nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage._repeated_ngrams(
words: list[str]
) -> bool
nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage._set_note(
task_data: dict[str, typing.Any],
value: str
) -> None
nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage._transcript_candidates(
text: str
) -> set[str]
staticmethod
nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage.inputs() -> tuple[list[str], list[str]]
nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage.outputs() -> tuple[list[str], list[str]]
nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage.process(
nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage.setup(
_worker_metadata: object | None = None
) -> None
nemo_curator.stages.audio.text_filtering.WhisperHallucinationStage.teardown() -> None