torch-stoi developer on retainer: NegSTOILoss(extended=False) standard STOI gradient saturation at low SNR — speech enhancement U-Net trapped at identity — clinical intelligibility 51% with enhancement vs 53% unprocessed — $340,000 — 14 months — torch-stoi developer on monthly retainer

torch-stoi 0.1.2 • PyTorch 1.13 • Python 3.10; NegSTOILoss(sample_rate=16000, extended=False); standard STOI saturates below 0 dB SNR; ∂STOI/∂enhancement ≈ 0 for SNR −10 to −5 dB; U-Net converges to identity function (STOI=0.69 for unprocessed = 0.69 for enhanced); clinical intelligibility 51% with enhancement vs 53% unprocessed; FDA class II failure; fix: NegSTOILoss(extended=True) (ESTOI); ESTOI=0.76; clinical 68% • Southfield Torch STOI Ltd. (4-person hearing aid startup, Edinburgh; 14 months; 2.0h)

Southfield Torch STOI Ltd. is a 4-person hearing aid DSP startup in Edinburgh building a speech enhancement processor targeting cafeteria noise at −10 to 0 dB SNR — the loudest and most demanding noise conditions encountered in everyday hearing aid use. Their U-Net enhancement network was trained using NegSTOILoss(sample_rate=16000, extended=False) as the sole training objective, with 48 hours of LibriSpeech clean speech mixed with ETSI EN 300 087 cafeteria noise at SNR −15 to 5 dB. Training ran for 100 epochs; the loss curve decreased from −0.521 (epoch 1) to −0.692 (epoch 10), then remained stable at −0.692 ± 0.001 for the remaining 90 epochs. To the team, this looked like successful convergence. STOI on the test set confirmed: unprocessed noisy signal: 0.693; enhanced signal: 0.695. The 0.002 improvement was within measurement noise. A pre-clinical evaluation with 40 hearing-impaired listeners using BKB sentences at −10 dB cafeteria SNR produced: 53.0% correct with unprocessed signal, 51.2% correct with enhanced signal. Enhancement was making intelligibility slightly worse — the network was adding mild artifacts from an identity-like transformation that was not quite the identity. The FDA class II pre-submission package was rejected on the grounds that the device failed to demonstrate efficacy over the unprocessed comparator.

Inspection of the trained network revealed that the U-Net was applying only minimal spectral modification to the input: the mean L2 norm of (output − input) was 1.3% of the input L2 norm, consistent with an approximate identity function. The gradient magnitude at epoch 1 for the enhancement network parameters was param.grad.abs().mean() = 3.1×10−6 — effectively zero. Standard STOI has a maximum achievable improvement of approximately 0.048 (from STOI=0.693 at −10 dB SNR to 0.741 for oracle clean signal). Over a 10 dB range, this gives a gradient of ≈0.005 per dB of improvement — too weak to train a U-Net with 1024-channel skip connections through 100 epochs of backpropagation. The network was not learning; it was held in place by gradient starvation. Total cost: $340,000 (4 engineers × 14 months at $5,500/month each + clinical study coordination ($18,000) + FDA submission preparation ($14,000) + regulatory consultant fees for the failed submission ($8,000)). Re-training with NegSTOILoss(extended=True) plus a 0.5× SI-SNR co-loss took 2 days; clinical re-test achieved 68.4% correct at −10 dB SNR (vs 53.0% unprocessed), meeting the minimum 10 percentage-point efficacy threshold for the FDA class II submission.

# Southfield Torch STOI Ltd. — torch-stoi 0.1.2 extended=True fix
# torch-stoi 0.1.2; PyTorch 1.13; Python 3.10
# Task: train speech enhancement U-Net for cafeteria noise at -10 to 0 dB SNR
#
# BUG: NegSTOILoss(extended=False) — standard STOI
#      saturates below 0 dB SNR; ∂STOI/∂enhancement ≈ 0
#      U-Net gradient mean epoch 1: 3.1e-6 (effectively zero)
#      U-Net converges to identity function; STOI enhanced ≈ STOI unprocessed
# FIX: NegSTOILoss(extended=True) — ESTOI
#      gradient epoch 1: 8.7e-5 (28× larger); network trains properly

import torch
import torch.nn as nn
from torch_stoi import NegSTOILoss

SAMPLE_RATE = 16000


def train_step_buggy(model: nn.Module, noisy: torch.Tensor, clean: torch.Tensor,
                      optimizer: torch.optim.Optimizer) -> float:
    """BUGGY: standard STOI (extended=False) saturates at low SNR → zero gradient."""
    # NegSTOILoss expects (batch, signal_length) — NO channel dimension
    loss_fn = NegSTOILoss(sample_rate=SAMPLE_RATE, extended=False)  # BUG for low-SNR targets
    optimizer.zero_grad()
    enhanced = model(noisy)                    # (batch, signal_length)
    loss = loss_fn(enhanced, clean)            # returns negative STOI in [-1, 0]
    loss.backward()
    # At -10 dB SNR: ∂STOI/∂enhanced ≈ 0 → gradient ≈ 0 → no weight updates
    optimizer.step()
    return float(-loss.item())                 # STOI value: 0.69–0.70 (barely above unprocessed)


def train_step_fixed(model: nn.Module, noisy: torch.Tensor, clean: torch.Tensor,
                      optimizer: torch.optim.Optimizer) -> float:
    """FIXED: ESTOI (extended=True) + SI-SNR co-loss for robust low-SNR gradient."""
    estoi_fn = NegSTOILoss(sample_rate=SAMPLE_RATE, extended=True)   # ESTOI: sensitive at low SNR
    optimizer.zero_grad()
    enhanced = model(noisy)                    # (batch, signal_length)

    # ESTOI loss — primary perceptual objective
    estoi_loss = estoi_fn(enhanced, clean)     # negative ESTOI in [-1, 0]

    # SI-SNR co-loss — provides dense gradients even when ESTOI saturates
    # SI-SNR (Scale-Invariant Signal-to-Noise Ratio) is differentiable and
    # provides strong gradient signal at all SNR levels
    si_snr_loss = -si_snr(enhanced, clean)     # negative SI-SNR (minimise = maximise)

    # Combined loss: 0.5 × ESTOI + 0.5 × SI-SNR
    loss = 0.5 * estoi_loss + 0.5 * si_snr_loss
    loss.backward()
    optimizer.step()
    return float(-estoi_loss.item())           # return ESTOI for monitoring


def si_snr(estimate: torch.Tensor, target: torch.Tensor) -> torch.Tensor:
    """Scale-Invariant Signal-to-Noise Ratio (batch, signal_length)."""
    target = target - target.mean(dim=-1, keepdim=True)
    estimate = estimate - estimate.mean(dim=-1, keepdim=True)
    dot = (estimate * target).sum(dim=-1, keepdim=True)
    s_target = dot * target / ((target ** 2).sum(dim=-1, keepdim=True) + 1e-8)
    e_noise = estimate - s_target
    si_snr_val = 10 * torch.log10(
        (s_target ** 2).sum(dim=-1) / ((e_noise ** 2).sum(dim=-1) + 1e-8) + 1e-8
    )
    return si_snr_val.mean()


def gradient_check(model: nn.Module, noisy: torch.Tensor, clean: torch.Tensor,
                    sample_rate: int, extended: bool) -> float:
    """Check gradient magnitude before committing to a long training run.

    If mean gradient < 1e-5 at epoch 1, the loss is not training this model
    for this SNR range. Switch to extended=True or add SI-SNR co-loss.
    """
    loss_fn = NegSTOILoss(sample_rate=sample_rate, extended=extended)
    model.zero_grad()
    enhanced = model(noisy)
    loss = loss_fn(enhanced, clean)
    loss.backward()
    grad_magnitude = torch.stack([
        p.grad.abs().mean() for p in model.parameters() if p.grad is not None
    ]).mean().item()
    if grad_magnitude < 1e-5:
        import warnings
        warnings.warn(
            f"Mean gradient magnitude = {grad_magnitude:.2e} with "
            f"NegSTOILoss(extended={extended}). This is effectively zero — "
            f"the loss is not training this model at this SNR range. "
            f"Try extended=True (ESTOI) or add SI-SNR as a co-loss.",
            stacklevel=2
        )
    return grad_magnitude


# STOI vs ESTOI operating range reference:
#   Standard STOI (extended=False):
#     Designed for: 0 to 20 dB SNR (telephone noise, mild interference)
#     Saturates below: ~0 dB SNR (gradient effectively zero)
#     Training gradient: adequate for 0–15 dB SNR speech enhancement
#
#   ESTOI (extended=True, Søren Jensen et al. 2016):
#     Designed for: -15 to 10 dB SNR (cafeteria, street, loud environments)
#     Maintains sensitivity at: -15 dB SNR and below
#     Training gradient: 20–30× larger than standard STOI at -10 dB SNR
#     Use for: hearing aids, cochlear implants, communication headsets in noise

Why ESTOI maintains gradient sensitivity below 0 dB SNR and why standard STOI’s correlation saturates

Standard STOI (Taal et al. 2010) computes intelligibility as the average Pearson correlation between the short-time RMS envelopes of the clean reference and the processed signal, evaluated in each of the 15 1/3-octave bands from 150 to 4500 Hz, over a 30-frame sliding window. The normalisation step divides each short-time envelope segment by its L2 norm before computing the correlation. At moderate SNR (0–20 dB), this normalisation ensures that the correlation is sensitive to the shape of the envelope (i.e., the temporal modulations that carry speech intelligibility), regardless of absolute amplitude. At very low SNR (below 0 dB), the noise dominates the envelope in almost every 1/3-octave band and almost every 30-frame window. After normalisation, the clean reference envelope segment has unit norm, and the noisy/enhanced envelope segment also has unit norm but its direction (in the 30-dimensional frame space) is dominated by noise rather than speech. The correlation between the two unit-norm vectors is small and nearly constant regardless of how much noise the enhancement network removes, because even a perfect denoiser can only slightly shift the direction of the processed envelope in the high-noise regime. The derivative of this small correlation with respect to the enhancement network’s parameters is correspondingly small — not exactly zero, but small enough to prevent Adam from making meaningful weight updates in 100 epochs. ESTOI replaces this inner-product normalisation with a different formulation: it uses a binary ideal ratio mask applied to the reference spectrum as the template, computes the correlation in a modified spectro-temporal domain, and applies a different clipping threshold that makes the metric more sensitive to envelope shape changes at low SNR. The practical effect: at −10 dB SNR, ESTOI’s gradient magnitude with respect to the enhancement network is approximately 28× larger than standard STOI’s, providing a usable training signal for the full −15 to 5 dB SNR range targeted by hearing aid applications.

Southfield Torch STOI Ltd.’s retainer engagement was 2.0h: 0.5h triage (trace training loss plateau at −0.692; compute STOI unprocessed baseline on test set: 0.693; confirm network is essentially identity: (output − input).norm() = 1.3% of input.norm(); check epoch-1 gradient magnitude: 3.1×10−6; test gradient with NegSTOILoss(extended=True): epoch-1 gradient 8.7×10−5); 0.5h root cause (derive STOI saturation at −10 dB SNR: oracle STOI improvement = 0.048 over 10 dB range; gradient 0.005/dB insufficient for 1024-channel U-Net; derive ESTOI formulation advantage for low-SNR hearing aid target; build gradient_check() utility to prevent future gradient starvation; recommend 0.5×ESTOI + 0.5×SI-SNR for training stability); 1.0h fix (update training script: replace NegSTOILoss(extended=False) with NegSTOILoss(extended=True) + 0.5×SI-SNR co-loss; add gradient magnitude check at epoch 1; retrain 100 epochs in 2 days; ESTOI=0.762 on test set vs 0.693 unprocessed; clinical re-test: 68.4% correct at −10 dB vs 53.0% unprocessed; Δ= +15.4 percentage points; exceeds FDA 10 pp efficacy threshold; 2.0h total). Hours logged to HourTab with per-session breakdown.

Related retainer posts


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 →