Upload 25 files
Browse files
README.md
CHANGED
|
@@ -1,137 +1,87 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
## Original Model
|
| 6 |
-
|
| 7 |
-
- **Source**: [nvidia/diar_streaming_sortformer_4spk-v2.1](https://huggingface.co/nvidia/diar_streaming_sortformer_4spk-v2.1)
|
| 8 |
-
- **Paper**: [Sortformer: Seamless Integration of Speaker Diarization and ASR](https://arxiv.org/abs/2409.06656)
|
| 9 |
-
- **Benchmark**: 20.57% DER on AMI SDM (NVIDIA reported)
|
| 10 |
-
|
| 11 |
-
## Models
|
| 12 |
-
|
| 13 |
-
| Model | Description | Input | Output |
|
| 14 |
-
|-------|-------------|-------|--------|
|
| 15 |
-
| `Pipeline_Preprocessor.mlpackage` | Mel spectrogram extraction | Audio waveform | 128-dim mel features |
|
| 16 |
-
| `Pipeline_PreEncoder.mlpackage` | FastConformer encoder + Transformer | Mel features + state | Encoded embeddings |
|
| 17 |
-
| `Pipeline_Head_Fixed.mlpackage` | Speaker prediction head | Embeddings | 4-speaker probabilities |
|
| 18 |
|
| 19 |
## Configuration
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
```swift
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
let predictions = headInput.featureValue(for: "speaker_preds")
|
| 86 |
-
```
|
| 87 |
-
|
| 88 |
-
## Mel Spectrogram Settings
|
| 89 |
-
|
| 90 |
-
For compatibility with the original NeMo model:
|
| 91 |
-
|
| 92 |
-
```python
|
| 93 |
-
mel_config = {
|
| 94 |
-
"sample_rate": 16000,
|
| 95 |
-
"n_fft": 512,
|
| 96 |
-
"win_length": 400, # 25ms
|
| 97 |
-
"hop_length": 160, # 10ms
|
| 98 |
-
"n_mels": 128,
|
| 99 |
-
"preemph": 0.97,
|
| 100 |
-
"log_zero_guard_value": 2**-24,
|
| 101 |
-
"normalize": "per_feature",
|
| 102 |
}
|
| 103 |
```
|
| 104 |
|
| 105 |
-
##
|
| 106 |
-
|
| 107 |
-
1. **Chunk audio** into ~480ms windows (48 mel frames core + context)
|
| 108 |
-
2. **Compute mel spectrogram** for each chunk
|
| 109 |
-
3. **Run PreEncoder** with current state (spkcache + fifo)
|
| 110 |
-
4. **Run Head** to get 4-speaker probabilities
|
| 111 |
-
5. **Update state** (spkcache/fifo buffers)
|
| 112 |
-
6. **Threshold predictions** (default: 0.5) for binary speaker activity
|
| 113 |
-
|
| 114 |
-
## Accuracy
|
| 115 |
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
-
##
|
| 119 |
|
| 120 |
-
|
| 121 |
-
- Apple Silicon (M1/M2/M3) recommended
|
| 122 |
-
- Python: `coremltools`, `numpy`, `torch`, `torchaudio`
|
| 123 |
-
|
| 124 |
-
## License
|
| 125 |
-
|
| 126 |
-
Apache 2.0 (following NVIDIA NeMo licensing)
|
| 127 |
-
|
| 128 |
-
## Citation
|
| 129 |
-
|
| 130 |
-
```bibtex
|
| 131 |
-
@article{park2024sortformer,
|
| 132 |
-
title={Sortformer: Seamless Integration of Speaker Diarization and ASR by Bridging Timestamps and Tokens},
|
| 133 |
-
author={Park, Taejin and Huang, He and Koluguri, Nithin and Georgiou, Panagiotis and Watanabe, Shinji and Ginsburg, Boris},
|
| 134 |
-
journal={arXiv preprint arXiv:2409.06656},
|
| 135 |
-
year={2024}
|
| 136 |
-
}
|
| 137 |
-
```
|
|
|
|
| 1 |
+
# Sortformer CoreML Models - Gradient Descent Configuration
|
| 2 |
|
| 3 |
+
Streaming speaker diarization models converted from NVIDIA's Sortformer to CoreML.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
## Configuration
|
| 6 |
|
| 7 |
+
**Gradient Descent** - Higher quality, more context:
|
| 8 |
+
|
| 9 |
+
| Parameter | Value |
|
| 10 |
+
|-----------|-------|
|
| 11 |
+
| chunk_len | 6 |
|
| 12 |
+
| chunk_right_context | 7 |
|
| 13 |
+
| chunk_left_context | 1 |
|
| 14 |
+
| fifo_len | 40 |
|
| 15 |
+
| spkcache_len | 188 |
|
| 16 |
+
| spkcache_update_period | 31 |
|
| 17 |
+
|
| 18 |
+
## Model Input Shapes
|
| 19 |
+
|
| 20 |
+
| Model | Input | Shape |
|
| 21 |
+
|-------|-------|-------|
|
| 22 |
+
| Preprocessor | audio_signal | [1, 18160] |
|
| 23 |
+
| Preprocessor | length | [1] |
|
| 24 |
+
| PreEncoder | chunk | [1, 112, 128] |
|
| 25 |
+
| PreEncoder | chunk_lengths | [1] |
|
| 26 |
+
| PreEncoder | spkcache | [1, 188, 512] |
|
| 27 |
+
| PreEncoder | spkcache_lengths | [1] |
|
| 28 |
+
| PreEncoder | fifo | [1, 40, 512] |
|
| 29 |
+
| PreEncoder | fifo_lengths | [1] |
|
| 30 |
+
| Head | pre_encoder_embs | [1, 242, 512] |
|
| 31 |
+
| Head | pre_encoder_lengths | [1] |
|
| 32 |
+
| Head | chunk_embs_in | [1, 14, 512] |
|
| 33 |
+
| Head | chunk_lens_in | [1] |
|
| 34 |
+
|
| 35 |
+
## Model Output Shapes
|
| 36 |
+
|
| 37 |
+
| Model | Output | Shape |
|
| 38 |
+
|-------|--------|-------|
|
| 39 |
+
| Preprocessor | features | [1, 112, 128] |
|
| 40 |
+
| Preprocessor | feature_lengths | [1] |
|
| 41 |
+
| PreEncoder | pre_encoder_embs | [1, 242, 512] |
|
| 42 |
+
| PreEncoder | pre_encoder_lengths | [1] |
|
| 43 |
+
| PreEncoder | chunk_embs_in | [1, 14, 512] |
|
| 44 |
+
| PreEncoder | chunk_lens_in | [1] |
|
| 45 |
+
| Head | speaker_preds | [1, 242, 4] |
|
| 46 |
+
| Head | chunk_pre_encoder_embs | [1, 14, 512] |
|
| 47 |
+
| Head | chunk_pre_encoder_lengths | [1] |
|
| 48 |
+
|
| 49 |
+
## Files
|
| 50 |
+
|
| 51 |
+
### Models
|
| 52 |
+
- `Pipeline_Preprocessor.mlpackage` / `.mlmodelc` - Audio to mel features
|
| 53 |
+
- `Pipeline_PreEncoder.mlpackage` / `.mlmodelc` - Mel features + state to embeddings
|
| 54 |
+
- `Pipeline_Head_Fixed.mlpackage` / `.mlmodelc` - Embeddings to speaker predictions
|
| 55 |
+
|
| 56 |
+
### Scripts
|
| 57 |
+
- `export_gradient_descent.py` - Export script used to create these models
|
| 58 |
+
- `coreml_wrappers.py` - PyTorch wrapper classes for export
|
| 59 |
+
- `streaming_inference.py` - Python streaming inference example
|
| 60 |
+
- `mic_inference.py` - Real-time microphone demo
|
| 61 |
+
|
| 62 |
+
## Usage with FluidAudio (Swift)
|
| 63 |
|
| 64 |
```swift
|
| 65 |
+
let config = SortformerConfig.gradientDescent
|
| 66 |
+
let diarizer = try await SortformerDiarizer(config: config)
|
| 67 |
+
|
| 68 |
+
// Process audio chunks
|
| 69 |
+
while let samples = getAudioChunk() {
|
| 70 |
+
if let result = try diarizer.processChunk(samples) {
|
| 71 |
+
// result.probabilities - confirmed speaker probabilities
|
| 72 |
+
// result.tentativeProbabilities - preview (may change)
|
| 73 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
}
|
| 75 |
```
|
| 76 |
|
| 77 |
+
## Performance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
+
| Metric | Value |
|
| 80 |
+
|--------|-------|
|
| 81 |
+
| Latency | ~1.04s (7 * 80ms right context + chunk) |
|
| 82 |
+
| DER (AMI) | ~30.8% |
|
| 83 |
+
| RTFx | ~8.2x on Apple Silicon |
|
| 84 |
|
| 85 |
+
## Source
|
| 86 |
|
| 87 |
+
Original model: [nvidia/diar_streaming_sortformer_4spk-v2.1](https://huggingface.co/nvidia/diar_streaming_sortformer_4spk-v2.1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|