Skip to content

fix(cli/scoring): sort speaker ids so diarization speaker mapping is deterministic - #923

Merged
Alex-Wengg merged 3 commits into
mainfrom
fix/922-deterministic-speaker-mapping
Sep 14, 2026
Merged

Alex-Wengg merged 3 commits into
mainfrom
fix/922-deterministic-speaker-mapping

Conversation

@Alex-Wengg

@Alex-Wengg Alex-Wengg commented Sep 14, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #922 — same nondeterminism class as #911/#921, in the diarization scorer.

computeSpeakerMapping built its speaker index orders with Array(predicted.keys) / Array(groundTruth.keys). Swift dictionary iteration order is per-instance random (the hash seed incorporates the storage allocation — re-confirmed empirically on Swift 6.2.3), and both assignment paths (the subset DP and the greedy fallback) tie-break by first-encountered index via strict > comparisons. The confusion matrix rounds overlaps to integer milliseconds, so exact ties are realistic — and whenever two pairings tie, the winning speaker mapping (and JER) depended on random key enumeration order.

Evidence

Standalone harness on the scenario in the new test (two predicted speakers each overlapping one ground-truth speaker by exactly 4.75 s after the 0.25 s collar): the pre-fix code produced 2 distinct speaker mappings within a single 200-call process (3/3 runs), and fails the new test's predicate in 20/20 processes. With the fix: 1 mapping, always (right → spk_a, pinned in the test).

Fixes (commit 2 adds the full sweep from adversarial review)

  1. computeSpeakerMapping: sort both key arrays — ties resolve by the solver's fixed index-order rule over lexicographically sorted speaker ids; unambiguous assignments unchanged.
  2. offlineMetrics: the correctlyAssigned, jaccardScores, and unmapped-pred loops accumulated Doubles in dictionary order. Addition is not associative, and both DER and JER pass through near-zero cancellation (max(0, overlapSpeech - correctlyAssigned), 1.0 - averageJaccard) where a ulp-level reorder survives the Float cast — with 3+ speakers, DER/JER were still not bit-deterministic. All three loops now iterate in sorted key order.
  3. Streaming path (DiarizationBenchmark.calculateStreamingMetrics): overlapsByGtSpeaker.max(by: { $0.value < $1.value }) kept the first-encountered element among tied overlaps in random dictionary order — same class. Ties now break by smaller speaker id.

Tests

DiarizationSpeakerMappingTests: tied-overlap stability across 50 calls (each call regroups segments into fresh dictionaries, each with an independent per-allocation key order — the unfixed code fails this 20/20 processes), the exact tied winner pinned so silent tie-break changes fail loudly, plus an unambiguous-mapping correctness check.

🤖 Generated with Claude Code

…istic

computeSpeakerMapping enumerated predicted/ground-truth speakers via
Array(dict.keys) — a per-instance random order (see #911/#921) — and
both assignment solvers keep the first-encountered winner among tied
confusion-matrix entries, so the reported speaker mapping (and JER in
asymmetric cases) could differ between runs whenever two pairings tied
in millisecond-rounded overlap.

Reproduced in a standalone harness: two predicted speakers tying at
4.75 s overlap against one ground-truth speaker produced 2 distinct
mappings within a single 200-call process on the old code; sorted key
arrays yield 1. Ties now resolve by the assignment solver's fixed
index-order rule over lexicographically sorted speaker ids.

Fixes #922
@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown

Supertonic3 Smoke Test ✅

Check Result
Build
Model download (incl. VectorEstimatorVariants/ int4 buckets)
Model load
Synthesis pipeline (--ve-variant int4)
Output WAV ✅ (364.7 KB)

Runtime: 0m36s

Note: CI VMs lack a physical Neural Engine; the ANE-bucketed VectorEstimator falls back to CPU here. This validates download + variant resolution + synthesis, not ANE residency/perf.

Post-review fixes on the #922 branch:

- offlineMetrics still iterated speakerMapping / groundTruthBySpeaker /
  predictedBySpeaker dictionaries while accumulating Doubles. Addition
  is not associative and both der and jer pass through near-zero
  cancellation (max(0, overlapSpeech - correctlyAssigned) and
  1.0 - averageJaccard), where a ulp-level reorder survives the Float
  cast — so with 3+ speakers der/jer were still not run-to-run
  deterministic after the mapping fix. All three loops now iterate in
  sorted key order; debug mapping log also sorted.

- Streaming path had the same class:
  overlapsByGtSpeaker.max(by: { $0.value < $1.value }) keeps the
  first-encountered element among tied overlaps, in random dictionary
  order. Ties now break by smaller speaker id.

- Test pins the exact tied winner (["right": "spk_a"]) instead of
  count/values-set asserts, so a silent tie-break change that would
  shift recorded benchmark numbers fails the test. Winner re-verified
  via the standalone harness (200-call x 3-process: 1 distinct mapping;
  unambiguous scenario unchanged).

Review also empirically re-confirmed per-ALLOCATION dictionary seeding
(Swift 6.2.3): the unfixed code fails the new test's predicate in
20/20 processes, so the in-process 50-iteration loop is a real
regression guard.
@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown

VAD Benchmark Results

Performance Comparison

Dataset Accuracy Precision Recall F1-Score RTFx Files
MUSAN 94.0% 89.3% 100.0% 94.3% 565.4x faster 50
VOiCES 94.0% 89.3% 100.0% 94.3% 495.7x faster 50

Dataset Details

  • MUSAN: Music, Speech, and Noise dataset - standard VAD evaluation
  • VOiCES: Voices Obscured in Complex Environmental Settings - tests robustness in real-world conditions

✅: Average F1-Score above 70%

@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown

Sortformer High-Latency Benchmark Results

ES2004a Performance (30.4s latency config)

Metric Value Target Status
DER 30.3% <35%
Miss Rate 28.2% - -
False Alarm 0.9% - -
Speaker Error 1.2% - -
RTFx 14.5x >1.0x
Speakers 4/4 - -

Sortformer High-Latency • ES2004a • Runtime: 2m 51s • 2026-09-14T16:03:19.389Z

@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown

Parakeet EOU Benchmark Results ✅

Status: Benchmark passed
Chunk Size: 320ms
Files Tested: 100/100

Performance Metrics

Metric Value Description
WER (Avg) 7.03% Average Word Error Rate
WER (Med) 4.17% Median Word Error Rate
RTFx 5.60x Real-time factor (higher = faster)
Total Audio 470.6s Total audio duration processed
Total Time 85.7s Total processing time

Streaming Metrics

Metric Value Description
Avg Chunk Time 0.086s Average chunk processing time
Max Chunk Time 0.171s Maximum chunk processing time
EOU Detections 0 Total End-of-Utterance detections

Test runtime: 1m35s • 09/14/2026, 11:59 AM EST

RTFx = Real-Time Factor (higher is better) • Processing includes: Model inference, audio preprocessing, state management, and file I/O

@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown

PocketTTS Smoke Test ✅

Check Result
Build
Model download
Model load
Synthesis pipeline
Output WAV ✅ (146.3 KB)

Runtime: 0m5s

Note: PocketTTS uses CoreML MLState (macOS 15) KV cache + Mimi streaming state. CI VM lacks physical GPU — audio quality and performance may differ from Apple Silicon.

@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown

ASR Benchmark Results ✅

Status: All benchmarks passed

Parakeet v3 (multilingual)

Dataset WER Avg WER Med RTFx Status
test-clean 0.57% 0.00% 4.43x
test-other 1.19% 0.00% 2.59x

Parakeet v2 (English-optimized)

Dataset WER Avg WER Med RTFx Status
test-clean 0.80% 0.00% 4.65x
test-other 1.00% 0.00% 2.33x

Streaming (v3)

Metric Value Description
WER 0.00% Word Error Rate in streaming mode
RTFx 0.52x Streaming real-time factor
Avg Chunk Time 1.705s Average time to process each chunk
Max Chunk Time 1.946s Maximum chunk processing time
First Token 2.026s Latency to first transcription token
Total Chunks 31 Number of chunks processed

Streaming (v2)

Metric Value Description
WER 0.00% Word Error Rate in streaming mode
RTFx 0.56x Streaming real-time factor
Avg Chunk Time 1.759s Average time to process each chunk
Max Chunk Time 2.435s Maximum chunk processing time
First Token 1.857s Latency to first transcription token
Total Chunks 31 Number of chunks processed

Streaming tests use 5 files with 0.5s chunks to simulate real-time audio streaming

25 files per dataset • Test runtime: 8m13s • 09/14/2026, 12:03 PM EST

RTFx = Real-Time Factor (higher is better) • Calculated as: Total audio duration ÷ Total processing time
Processing time includes: Model inference on Apple Neural Engine, audio preprocessing, state resets between files, token-to-text conversion, and file I/O
Example: RTFx of 2.0x means 10 seconds of audio processed in 5 seconds (2x faster than real-time)

Expected RTFx Performance on Physical M1 Hardware:

• M1 Mac: ~28x (clean), ~25x (other)
• CI shows ~0.5-3x due to virtualization limitations

Testing methodology follows HuggingFace Open ASR Leaderboard

…lation

Closes the review's remaining test gap:

- Extract the streaming overlap-winner selection into
  StreamDiarizationBenchmark.bestOverlapMatch (internal, testable) and
  test it directly: 100 fresh tied dictionaries always yield the
  smaller speaker id; unambiguous max and empty-dict cases covered.

- Add a 3-speaker offlineMetrics test asserting mapping plus exact
  der/jer/speakerErrorRate stability across 50 calls, exercising the
  sorted Double-accumulation loops. Expected values verified with the
  standalone harness: mapping p1/p2/p3 -> gt_a/gt_b/gt_c, metrics
  bitwise identical within and across 5 processes.
@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown

Offline VBx Pipeline Results

Speaker Diarization Performance (VBx Batch Mode)

Optimal clustering with Hungarian algorithm for maximum accuracy

Metric Value Target Status Description
DER 10.4% <20% Diarization Error Rate (lower is better)
RTFx 11.21x >1.0x Real-Time Factor (higher is faster)

Offline VBx Pipeline Timing Breakdown

Time spent in each stage of batch diarization

Stage Time (s) % Description
Model Download 18.137 19.4 Fetching diarization models
Model Compile 7.773 8.3 CoreML compilation
Audio Load 0.065 0.1 Loading audio file
Segmentation 26.792 28.6 VAD + speech detection
Embedding 93.378 99.7 Speaker embedding extraction
Clustering (VBx) 0.110 0.1 Hungarian algorithm + VBx clustering
Total 93.641 100 Full VBx pipeline

Speaker Diarization Research Comparison

Offline VBx achieves competitive accuracy with batch processing

Method DER Mode Description
FluidAudio (Offline) 10.4% VBx Batch On-device CoreML with optimal clustering
FluidAudio (Streaming) 17.7% Chunk-based First-occurrence speaker mapping
Research baseline 18-30% Various Standard dataset performance

Pipeline Details:

  • Mode: Offline VBx with Hungarian algorithm for optimal speaker-to-cluster assignment
  • Segmentation: VAD-based voice activity detection
  • Embeddings: WeSpeaker-compatible speaker embeddings
  • Clustering: PowerSet with VBx refinement
  • Accuracy: Higher than streaming due to optimal post-hoc mapping

🎯 Offline VBx Test • AMI Corpus ES2004a • 1049.0s meeting audio • 120.3s processing • Test runtime: 2m 3s • 09/14/2026, 11:56 AM EST

@github-actions

Copy link
Copy Markdown

Speaker Diarization Benchmark Results

Speaker Diarization Performance

Evaluating "who spoke when" detection accuracy

Metric Value Target Status Description
DER 15.1% <30% Diarization Error Rate (lower is better)
JER 24.9% <25% Jaccard Error Rate
RTFx 21.10x >1.0x Real-Time Factor (higher is faster)

Diarization Pipeline Timing Breakdown

Time spent in each stage of speaker diarization

Stage Time (s) % Description
Model Download 13.291 26.7 Fetching diarization models
Model Compile 5.696 11.5 CoreML compilation
Audio Load 0.054 0.1 Loading audio file
Segmentation 14.914 30.0 Detecting speech regions
Embedding 24.857 50.0 Extracting speaker voices
Clustering 9.943 20.0 Grouping same speakers
Total 49.732 100 Full pipeline

Speaker Diarization Research Comparison

Research baselines typically achieve 18-30% DER on standard datasets

Method DER Notes
FluidAudio 15.1% On-device CoreML
Research baseline 18-30% Standard dataset performance

Note: RTFx shown above is from GitHub Actions runner. On Apple Silicon with ANE:

  • M2 MacBook Air (2022): Runs at 150 RTFx real-time
  • Performance scales with Apple Neural Engine capabilities

🎯 Speaker Diarization Test • AMI Corpus ES2004a • 1049.0s meeting audio • 49.7s diarization time • Test runtime: 2m 57s • 09/14/2026, 12:04 PM EST

@Alex-Wengg
Alex-Wengg merged commit 69e42da into main Sep 14, 2026
13 checks passed
@Alex-Wengg
Alex-Wengg deleted the fix/922-deterministic-speaker-mapping branch September 14, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diarization scorer speaker mapping is nondeterministic (same class as #911: random dictionary key order + tie-broken assignment)

1 participant