ASRAttacks¶
ASRAttacks ¶
ASRAttacks(model: Module, device: device | str, labels: list[str] | tuple[str, ...], verbose: bool = True)
Run the same attacks as :class:~asr_attacks.ASRAttacker on a CTC module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
Differentiable CTC model. Forward should return logits or
|
required |
device
|
device | str
|
|
required |
labels
|
list[str] | tuple[str, ...]
|
Vocabulary in index order (for example |
required |
verbose
|
bool
|
Show progress bars and early-stop messages ( |
True
|
Source code in src/asr_attacks/compat.py
CW_ATTACK ¶
CW_ATTACK(input__, target=None, epsilon: float = _CW_EPS, c: float = 1.0, learning_rate: float = _CW_LR, num_iter: int = 5000, decrease_factor_eps: float = 0.8, num_iter_decrease_eps: int = 10, check_every: int | None = None, optimizer: str | None = 'adam', nested: bool = True, early_stop: bool = False, search_eps: bool = True, targeted: bool = False, internal_call: bool = False, label=None, db_bound: float | None = None, loss: str = 'ctc', kappa: float = 0.0) -> np.ndarray
Audio Carlini & Wagner attack; see :meth:ASRAttacker.cw.
num_iter_decrease_eps is used as check_every when
check_every is None (legacy name kept for compatibility).
Source code in src/asr_attacks/compat.py
IMPERCEPTIBLE_ATTACK ¶
IMPERCEPTIBLE_ATTACK(input__, target=None, epsilon: float = _EPS_QIN, c: float | None = None, learning_rate1: float = _LR1_QIN, learning_rate2: float = _LR2_QIN, num_iter1: int = 1000, num_iter2: int = 4000, decrease_factor_eps: float = 0.8, num_iter_decrease_eps: int = 10, check_every: int | None = None, optimizer1: str | None = 'sgd', optimizer2: str | None = 'adam', nested: bool = True, early_stop_cw: bool = False, search_eps_cw: bool = True, alpha: float = 0.05, sample_rate: int = 16000, targeted: bool = True, label=None, mode: str = 'imperceptible', rooms=None, robust_delta: float = _ROBUST_DELTA, num_iter_r1: int = 2000, num_iter_r2: int = 4000, learning_rate_r1: float = _LR_R1, learning_rate_r2: float = _LR_R2, num_iter_ir1: int = 4000, num_iter_ir2: int = 6000, learning_rate_ir1: float = _LR2_QIN, learning_rate_ir2: float = _LR_IR2) -> np.ndarray
Qin et al. imperceptible / robust attack; see :meth:ASRAttacker.imperceptible.
target may be None when targeted=False. When
targeted=True, a missing target raises from
resolve_target. c is deprecated and ignored.
Source code in src/asr_attacks/compat.py
wer_compute ¶
wer_compute(ground_truth: list[str], audios: list[ndarray], targeted: bool = False) -> tuple[float, list[tuple[int, int, int]]]
Return mean Levenshtein WER and per-utterance (S, I, D) counts.
targeted is unused. This method always returns WER.