|
| 1 | +# Implementation Plan: Expand Speech Representation Model Coverage |
| 2 | + |
| 3 | +**Branch**: `20260428-101838-expand-speech-models` | **Date**: 2026-04-28 | **Spec**: [spec.md](spec.md) |
| 4 | + |
| 5 | +## Summary |
| 6 | + |
| 7 | +Expand senselab's speech representation model coverage by integrating S3PRL (30+ SSL models), broadening SpeechBrain access, adding NeMo ASR, enabling dedicated Pyannote VAD, creating a model registry, and providing a tutorial reproducing the speaker identity coding paper's benchmarking pipeline. |
| 8 | + |
| 9 | +## Technical Context |
| 10 | + |
| 11 | +**Language/Version**: Python 3.11-3.12 |
| 12 | +**Primary Dependencies**: s3prl (subprocess venv), speechbrain, pyannote-audio, nemo_toolkit (subprocess venv), transformers |
| 13 | +**Storage**: N/A |
| 14 | +**Testing**: pytest for unit tests, papermill for tutorials |
| 15 | +**Target Platform**: Linux (CI), macOS (dev), Google Colab (tutorials) |
| 16 | +**Project Type**: Library extension + tutorials + documentation |
| 17 | + |
| 18 | +## Constitution Check |
| 19 | + |
| 20 | +| Principle | Status | Notes | |
| 21 | +|-----------|--------|-------| |
| 22 | +| I. UV-Managed Python | PASS | All execution via uv; subprocess venvs for S3PRL/NeMo | |
| 23 | +| II. Encapsulated Testing | PASS | Tests in uv-managed venv | |
| 24 | +| III. Commit Early and Often | PASS | Incremental per-phase commits | |
| 25 | +| IV. CI Must Stay Green | PASS | New tests + existing tests must pass | |
| 26 | +| V. Memory-Driven Anti-Pattern Avoidance | PASS | Follows subprocess venv pattern from prior work | |
| 27 | +| VI. No Unnecessary API Calls | PASS | Models cached after first download | |
| 28 | +| VII. Simplicity First | PASS | Uses existing patterns (subprocess venv, model classes) | |
| 29 | +| VIII. No Hardcoded Parameters | PASS | Model names, venv paths configurable | |
| 30 | + |
| 31 | +## Project Structure |
| 32 | + |
| 33 | +```text |
| 34 | +src/senselab/audio/tasks/ |
| 35 | +├── ssl_embeddings/ |
| 36 | +│ ├── self_supervised_features.py # UPDATED (add S3PRL + SpeechBrain backends) |
| 37 | +│ ├── s3prl.py # NEW (S3PRL subprocess venv worker) |
| 38 | +│ └── doc.md # UPDATED (comprehensive model list) |
| 39 | +├── speech_to_text/ |
| 40 | +│ ├── nemo.py # NEW (NeMo ASR subprocess venv) |
| 41 | +│ └── api.py # UPDATED (NeMo backend option) |
| 42 | +├── voice_activity_detection/ |
| 43 | +│ ├── pyannote_vad.py # NEW (dedicated Pyannote VAD) |
| 44 | +│ └── api.py # UPDATED (VAD model option) |
| 45 | +
|
| 46 | +tutorials/audio/ |
| 47 | +├── ssl_embeddings_comparison.ipynb # NEW (multi-model embedding comparison) |
| 48 | +├── speaker_identity_benchmark.ipynb # NEW (reproduce paper's 17-model benchmark) |
| 49 | +
|
| 50 | +docs/ |
| 51 | +└── model_registry.md # NEW (or generated page) |
| 52 | +``` |
| 53 | + |
| 54 | +## Implementation Phases |
| 55 | + |
| 56 | +### Phase 1: S3PRL Subprocess Venv Integration (US1 — P1) |
| 57 | + |
| 58 | +**Goal**: Add S3PRL models as a backend for SSL embedding extraction via subprocess venv. |
| 59 | + |
| 60 | +1. Create `s3prl.py` with subprocess worker script that: |
| 61 | + - Loads model via `s3prl.hub` |
| 62 | + - Accepts audio as FLAC files |
| 63 | + - Extracts hidden states / embeddings |
| 64 | + - Returns as numpy arrays via JSON |
| 65 | +2. Create `S3PRLModel` or use string-based model selection |
| 66 | +3. Update `ssl_embeddings` API to route S3PRL models to subprocess backend |
| 67 | +4. Write tests for at least 3 S3PRL models (APC, TERA, CPC) |
| 68 | +5. Update `ssl_embeddings/doc.md` with S3PRL model table |
| 69 | + |
| 70 | +### Phase 2: SpeechBrain Embedding Unification (US1 — P1) |
| 71 | + |
| 72 | +**Goal**: Make SpeechBrain speaker encoders accessible through ssl_embeddings in addition to speaker_embeddings. |
| 73 | + |
| 74 | +1. Update `ssl_embeddings` API to accept SpeechBrainModel and route to existing speaker encoder infrastructure |
| 75 | +2. This is primarily an API routing change — the actual SpeechBrain encode_batch() already works |
| 76 | +3. Document in ssl_embeddings/doc.md |
| 77 | + |
| 78 | +### Phase 3: NeMo ASR (US3 — P2) |
| 79 | + |
| 80 | +**Goal**: Add NeMo Conformer ASR as a subprocess venv option for speech-to-text. |
| 81 | + |
| 82 | +1. Create `nemo.py` in speech_to_text with subprocess worker script |
| 83 | +2. Reuse existing NeMo subprocess venv (add nemo ASR dependencies if missing) |
| 84 | +3. Update `transcribe_audios` API to accept NeMo models |
| 85 | +4. Test with `nvidia/stt_en_conformer_ctc_large` |
| 86 | + |
| 87 | +### Phase 4: Pyannote Dedicated VAD (US3 — P2) |
| 88 | + |
| 89 | +**Goal**: Expose Pyannote's VAD pipeline as a distinct option. |
| 90 | + |
| 91 | +1. Create `pyannote_vad.py` with dedicated VAD pipeline (not diarization-based) |
| 92 | +2. Update VAD API to support model selection |
| 93 | +3. Test with `pyannote/voice-activity-detection` |
| 94 | + |
| 95 | +### Phase 5: Model Registry + Documentation (US4 — P2) |
| 96 | + |
| 97 | +**Goal**: Create a comprehensive model registry and update all docs. |
| 98 | + |
| 99 | +1. Create YAML data source with all supported models |
| 100 | +2. Generate model_registry.md from YAML |
| 101 | +3. Update ssl_embeddings/doc.md with complete model table |
| 102 | +4. Update README.md features section if needed |
| 103 | + |
| 104 | +### Phase 6: Expand Speaker Embeddings Tutorial (US2 — P2) |
| 105 | + |
| 106 | +**Goal**: Expand existing `extract_speaker_embeddings.ipynb` with multi-backend comparison exploring how different representations capture speaker identity. |
| 107 | + |
| 108 | +1. Add S3PRL, HuggingFace SSL sections to existing tutorial |
| 109 | +2. Add comparison visualization (t-SNE, cosine similarity) |
| 110 | +3. Pedagogical explanations of supervised vs self-supervised vs generative approaches |
| 111 | + |
| 112 | +### Phase 7: Polish |
| 113 | + |
| 114 | +1. Run all tests locally |
| 115 | +2. Run pre-commit |
| 116 | +3. Push and verify CI |
| 117 | +4. Merge |
| 118 | + |
| 119 | +## Risk Mitigation |
| 120 | + |
| 121 | +| Risk | Mitigation | |
| 122 | +|------|-----------| |
| 123 | +| S3PRL venv creation slow | Cache venv; only create on first use | |
| 124 | +| S3PRL model download large | Tests use smallest models (APC < 5MB) | |
| 125 | +| NeMo ASR model large (~500MB) | CPU timeout generous; test with small model if available | |
| 126 | +| Some paper models unavailable | Document which are accessible (15/17 target) | |
0 commit comments