Backends¶
ASRBackend ¶
CTCModuleBackend ¶
CTCModuleBackend(model: Module, labels: list[str] | tuple[str, ...], device: device | str | None = None, blank_id: int | None = None, freeze_model: bool = True)
Bases: ASRBackend
Wrap a PyTorch CTC module such as torchaudio wav2vec2.
labels must be the model's vocabulary in index order (bundle.get_labels()
for torchaudio wav2vec2). Encoding uses this vocabulary; it is not hardcoded.
Logits must be (batch, time, vocab) with vocab == len(labels).
Source code in src/asr_attacks/backends/module.py
HuggingFaceCTCBackend ¶
HuggingFaceCTCBackend(model: str | Module, device: device | str = 'cpu', processor=None, tokenizer=None, freeze_model: bool = True)
Bases: ASRBackend
Wrap a Hugging Face AutoModelForCTC checkpoint.
Install the optional extra: pip install asr-attacks[hf].
Most wav2vec2-family checkpoints expect zero-mean, unit-variance input. When the
processor's feature extractor has do_normalize=True the backend applies that
normalization inside :meth:logits (in autograd), so attacks perturb the raw
waveform and optimize the loss of the normalized audio the model actually receives.