How it works#
The method#
Li et al. [1] erase one dimension of the input by setting it to zero, then measure the relative change in the negative log-likelihood of the correct label. For audio the “dimension” is a patch of the time-frequency plane. With X = STFT(x) in Whisper’s analysis settings (window 400 samples, hop 160, Hann, 16 kHz), patch P = (b, t) covers STFT frames [10t, 10t + 10) and the bins of band b, and erasing it is
The erased waveform goes to the model through its own front end, so one operator serves Whisper (log-mel input), Moonshine (raw waveform input) and a remote server (a WAV file over HTTP). With y = (y₁ … y_K) the model’s own greedy transcript and S_k(x) = −log p(y_k | y_<k, x) the surprisal of token k under teacher forcing, every patch gets three scores from the same forward pass:
Δ is in nats and positive when the patch supported the token. r is Li et al.’s equation 1 with the sign flipped. flip is their discrete criterion, whether the decision changes. The non-negative mass m_k(P) = max(Δ_k(P), 0) / Σ max(Δ_k, 0) gives the time profile, the band shares and the top patch of a token. In the rest of this README a token’s evidence means this mass. The noise-focus ratio compares it with the AADD flags f(t), whose clip mean is f̄:
Stats for nerds (the fine print of the operator and the scores)
Zeroing coefficients and resynthesising is not exact: the 25 ms windows overlap by 75 %, so the new signal’s own STFT regains some energy in the patch from the frames and bins around it. WAYS applies the projection three times (zero, resynthesise, re-analyse). Measured in Whisper’s log-mel on three real clips, the patch falls by 33 to 36 dB on average and by at least 17 dB in the worst case, below the clip’s own 10th-percentile background. Without resynthesis the drop would be 56 dB. The residual is the cost of resynthesising a waveform, which every backend takes as input. The waveform outside the patch’s time span by more than 20 ms is unchanged to 1e-5, and only the two patches that share a window edge with P lose a little of their own energy (up to about 10 % of P’s effect).
Dividing by S_k(x) is a per-token constant, so every within-token summary is the same from Δ or from r. r only matters between tokens and is unstable for tokens the model was nearly certain of (S_k ≈ 0), so the summaries use Δ.
A server that returns only text cannot give S_k. There WAYS re-decodes x\P, aligns the new transcript to y word by word with jiwer, and marks each original word that is not inside an “equal” alignment chunk. This is the “relative change in evaluation metric” form of erasure from the same paper, applied at word level with a value of 0 or 1 per patch.
NFR is 1 when a token spreads its evidence without regard to the flags, above 1 when it leans on flagged audio, below 1 when it avoids it. It is undefined with no flagged frames and trivially 1 when every frame is flagged, so the tables report it on the clips with 5 to 95 % of frames flagged (“informative” clips) as well as on all clips. Uncertainty is a 10 000-resample bootstrap over clips (seed 8001), and model differences are paired on the same clips.
Faster scoring with the same scores#
Scoring an erased clip needs the model’s logits and never its attention weights. Since 0.3.3 the scoring passes of the Whisper backend use PyTorch’s fused scaled-dot-product attention. It evaluates the same expression, softmax(QKᵀ / √d) V, with the same weights and in the same 32-bit precision, but it does not build the weight matrix. Transcription keeps the step-by-step attention, because the token timestamps are read from those weights. The two kernels can differ only in the order of floating-point operations. Moonshine already used the fused kernel.
I rescored the 100 test-slice clips with the fused kernel and compared them with the saved maps,
which were made with the step-by-step one (experiments/check_fast_attention.py):
model |
transcripts unchanged |
top patch unchanged |
largest change of any score |
flips that differ |
largest change of a clip’s noise-focus ratio |
seconds per clip, before and after |
|---|---|---|---|---|---|---|
whisper-tiny |
100 of 100 |
4 034 of 4 034 tokens |
0.0002 nats |
5 of 4 259 824 |
0.0001 |
7.4 and 5.5 (1.36x) |
whisper-base |
100 of 100 |
3 267 of 3 267 tokens |
0.0001 nats |
1 of 3 149 872 |
0.0001 |
14.2 and 9.8 (1.45x) |
The six flips that differ are tokens whose two best candidates were tied to within rounding.
load_backend("hf-whisper", ..., fast_attention=False) restores the old path. Three faster options
were measured on 12 controlled clips and not adopted, because they change the maps: half precision
(3.4x, same top patch, scores off by 0.006 nats), running the encoder without Whisper’s 30 s padding
(4x, top patch kept for 83 % of tokens) and the gradient approximation known as attribution patching
(7x, rank correlation 0.30 with true erasure).