DISENT-KWS β€” Speech Disentanglement for Robust Custom Word Detection

DISENT-KWS Training Pipeline

1.806M params 4.69% Keyword EER 0.8425 AUC 0.60 MB ONNX 0.0132 real-time factor MIT License



Quick Start

# Install dependencies
uv sync --all-extras

# Run tests (verify 60+ tests pass)
make test

# Option A: Live record 5 utterances from mic, then enroll
python src/demo.py record --model model_final.pt --out enrollment.pt

# Option B: Provide pre-recorded WAV files
python src/demo.py enroll \
    --recordings ./my_recordings/*.wav \
    --model model_final.pt \
    --out enrollment.pt

# Real-time detection
python src/demo.py detect --enrollment enrollment.pt --auto-threshold --vad-threshold 0.02

Project Artifacts

Technical Documentation

All technical documentation is organized in the docs/ directory:

DocumentDescription
docs/solution_architecture.mdArchitecture, mathematical foundations, loss functions, ablation study & results
docs/installation.mdEnvironment setup, dependencies, dataset configuration
docs/user_guide.mdTraining pipeline, speaker enrollment, real-time demo, result reproducibility
docs/ax.mdAgentic AI setup, workflows, tool chaining, and developer retrospective

Source Code

The complete source code is organized under src/:

sβ”œβ”œβ”œβ”œβ”‚β”‚β”‚β”‚β”‚β”‚β”œβ”‚β”‚β”‚β”œβ”‚β”‚β”‚β”œβ”‚β”‚β”‚β””r────────c────────/ctdmβ”œβ”œβ”œβ”œβ”œβ””dβ”œβ”œβ””tβ”œβ”œβ””eβ”œβ”œβ””eβ””oreo──────a───r───v───n─namd──────t───a───a───r─fioeailoin.lbtfhsd/dasnlds/baeleg.psceieciauyioicebxln.py/_mlaostgnnsshnlpmrpyrpmdreamtgseecaoeoyeo.senseh/endhtrnlsrp.rtenestumittlnayp._ttt.alao./.elypvsaipnernppt.y2.tcygrk.yy.p.pi.l..ppypyopeppyyyny.yysp.ypy########################HMRBSMFCDUAGRDLAGGEFCOOPyueChaiaunuSISoARRvuoNfrpla-amLuaidCRPsMLLalmNfoetlRrbMslfi,,-s-llpXltri-eeaa-iobSaluoiop-tsdclgeVMafouaaKnentapiNSoadloUsuftmtPexeyrhmeeSnCtoxSentobiInppaaetnMdoemaCAdcmgdotosemscinodeNtarane-rpeeseo/tfsdeleixavwteettndiocerenno,dr&aiaxetrceDorolsbornals&ktrreorinmr,iosPfmbueersaadlieea&slrupeaIraimebanrrsLel&on-ntaN/c&niratgsai,mtcucibTktin,ce(weubedotphol8eiangkdlpimgrSnitimnayorgtbahtbmiptsyosatqwncdeoCyohlePeepncr(iuoheemnoenynhcanihkToarwintpenreEtrAutc+eiAnnditteovtMaaugaadn,ttercr1iAtsgmnlCugsiehcytaDciemeg,LlFtzntol)soenlUeAuarDuprfmnlnteRB,dtoSroba+ootameyilPeillopa,tejMDolnolEtidineIEnmactcbChpesotcTeuokaAierpnte,ngn,cPnlseistmtkAgieotlerd-ndnianauLe,mttcaipaeatlteKtnterDocihtryoe(ul)nasrodpbsseas,atekisseocrno)rer

Models Used

ModelDescriptionLicense
SpeechBrain ECAPA-TDNNPre-trained speaker verification teacherApache 2.0

Models Published

ModelLinkFormatSize
DISENT-KWSπŸ€— Hugging Face (free tier)PyTorch + ONNX7 MB + 0.60 MB

The model is hosted on Hugging Face’s free tier β€” no payment required to download or use.

Datasets Used

DatasetUsageSamplesLicense
Google Speech Commands v2Keyword spotting pre-training105K utterancesCC BY 4.0
VoxCeleb1Speaker verification training153K utterances (1,251 speakers)CC BY 4.0
LibriPhraseHard-negative triplet pairs (up to 3K triplets generated from metadata)Apache 2.0
MUSANNoise augmentation109 hrsCC BY 4.0

Datasets Published

No custom datasets were published. All datasets listed above are publicly available.


Architecture Overview

Parameter Budget Distribution

The system uses a dual-head disentangled architecture built on a shared BC-ResNet-2 encoder (total 1.806M parameters):

  1. Shared Encoder (BC-ResNet-2) β€” Broadcasted residual network, 33.8K params
  2. Temporal Block (Mamba SSM / Dilated Conv1D) β€” O(T) temporal context modeling, 10.3K params
  3. Phonetic Head (Causal Conformer) β€” Extracts keyword-discriminative embeddings zβ‚šβ‚•β‚™ ∈ ℝ¹⁹², 1,673K params
  4. Speaker Head (ECAPA-TDNN Lite) β€” Extracts speaker-discriminative embeddings zβ‚›β‚šβ‚– ∈ ℝ¹⁹², 88.8K params
  5. Disentanglement Module (GRL + CLUB) β€” Adversarial gradient reversal + mutual information minimization forces zβ‚šβ‚•β‚™ βŸ‚ zβ‚›β‚šβ‚–
  6. Dual-Gate Scorer β€” Weighted cosine similarity (w_kw=0.30, w_spk=0.65) with EMA smoothing and DET-calibrated threshold (Ο„=0.2222)

Three-Layer Defense Against False Accepts

LayerMechanismFailure Mode Blocked
β‘ FiLM ConditioningDirects attention toward enrolled speaker/keyword
β‘‘GRL + CLUB DisentanglementPrevents speaker ID leaking into phonetic embeddings
β‘’Dual-Gate ScoringBoth keyword AND speaker must match independently

Final Performance Benchmarks

Evaluated on Google Speech Commands v2 test set (11,005 samples, 35 classes) and VoxCeleb1 (1,251 speakers). Scorer weights calibrated via joint verification grid search over 10Γ—10 weight combinations + DET-driven threshold selection.

MetricAchievedTargetStatus
Parameters1.806 M< 3.0 Mβœ…
ONNX Model Size0.60 MB (INT8)β€”βœ…
CPU Latency26.43 ms (p95: 28.29 ms)< 200 msβœ…
Real-Time Factor (xRT)0.0132< 0.20βœ…
Keyword EER (standalone)4.69%lowβœ…
Speaker EER (standalone)17.86%lowβœ…
Joint EER23.47%β€”β€”
Joint AUC0.8425β€”βœ…
Optimal Scorer Weightswβ‚–w=0.30, wβ‚›β‚šβ‚–=0.65β€”βœ…
EER Threshold (Ο„)0.2222β€”βœ…

Detection Error Trade-off (DET) Curve

Joint DET Curve

SNR Robustness Across -5 dB to 30 dB

SNR Robustness Evaluation


Ablation Study Results

To isolate each component’s contribution, we systematically disabled modules and re-evaluated:

ConfigurationKeyword EER (%)Speaker EER (%)ParamsImpact
Full Model (baseline)4.6917.331.806 Mβ€”
No FiLM Conditioning4.6917.331.683 MSaves 123K params, no EER change on this test set
No Speaker Head4.69N/A1.806 MKWS-only mode; speaker verification disabled
No Temporal Block11.2225.481.796 MπŸ”΄ Keyword EER ↑6.53pp, Speaker EER ↑8.15pp
Equal Scorer Weights4.6917.331.806 MCalibrated 0.30/0.65 > equal 0.50/0.50

Ablation Study Visualization

Key Insight: The temporal block is the single most critical component β€” removing it degrades keyword EER by 2.4Γ— and speaker EER by 1.5Γ—.


Attribution

This project builds upon and transfers weights from the open-source SpeechBrain repository (ECAPA-TDNN for speaker verification).

Citation

If you use DISENT-KWS in your research, please cite it:

@misc{bt2026disentkws,
  title={DISENT-KWS: Speech Disentanglement for Robust Custom Word Detection},
  author={Banerjee, Sohini and Tripathi, Swarnim},
  year={2026},
  howpublished={\url{https://github.com/tripathiji1312/DISENT_KWS}},
  note={BC-ResNet-2 backbone with Causal Conformer phonetic head, ECAPA-TDNN Lite speaker head, and GRL+CLUB disentanglement. 1.806M parameters.}
}

Novel Contributions Developed for This Solution

InnovationDescription
Decoupled Dual-Head ArchitectureSeparate Causal Conformer (phonetic) and ECAPA-TDNN Lite (speaker) heads on a shared BC-ResNet-2 backbone
Feature DisentanglementGradient Reversal Layer (GRL) + CLUB Mutual Information estimator enforces orthogonal latent spaces
Dual-Gate ScorerWeighted cosine similarity (wβ‚–w=0.30, wβ‚›β‚šβ‚–=0.65) + EMA smoothing for stable real-time streaming
Calibration PipelineGrid-searched scorer weights + DET curve-driven threshold selection (Ο„=0.2222)
Rejection LossContrastive triplet loss with hard-negative mining from LibriPhrase for confuser rejection
GE2E Speaker Fine-tuningGeneralized End-to-End loss for speaker head refinement in Phase 3
Mamba SSM FallbackAutomatic fallback from Mamba to Dilated Conv1D for cross-platform compatibility