Upload README.md with huggingface_hub
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102---license: cc-by-4.0tags:- speaker-diarization- coreml- apple-silicon- neural-engine- sortformerdatasets:- voxconverselanguage:- enpipeline_tag: audio-classification---# Sortformer Diarization (CoreML)CoreML port of [NVIDIA Sortformer](https://arxiv.org/abs/2409.06656) for end-to-end streaming speaker diarization on Apple Silicon.Runs on the Neural Engine via CoreML. No separate embedding extraction or clustering — the model directly predicts per-frame speaker activity for up to 4 speakers.## Model Details- **Architecture**: Sortformer (Sort Loss + 17-layer FastConformer encoder + 18-layer Transformer)- **Base model**: `nvidia/diar_streaming_sortformer_4spk-v2.1` (117M params)- **Task**: Speaker diarization (up to 4 speakers)- **Input**: 128-dim log-mel features, streamed in chunks- **Output**: Per-frame speaker activity probabilities (sigmoid)- **Format**: CoreML `.mlmodelc` (compiled pipeline, 2 sub-models)- **Size**: ~230 MB## Streaming Configuration| Parameter | Value ||-----------|-------|| Sample rate | 16 kHz || Mel bins | 128 || n_fft | 400 || Hop length | 160 || Chunk length | 6s || Left context | 1 chunk || Right context | 7 chunks || Subsampling factor | 8 || Speaker cache length | 188 frames || FIFO length | 40 frames || Max speakers | 4 |## Input/Output Shapes**Inputs:**| Tensor | Shape | Description ||--------|-------|-------------|| `chunk` | `[1, 112, 128]` | Mel features for current chunk || `chunk_lengths` | `[1]` | Valid frames in chunk || `spkcache` | `[1, 188, 512]` | Speaker cache state || `spkcache_lengths` | `[1]` | Valid entries in speaker cache || `fifo` | `[1, 40, 512]` | FIFO buffer state || `fifo_lengths` | `[1]` | Valid entries in FIFO |**Outputs:**| Tensor | Shape | Description ||--------|-------|-------------|| `speaker_preds_out` | `[1, 242, 4]` | Speaker activity probabilities || `chunk_pre_encoder_embs_out` | `[1, 14, 512]` | Chunk embeddings for state update || `chunk_pre_encoder_lengths_out` | `[1]` | Valid embedding frames |## UsageUsed by [speech-swift](https://github.com/soniqo/speech-swift) for speaker diarization:```bashaudio diarize meeting.wav --engine sortformer``````swiftlet diarizer = try await SortformerDiarizer.fromPretrained()let result = diarizer.diarize(audio: samples, sampleRate: 16000)for segment in result.segments {print("Speaker \(segment.speakerId): \(segment.startTime)s - \(segment.endTime)s")}```## Pipeline ArchitectureThe model is a CoreML pipeline with two sub-models:1. **PreEncoder** (model0) — Runs `pre_encode` on the mel chunk, concatenates with speaker cache and FIFO state2. **Head** (model1) — Full FastConformer encoder + Transformer + sigmoid speaker headsState management (FIFO rotation, speaker cache compression) is handled in Swift outside the model.## LicenseCC-BY-4.0---- **Guide**: [soniqo.audio/guides/diarize](https://soniqo.audio/guides/diarize)- **Docs**: [soniqo.audio](https://soniqo.audio)- **GitHub**: [soniqo/speech-swift](https://github.com/soniqo/speech-swift)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110---license: cc-by-4.0language:- entags:- speaker-diarization- coreml- apple-silicon- neural-engine- sortformer- streamingdatasets:- voxconversebase_model: nvidia/diar_streaming_sortformer_4spk-v2.1library_name: coremlpipeline_tag: audio-classification---# Sortformer Diarization (CoreML)CoreML port of [NVIDIA Sortformer](https://arxiv.org/abs/2409.06656) for end-to-end speaker diarization on Apple Silicon. Runs on the Neural Engine. No separate embedding extraction or clustering — the model directly predicts per-frame speaker activity for up to 4 speakers, with streaming state (speaker cache + FIFO) carried across calls.## Model| | ||---|---|| Architecture | Sortformer (Sort Loss + 17-layer FastConformer + 18-layer Transformer) || Base model | [`nvidia/diar_streaming_sortformer_4spk-v2.1`](https://huggingface.co/nvidia/diar_streaming_sortformer_4spk-v2.1) (117M params) || Precision | FP16 compute, FP32 I/O boundaries || Sample rate | 16 kHz, 128 mel bins (n_fft 400, hop 160) || Max speakers | 4 (arrival-order slots) || Speaker cache / FIFO | 188 / 40 encoder frames || Frame duration | 80 ms per prediction frame |Three variants ship from the same checkpoint, differing only in chunk shape:| Variant | New audio per call | Mel input | Use case ||---|---|---|---|| `Sortformer` (default) | ~27 s | `[1, 3048, 128]` | offline batch, highest throughput || `Sortformer_balanced` | ~8 s | `[1, 968, 128]` | ~3× faster first-load compile || `Sortformer_streaming` | 480 ms | `[1, 112, 128]` | incremental / realtime |## Files| File | Size | Description ||---|---|---|| `Sortformer.mlmodelc` / `.mlpackage` | ~230 MB | default variant (compiled / source) || `Sortformer_balanced.mlmodelc` / `.mlpackage` | ~230 MB | balanced variant || `Sortformer_streaming.mlmodelc` / `.mlpackage` | ~230 MB | streaming variant || `config.json`, `config_balanced.json`, `config_streaming.json` | <1 KB | chunk-shape hyperparameters per variant |## PerformanceMeasured on M-series Apple Silicon (Neural Engine, warm):| Variant | Per-call latency | Realtime factor ||---|---|---|| default | one call per ~27 s of audio | ~125–750× || balanced | one call per ~8 s | hundreds of × || streaming | **8.1 ms median per 480 ms step** | ~59× per step; ~39× end-to-end incremental |The streaming export is parity-gated: driven by NeMo's own streaming featureloader and cache-update algorithm, it matches NeMo's native`forward_streaming` loop at **100% frame-decision agreement (MAE 0.0005)**.On a five-file VoxConverse-dev pilot, the incremental session reaches 8.1%DER (collar 0.25) with correct speaker counts on all files.## Streaming interfaceThe streaming variant carries state through the CoreML interface; thespeaker-cache update runs host-side between calls.**Inputs:** `chunk [1,112,128]`, `chunk_lengths [1]`, `spkcache [1,188,512]`,`spkcache_lengths [1]`, `fifo [1,40,512]`, `fifo_lengths [1]`**Outputs:** `speaker_preds_out [1,242,4]`,`chunk_pre_encoder_embs_out [1,14,512]`, `chunk_pre_encoder_lengths_out [1]`The pipeline contains two sub-models: **PreEncoder** (mel pre-encode +state concat) and **Head** (FastConformer + Transformer + sigmoid heads).## Usage```swift// Whole-buffer diarizationlet diarizer = try await SortformerDiarizer.fromPretrained()let result = diarizer.diarize(audio: samples, sampleRate: 16000)// Incremental streaming: push PCM in any size, stable speaker slotslet session = try await SortformerStreamingSession.fromPretrained()let snapshot = try session.push(audio: samples)let final = try session.finish()``````bashspeech diarize meeting.wav --engine sortformer```## Source- Upstream model: [nvidia/diar_streaming_sortformer_4spk-v2.1](https://huggingface.co/nvidia/diar_streaming_sortformer_4spk-v2.1) · [Sortformer paper](https://arxiv.org/abs/2409.06656) · [Streaming Sortformer paper](https://arxiv.org/abs/2507.18446)- Upstream license: NVIDIA Open Model License (weights); this conversion is published under CC-BY-4.0 with attribution to NVIDIA.## Links- [speech-swift](https://github.com/soniqo/speech-swift) — Apple SDK- [Docs](https://soniqo.audio/getting-started) — install and CLI docs- [Guide](https://soniqo.audio/guides/diarize) — speaker diarization guide- [soniqo.audio](https://soniqo.audio) — website- [blog](https://soniqo.audio/blog) — blog
README.md+82-74