10 · Adapt speech recognition
Listen to the same utterance through three channels and test whether a filter or a Whisper adapter improves the transcript.
- Part 3
- Adapt models
- Model
openai/whisper-base- Data
- LibriSpeech at 71cacbfb7e2354c4226d01e70d77d5fca3d04ba1 (CC BY 4.0). Cap the public clean splits before applying a fixed noise transform and keep speakers disjoint.
- Hardware
- Tesla T4, in Google Colab
Would you filter the incoming audio?
You maintain the transcription step for a voice-note inbox. A reviewer flagged that the transcript changed a name. Before changing the recogniser, listen to the first word of the same 3.505-second recording in the three clips below. Which version would you send to the recogniser? The audiobook excerpt gives us a reference transcript, and the noise and filter were applied to that one recording.
Same utterance, three channels
LibriSpeech 6930-75918-0000 · 3.505 seconds · common amplitude scale
Original audiobook
Simulated noisy channel
Same noise after bandpass
Check the first word against the three transcripts
The reference starts with Concord. Frozen Whisper wrote Concorde on the original, Concord on the noisy clip and Common Core after filtering. The noisy version had zero word edits on this clip. Check all 24 held-out recordings before deciding whether to keep the filter.
LibriSpeech 6930-75918-0000
- Reference
- CONCORD RETURNED TO ITS PLACE AMIDST THE TENTS
- Frozen · clean
- Concorde returned to its place amidst the tents.
- Frozen · corrupted
- Concord returned to its place amidst the tents.
- Frozen · filtered
- Common Core returned to its place amidst the tents.
The bandpass made word errors more frequent
Pooled word error rate · 24 clips · 333 reference words per condition · bar scale 0–70%
119/333
74/333
214/333
19/333
74/333
1. Separate what the filter changes from what LoRA changes
A filter changes what the model hears; training changes how the model responds to what it hears. Measure those two interventions separately before attributing gains to adaptation.
Use the same utterances and references in every condition. For the filter comparison, hold Whisper Base fixed and compare the noisy clip with its filtered copy. For the adapter comparison, hold the waveform fixed and compare the frozen and trained checkpoints. Run the second comparison on clean originals as well to check retention. Keep English transcription, greedy decoding and the 144-token generation cap fixed in all five conditions. Whisper Base checkpoint · Whisper API
Change one thing at a time
Each comparison uses the same held-out utterances
2Change the waveform
Frozen Whisper hears the corrupted clip and its bandpass-filtered copy.
WER change +42.0 points
95% interval +1.0 to +117.1 points
Change the weights
Frozen Whisper and LoRA hear exactly the same corrupted clip. Repeat on the clean original.
WER change 0.0 points on both channels
The sampled LibriSpeech clips are volunteer audiobook readings. The clean source at 16 kHz was downsampled to 8 kHz and restored to 16 kHz before adding seeded white noise at 8 dB signal-to-noise ratio. The conditioning arm applies a fourth-order 300–3,400 Hz Butterworth bandpass forward and backward. Listen for the opening consonant in each version. The study estimates performance for this simulated channel on a selected group of readers. LibriSpeech collection · Pinned dataset card
The fixed filter is a separate choice from the simulated channel. It can suppress energy outside the selected passband, but it can't recreate speech lost during resampling or tell which frequencies carry the name. The same waveform reaches both recognisers in the adapter comparison. That means an apparent difference there belongs to the recognition stage under the tested settings. A filter-plus-adapter combination would need its own arm before attributing a gain or regression to either stage of that combination.
The conditioning code applies a forward-backward filter to the entire waveform. That requires the clip as a whole. A live call transcription service with incremental input would need to account for buffering or use a different filter. Hold the implementation fixed before using these transcript scores to judge the operational cost of conditioning.
# Filter the whole clip in both directions.
def conditioned(wave, rate):
sos = butter(4, (300, 3400), btype="bandpass", fs=rate, output="sos")
return sosfiltfilt(sos, wave).astype(np.float32)The original Whisper paper gives a separate reason to measure both channels. In its Table 2, wav2vec 2.0 Large and Whisper Large V2 both scored 2.7% WER on LibriSpeech test-clean. On Common Voice, the corresponding scores were 29.9% and 9.0%. Those published comparisons use different checkpoints and datasets from this lab. Whisper paper, §3.3 and Table 2
2. Train on the noisy clips with the original references
The input to training is the distorted waveform. The target is the original transcript with the English transcription prefix. The notebook freezes the base model and adds rank-eight LoRA weights to the query and value projections in attention. It uses alpha 16, dropout 0.05 and AdamW at a learning rate of 1e-4. These are the forward-pass steps from the fit.
# Fit the shifted waveform against the original transcript.
def train_step(clip, optimiser, scaler):
features = to_features(clip["shifted"])
labels = processor.tokenizer(clip["reference"].lower(), return_tensors="pt").input_ids.to(device)
if labels[0, 0].item() == model.config.decoder_start_token_id:
labels = labels[:, 1:]
optimiser.zero_grad(set_to_none=True)
with torch.autocast(device_type="cuda", dtype=torch.float16):
loss = adapter(**features, labels=labels, use_cache=False).loss
if not torch.isfinite(loss):
raise FloatingPointError(f"Nonfinite ASR loss for {clip['id']}")
scaler.scale(loss).backward()
scaler.unscale_(optimiser)
torch.nn.utils.clip_grad_norm_(trainable_parameters, 1.0)
previous_scale = scaler.get_scale()
scaler.step(optimiser)
scaler.update()
return loss.item(), scaler.get_scale() >= previous_scaleThe preflight made one real update on the longest training transcript. Then the notebook restored the adapter parameters and random state before the scored fit. It checks for a finite loss, unscales gradients and records whether the optimiser update was applied. The first scored update processed clip 7800-283478-0018, returned a loss of 1.010 and applied the step. The 16 losses come from different utterances, so the held-out comparisons determine whether the resulting weights help. All 16 updates · Preflight record
In the opening clip, the noisy base transcript already has the correct name. That is a useful control for reading a training curve. The training objective asks the decoder to predict the full transcript, where a short place name is only part of the target. A drop in loss doesn't guarantee that names, dates or amounts improve at the same rate as the surrounding words. Score the name from the exact saved completion before using it to route a voice note. When adapting a real inbox, take care to split by speaker or recording session before training. Otherwise repeated narration style can make the apparent channel recovery easier than it will be on a caller the system hasn't heard.
All 16 updates ran on the noisy training clips
Token cross-entropy per update · different utterances
33. Count the words and characters separately
Pool edits across clips and divide by the total number of reference words. On the opening noisy recording, the frozen result contributes zero edits over eight words. The filtered result contributes two edits over eight words because Common Core takes the place of Concord.
Here S, D and I count substitutions, deletions and insertions, and N is the number of reference words. Character error rate applies the same calculation to characters. An edit rate can exceed 100% when the recogniser adds more words than the reference contains.
Filtering raised WER by 42.0 percentage points. The 95% paired bootstrap interval was +1.0 to +117.1 points. Each draw resampled speakers together with their clips. LoRA changed WER by 0.0 points on both the clean and noisy clips, with a zero-width interval on this sample. Four held-out speakers give limited evidence about how either intervention would behave on other voices or channels. Scores and intervals
| Condition | WER | CER |
|---|---|---|
| Frozen, clean | 5.7% | 1.9% |
| Frozen, corrupted | 22.2% | 10.5% |
| Frozen, conditioned | 64.3% | 37.6% |
| Adapted, clean | 5.7% | 1.9% |
| Adapted, corrupted | 22.2% | 10.4% |
These entries are rounded from the saved report. The code sums the denominators and numerators independently. Longer clips contribute more reference words, as they should when the measure answers “what fraction of reference words required edits?” An average across equally weighted clips would ask a different question. The numeric diagnostic has its own denominator and excludes clips without eligible number tokens.
# Pool the edit counts and track numeric coverage separately.
def aggregate(records):
numeric = [r["numeric_exact"] for r in records if r["numeric_exact"] is not None]
return {
"clips": len(records),
"wer": sum(r["word_edits"] for r in records) / sum(r["word_total"] for r in records),
"cer": sum(r["char_edits"] for r in records) / sum(r["char_total"] for r in records),
"numeric_exact": sum(numeric) / len(numeric) if numeric else None,
"numeric_denominator": len(numeric),
"decode_real_time_factor": sum(r["decode_seconds"] for r in records) / sum(r["audio_seconds"] for r in records),
}The adapter changed two character edits on noisy audio
Pooled character error rate · 1,783 reference characters per condition · bar scale 0–40%
434/1783
187/1783
671/1783
34/1783
185/1783
Numeric sequence matched on 2/2 eligible clips in all five conditions.
All five conditions matched the reference number-token sequence on the same two eligible clips. For example, the replay below has one in “the one party,” and both noisy outputs retain it. The diagnostic maps listed single number words such as “one” to digits and compares the resulting sequences. It includes phrases such as “the one party” and does not evaluate amounts such as “two hundred and six dollars” as currency values.
4. Replay a regression even when aggregate WER ties
Listen for the three words indicated below. Both recognisers received the exact same noisy audio. The adapter changed two of the disputed words and introduced an additional reference mismatch on desolation.
One more wrong word on the same noisy clip
LibriSpeech 5639-40744-0005 · 5.645 seconds
5- Reference words
- exulting · desolation · woe
- Frozen · 2 edits
- exhausting · desolation · war
- LoRA · 3 edits
- exalting · deflation · war
LibriSpeech 5639-40744-0005
- Reference
- FINALLY THE ONE PARTY WENT OFF EXULTING AND THE OTHER WAS LEFT IN DESOLATION AND WOE
- Frozen · corrupted
- Finally, the one party went off exhausting and the other was left in desolation and war.
- LoRA · corrupted
- Finally, the one party went off exalting and the other was left in deflation and war.
The frozen model made two word edits and the adapted model made three, giving this clip the largest positive word-edit delta in the run. Both have five character edits. The additional word error can matter even when character-level edits tie. Inspect the other paired transcripts before changing the default. Raw per-clip transcripts and edit counts
| Same regression clip | Word edits / reference words | Character edits / reference characters |
|---|---|---|
| Frozen, corrupted | 2/16 | 5/84 |
| Frozen, conditioned | 4/16 | 14/84 |
| Adapted, corrupted | 3/16 | 5/84 |
Read the exact mistakes before looking for a threshold. The adapted recogniser substitutes deflation for desolation. It also changes the frozen exhausting to exalting, which is still a word mismatch against exulting. Both noisy systems finish on war instead of woe. Similar character totals conceal the difference in how many words the listener has to repair. For a transcript that feeds a search index, deflation and desolation can lead to entirely different matches. For a transcript that a person reads beside the original audio, it might instead create a manual correction. Keep the use of the transcript explicit when selecting the evaluation.
The filter was harmful on the aggregate and happened to restore exulting in this particular replay. It still dropped woe, changed desolation, and returned a shorter phrase than the reference. This is why a filter decision needs the paired records in addition to the aggregate. If the filter failed only on a small group of speakers, you might try routing by a property of the channel. If failures appear for the same speaker across several recordings, compare the unfiltered and filtered waveforms before changing model weights. The report groups uncertainty by speaker, which preserves some of that dependence. An actual voice-note inbox may introduce other dependencies, such as many clips from one device in the same location. Decide which units are likely to share the same errors before splitting them across training and evaluation.
A clean-retention comparison helps decide whether routing can be simple. Here the clean scores tie, so there is no measured clean penalty in this speaker set. The noisy WER tie leaves no measured recognition gain to offset the added serving work. Move the same analysis to your inbox by deciding which edits change an action. A wrong address may need a callback, while a punctuation choice may have no consequence once the voice note reaches the right queue. Collect those labels on held-out messages and keep the original audio for difficult cases. The audiobook results are evidence about this channel simulation and a guide to what to inspect in a real inbox.
What to keep
| Option | What the evidence supports | Check before revisiting |
|---|---|---|
| Frozen Whisper | Default comparison on clean and corrupted audio | Replay names and amounts before routing transcripts. |
| Fixed bandpass | Keep as a diagnostic comparison | Measure actual channel speech and any streaming delay. |
| Whisper with LoRA | Retain as a controlled adaptation candidate | Look for meaningful paired gains on target-domain speech. |
- Hold the utterance fixed. Change the channel or model independently so you can locate the source of any difference.
- Check clean retention. Compare checkpoints on the untouched recordings before routing all audio through the adapter.
- Inspect consequential words. Pooled WER can tie while the words that drive a downstream action change.
- Show numeric coverage. Two eligible clips support only a narrow reading of the number-token score.
- Preserve difficult examples. Keep the original audio, reference and competing transcripts together for review.
- Next to try, not tested here: compare real inbox recordings by codec and background noise with names and amounts specifically adjudicated.
How it was built
| Item | Setting |
|---|---|
| Base model | Whisper Base revision e37978b90ca9030d5170a5c07aadb050351a65bb. |
| Data | LibriSpeech, 32 training clips from four speakers. |
| Test | 24 held-out clips from four disjoint speakers. |
| Method | Seeded channel corruption, a fixed bandpass control and LoRA on the query and value projections. |
| Training | 16 AdamW updates, rank 8, alpha 16, dropout 0.05 and learning rate 1e-4. |
| Decoding | Greedy English transcription with a 144-token cap. |
| Hardware | Tesla T4 with FP16 autocast. |
The fit itself took 2.80 seconds
Default profile · one Tesla T4
6One-update preflight
0.42 s · 1.38 GiB peak reserved
Longest training transcript · 7800-283478-0021
Recorded fit
16 updates · 1.24 GiB peak allocated
294,912 trainable parameters · 95.76 s for the notebook
Time and cost. The receipt records 95.76 seconds including notebook overhead. The fit took 2.80 seconds and peaked at 1,326,121,984 allocated bytes. The saved LoRA weights occupy 1,189,560 bytes. PyTorch 2.14.1+cu130, Transformers 4.57.1, PEFT 0.17.1, Datasets 3.6.0 and jiwer 4.0.0 made up the model and scoring stack. The default profile selected 32 training clips and 24 test clips from disjoint speakers. The report records the complete clip rosters and pinned model and dataset revisions. Audio replays are the saved notebook WAVs, and the waveforms summarise the minimum and maximum sample values within equal time bins. Execution receipt · Opening raw outputs · Regression raw outputs
Run it yourself
Open the notebook from the facts box or download the exact notebook used for the run. Allow 95.76 seconds on the measured T4 setup. Follow the notebook’s channel section alongside the paired conditions, the adapter section alongside training, and paired retention alongside scores and the transcript replay.
- Predict whether raising the lower bandpass cutoff changes the opening name. Keep the upper cutoff and recogniser fixed. Inspect the retained waveform and the first word for
6930-75918-0000inexamples.jsonl. - Predict whether restricting evaluation to proper names reverses the apparent noisy WER tie. Change only the scorer’s eligible spans on the same outputs and compare the two arm counts alongside the original word edits.
- Predict what happens to frozen and adapted WER when the signal-to-noise ratio rises from 8 dB to 12 dB. Change only the ratio and check the paired corrupted scores and the clean-retention comparison.
How is this page?
Last updated on