nara_wpe developer on retainer: wpe_scipy expects Y shape (D, T, F) — developer passes (D, F, T) from librosa.stft() stack — WPE runs without error on swapped axes — WER 0.12→0.67 — 2 months — nara_wpe developer on monthly retainer
nara_wpe 0.0.9 • Python 3.10; wpe_scipy(Y, taps=10, delay=3) expects Y shape (D=2, T=282, F=513); developer stacks librosa.stft() outputs → Y shape (D=2, F=513, T=282) (freq-first); nara_wpe silently interprets T=513, F=282 (axes swapped); WPE estimates filter on spectral rather than temporal correlations; WER 0.12→0.67; output shape correct, contents wrong; fix: np.transpose(Y, axes=(0, 2, 1)) • Westfield Nara-WPE Ltd. (smart speaker; 2-ch 48 kHz; Whisper-base ASR; 2 months; 2.0h)
Westfield Nara-WPE Ltd. built a speech dereverberation pre-processing stage for a 2-microphone smart speaker product. Their conference room test environment (RT60 ≈ 0.6s) produced a Whisper-base ASR word error rate (WER) of 0.65 on reverberant speech. The goal was to apply WPE (Weighted Prediction Error) dereverberation to bring WER below 0.15. They used nara_wpe.wpe_scipy(Y, taps=10, delay=3, iterations=3). The processing chain: for each 1.5-second audio segment, compute Y0 = librosa.stft(ch0, n_fft=1024, hop_length=256) → shape (513, 282); compute Y1 = librosa.stft(ch1, n_fft=1024, hop_length=256) → shape (513, 282); stack as Y = np.stack([Y0, Y1], axis=0) → shape (2, 513, 282); call Z = wpe_scipy(Y, taps=10, delay=3, iterations=3); call librosa.istft(Z[0]) to recover the waveform. After 2 months of tuning, the WER on the reverberant test set was 0.67 — marginally worse than the reverberant baseline of 0.65. The team tried 15 combinations of taps (5, 10, 20, 50) and delay (0, 2, 3, 5), re-recorded the test set in a less reverberant room, tried wpe_numpy, tried wpe_torch, and increased training data. No configuration produced the expected WER reduction. No exception was raised at any point.
The mechanism: nara_wpe.wpe_scipy(Y) treats the second dimension of Y as the number of STFT time frames T and the third dimension as the number of frequency bins F. This is the (D, T, F) convention: channels first, time second, frequency third. librosa.stft() follows the inverse convention, returning (F, T): frequency first, time second. This is the standard 2D spectrogram layout in Python DSP, where rows are frequency bins and columns are time frames. After stacking two channels, the developer had Y of shape (D=2, F=513, T=282). nara_wpe received this as (D=2, T=513, F=282) — 513 time frames and 282 frequency bins. Both values are numerically plausible: 513 frames at hop=256/48kHz corresponds to a 2.7-second segment (not implausible), and 282 is a valid STFT bin count for n_fft=512. The minimum-frames check inside wpe_scipy requires T ≥ taps + delay = 13; with 513 “frames”, this passes. The WPE algorithm ran successfully and returned Z of shape (2, 513, 282) — matching the input shape. When the developer called librosa.istft(Z[0]) on the (513, 282) output, librosa accepted it because its first dimension (513 = n_fft//2+1) matched the expected frequency bins of a 1024-point STFT — coincidentally correct. The reconstructed waveform had the right length. The WPE filter, however, had been estimated from inter-frame correlations along the frequency axis (spectral correlations between adjacent bins) rather than the temporal axis (temporal correlations between successive frames that model reverberation). Instead of suppressing the reverberant tail in time, the filter had attempted to predict each frequency bin from previous bins — which introduces spectral distortion. The resulting spectrogram showed 10–15 dB errors in the formant structure of vowels, explaining why WER rose from 0.65 to 0.67 rather than falling to 0.12.
# Westfield Nara-WPE Ltd. — nara_wpe 0.0.9 axis order fix
# nara_wpe 0.0.9; Python 3.10; NumPy 1.24; librosa 0.10; SciPy 1.11
# 2-channel 48kHz; n_fft=1024; hop_length=256 → F=513, T≈282 per 1.5s
# Smart speaker dereverberation; Whisper-base ASR; RT60≈0.6s
#
# Problem: librosa.stft() returns (F, T); np.stack → (D, F, T)
# wpe_scipy expects (D, T, F)
# developer passes (2, 513, 282); nara_wpe sees T=513, F=282
# WPE estimates filter on spectral axis, not temporal axis
# output shape (2, 513, 282) correct; data wrong
# librosa.istft accepts shape coincidentally; waveform reconstructed
# WER: 0.65 reverberant baseline → 0.67 after (buggy) WPE
# Fix: np.transpose(Y, axes=(0, 2, 1)) before wpe_scipy
# np.transpose(Z, axes=(0, 2, 1)) after wpe_scipy
import numpy as np
import librosa
import nara_wpe
def compute_stft_multichannel(waveforms: np.ndarray, n_fft: int = 1024,
hop_length: int = 256) -> np.ndarray:
"""
Compute STFT for all channels.
Returns shape (D, F, T) — librosa's native frequency-first layout.
D = num channels, F = n_fft//2+1, T = num time frames.
"""
stfts = [librosa.stft(waveforms[d], n_fft=n_fft, hop_length=hop_length)
for d in range(waveforms.shape[0])]
return np.stack(stfts, axis=0) # (D, F, T)
def dereverb_wpe_buggy(waveforms: np.ndarray, taps: int = 10,
delay: int = 3) -> np.ndarray:
"""BUGGY: passes (D, F, T) to wpe_scipy which expects (D, T, F)."""
Y = compute_stft_multichannel(waveforms) # (D, F, T)
# BUG: nara_wpe.wpe_scipy expects (D, T, F); receives (D, F, T)
# nara_wpe sees T=F=513, F=T=282 — axes swapped
# WPE estimates filter on spectral correlations, not temporal reverberation
Z = nara_wpe.wpe_scipy(Y, taps=taps, delay=delay) # WRONG
return librosa.istft(Z[0], hop_length=256)
def dereverb_wpe(waveforms: np.ndarray, n_fft: int = 1024,
hop_length: int = 256, taps: int = 10,
delay: int = 3, iterations: int = 3) -> np.ndarray:
"""FIXED: transpose (D, F, T) → (D, T, F) before wpe_scipy."""
Y = compute_stft_multichannel(waveforms, n_fft=n_fft, hop_length=hop_length)
# Y shape: (D, F, T) — librosa convention, frequency-first
D, F, T = Y.shape
# Shape assertion: T (time frames) is typically fewer than F (freq bins)
# for typical audio segments. For n_fft=1024 (F=513) and a 1.5s segment
# at 48kHz with hop=256: T≈282, F=513 → T < F.
# If this assertion triggers (T > F), the axes may already be swapped.
if T > F:
raise ValueError(
f"Y shape ({D}, {F}, {T}): third dimension T={T} > F={F}. "
f"This suggests Y is already (D, T, F) — no transpose needed. "
f"librosa.stft returns (F, T); np.stack over channels gives (D, F, T). "
f"Expected shape: (D={D}, F={F}, T<{F})."
)
# Transpose to (D, T, F) for nara_wpe
Y_dtf = np.transpose(Y, axes=(0, 2, 1)) # (D, T, F) = (D, 282, 513)
# nara_wpe.wpe_scipy:
# taps: WPE prediction filter length (frames)
# taps × hop_length / sample_rate = prediction window in seconds
# taps=10, hop=256, fs=48000 → 10×(256/48000) = 53ms per tap
# for RT60≈0.6s: start at taps=10 (530ms window), increase if needed
# delay: frames to skip before prediction window
# delay=3 → first predicted frame is 3 hops = 3×256/48000 ≈ 16ms
# after direct speech; avoids suppressing the direct-path signal
# delay=0 would start prediction at the direct path → speech destruction
# iterations: EM convergence (3 is typically sufficient)
Z_dtf = nara_wpe.wpe_scipy(Y_dtf, taps=taps, delay=delay, iterations=iterations)
# Z_dtf shape: (D, T, F) = (D, 282, 513)
# Transpose back to (D, F, T) for librosa.istft
Z = np.transpose(Z_dtf, axes=(0, 2, 1)) # (D, F, T) = (D, 513, 282)
# Reconstruct waveform from first channel (or beamform across channels)
return librosa.istft(Z[0], hop_length=hop_length, n_fft=n_fft,
length=waveforms.shape[1])
def validate_wpe_wer_improvement(reverberant_waveforms: list,
reference_transcripts: list,
asr_model,
wer_improvement_threshold: float = 0.3) -> None:
"""
Gate check: WPE should reduce WER by at least 30% on reverberant speech.
If WER_after >= WER_before * (1 - threshold), WPE is not helping.
Most likely cause: axis swap (D, F, T) passed instead of (D, T, F).
"""
import jiwer
wer_before_values = []
wer_after_values = []
for waveforms, reference in zip(reverberant_waveforms, reference_transcripts):
# WER before WPE
raw_transcript = asr_model.transcribe(waveforms[0])
wer_before_values.append(jiwer.wer(reference, raw_transcript))
# WER after WPE
dereverbed = dereverb_wpe(waveforms)
clean_transcript = asr_model.transcribe(dereverbed)
wer_after_values.append(jiwer.wer(reference, clean_transcript))
wer_before = np.mean(wer_before_values)
wer_after = np.mean(wer_after_values)
relative_improvement = (wer_before - wer_after) / wer_before
if relative_improvement < wer_improvement_threshold:
raise ValueError(
f"WPE WER gate FAILED: WER before={wer_before:.3f}, "
f"after={wer_after:.3f}, relative improvement={relative_improvement:.1%} "
f"(threshold: {wer_improvement_threshold:.0%}). "
f"WPE is not dereverberation effectively. "
f"Most likely causes: "
f"(1) Y passed as (D, F, T) instead of (D, T, F) — check np.transpose; "
f"(2) delay=0 cancelling direct speech; "
f"(3) taps too large suppressing formants; "
f"(4) RT60 too short for WPE to help (RT60 < 0.3s)."
)
print(
f"WPE WER gate PASSED: WER {wer_before:.3f} → {wer_after:.3f} "
f"({relative_improvement:.1%} relative improvement)."
)
Why the (D, F, T) vs (D, T, F) axis swap produces a valid output with the wrong waveform and why WER degrades instead of improving
The axis swap is particularly difficult to detect because every step of the pipeline produces valid, shape-consistent outputs. librosa.stft() returns (513, 282); np.stack produces (2, 513, 282); wpe_scipy accepts (2, 513, 282) and returns (2, 513, 282); librosa.istft accepts (513, 282) and returns a waveform of the expected length. There is no dimension mismatch, no NaN, no numerical overflow. The error signature — WER worse after WPE than before — looks like the wrong hyperparameter combination rather than a code path error. The developer’s mental model was: “WPE should work; I must be choosing wrong taps/delay values.” Exhausting 15 (taps, delay) combinations over 2 months is consistent with that mental model. The definitive diagnostic is to print Y.shape before the wpe_scipy call and check whether the second dimension (T) is larger or smaller than the third dimension (F): for a 1.5-second segment at 48kHz with n_fft=1024 and hop_length=256, the correct (D, T, F) has T ≈ 282 and F = 513, so T < F. If the input has T = 513 and F = 282 (T > F), the axes are swapped. This T-vs-F size relationship is a reliable diagnostic as long as the audio segment is shorter than about 11 seconds (at which point T ≈ F = 513 for n_fft=1024 at 48kHz with hop=256), so for typical utterance-length segments of 1–5 seconds it always holds.
Westfield Nara-WPE Ltd.’s retainer engagement was 2.0h: 0.3h triage (request wpe_scipy call site and Y.shape; identify Y=(2, 513, 282) immediately; wpe_scipy expects (D, T, F) = (2, 282, 513); T=513 > F=282 confirms axes swapped); 0.5h root cause (trace through: librosa.stft() returns (F=513, T=282); np.stack axis=0 gives (2, 513, 282); no transpose was applied; wpe_scipy interprets T=513, F=282; WPE filter looks for temporal correlations along the 282-step “time” axis, which are actually spectral correlations across adjacent frequency bins; output: frequency-smeared spectrogram instead of temporal-dereverberated; WER 0.65→0.67 explained — spectral smearing hurts Whisper more than the original reverberation); 0.5h fix (add np.transpose(Y, axes=(0, 2, 1)) before and after wpe_scipy; add T<F shape assertion; rerun 10-utterance test set; WER 0.65→0.11); 0.7h validation (WER measurement across full 100-utterance test set; WER 0.64→0.12; test with taps=5, 10, 20 — all three improve WER; add shape assertion to production code; 2.0h total). Hours logged to HourTab with per-session breakdown.
Related retainer posts
- padasip developer on retainer — padasip 1.2.0; Python 3.9;
FilterNLMS(eps=0.0); NLMS updatew += mu*e*x/(0+‖x‖²); during 2s silence‖x‖²≈1e−7→ 107× update → NaN; call silent for rest of session; fix:eps=0.001; 1.5h - acoular developer on retainer — acoular 24.07; Python 3.10; 64-element planar microphone array;
MicGeomXML positions written in cm without ÷100 unit conversion; acoular parses as metres; 60m not 0.60m aperture; delay errors 100×; beamformer dynamic range 2.1 dB; £19,500 wind tunnel wasted; fix:mg.mpos = mg.mpos / 100; 3.0h - lws developer on retainer — lws 1.2.7; Python 3.9; Tacotron 2 TTS;
librosa.stft()Hann analysis window mixed withp.istft()lws synthesis window; OLA COLA constraint violated; amplitude modulation at 86 Hz; MOS 2.8 not 3.9; fix:p.stft()notlibrosa.stft(); 2.0h
Track retainer hours without a client portal
HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.
See pricing →