Skip to content

Adding flexible input sources for Diarization Mixin - #15184

Merged
tango4j merged 8 commits into
NVIDIA-NeMo:mainfrom
tango4j:sortformer_infer_fix
Dec 16, 2025
Merged

tango4j merged 8 commits into
NVIDIA-NeMo:mainfrom
tango4j:sortformer_infer_fix

Conversation

@tango4j

@tango4j tango4j commented Dec 13, 2025 •

Copy link
Copy Markdown
Collaborator

What does this PR do ?

Reflecting the change requested by:

Issues #14495
Issues #14977

  • Force end-to-end diarization to use the first channel audio if it is multichannel audio.
  • Adding numpy input format to end-to-end speaker diarization (Sortformer models)
  • Added offset/duration masking feature to .diarize() (SpkDiarizationMixin) function
  • Added max-speaker limitation to multi-speaker inference pipeline
  • Revamped the diarization mixin unit-tests.

Collection: [Note which collection this PR will affect]

Changelog

The following files are changed.

nemo/collections/asr/data/audio_to_diar_label_lhotse.py                                                                                                                                                                                                                             
nemo/collections/asr/models/sortformer_diar_models.py                                                                                                                                                                                                                               
nemo/collections/asr/parts/mixins/diarization.py                                                                                                                                                                                                                                    
nemo/collections/asr/parts/utils/multispk_transcribe_utils.py                                                                                                                                                                                                                       
tests/collections/speaker_tasks/mixins/test_diarization.py

Usage

  • You can potentially add a usage example below
from nemo.collections.asr.models import SortformerEncLabelModel

# load model from Hugging Face model card directly (You need a Hugging Face token)
diar_model = SortformerEncLabelModel.from_pretrained("nvidia/diar_streaming_sortformer_4spk-v2")

# If you have a downloaded model in "/path/to/diar_streaming_sortformer_4spk-v2.nemo", load model from a downloaded file
diar_model = SortformerEncLabelModel.restore_from(restore_path="/path/to/diar_streaming_sortformer_4spk-v2.nemo", map_location='cuda', strict=False)

# switch to inference mode
diar_model.eval()

predicted_segments = diar_model.diarize(audio=audio_input, batch_size=1)

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

If you haven't finished some of the above items you can still open "Draft" PR.

Who can review?

Anyone in NeMo ASR

Additional Information

Related issues:
Issues #14495 - A request for numpy input for .diarize() function.
Issues #14977 - Duration is not picked up when manifest is used for .diarize() function.

Signed-off-by: taejinp <tango4j@gmail.com>
KunalDhawan
KunalDhawan previously approved these changes Dec 16, 2025

@KunalDhawan KunalDhawan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, great work @tango4j!

self.num_mel_frame_per_target_frame = int(self.cfg.get('subsampling_factor', 8))

def __getitem__(self, cuts) -> Tuple[torch.Tensor, ...]:
# NOTE: This end-to-end diarization dataloader only loads the 1st ch of the audio file.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add log this somewhere so that users don't run into unexpected issues?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the warning message and made these into one for loop.

Signed-off-by: tango4j <tango4j@users.noreply.github.com>
Signed-off-by: taejinp <tango4j@gmail.com>
@tango4j
tango4j merged commit 61aa919 into NVIDIA-NeMo:main Dec 16, 2025
"""
return super().diarize(
audio=audio,
batch_size=batch_size,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need sample_rate here too?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes because if numpy input is assigned to audio, we do not know what sample rate audio time series signal is based on. This is mentioned in the Huggingface README. default is 16000 always.

@ooobo ooobo Dec 23, 2025 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I wasn't quite clear, I'm wondering if we need to return sample_rate here too.
Running the example as per the readme fails when I try it, as sample_rate is not passed through:

from nemo.collections.asr.models import SortformerEncLabelModel
diar_model = SortformerEncLabelModel.from_pretrained("nvidia/diar_streaming_sortformer_4spk-v2")
diar_model.eval()

import numpy as np
# Create dummy audio: 10 seconds of white noise at 16kHz
audio_input = np.random.randn(16000 * 10).astype(np.float32)

diar_model.diarize(audio=audio_input, batch_size=1, sample_rate=16000)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct and I made a mistake.
sample_rate variable is missing in super().diarize() function.
I checked and I missed this part.
I will make a PR that fixes that.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diarize() function in this file
NeMo/nemo/collections/asr/parts/mixins/diarization.py
has "sample_rate" so this fix will do the job.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ooobo
Thank you so much for pointing this out.
I prepared a PR for this: #15228

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, all set now
Appreciate all your hard work!

AkCodes23 pushed a commit to AkCodes23/NeMo that referenced this pull request Jan 28, 2026
* Adding flexible input source for Diarization Mixin

Signed-off-by: taejinp <tango4j@gmail.com>

* Apply isort and black reformatting

Signed-off-by: tango4j <tango4j@users.noreply.github.com>

---------

Signed-off-by: taejinp <tango4j@gmail.com>
Signed-off-by: tango4j <tango4j@users.noreply.github.com>
Co-authored-by: tango4j <tango4j@users.noreply.github.com>
Signed-off-by: Akhil Varanasi <akhilvaranasi23@gmail.com>
nune-tadevosyan pushed a commit to nune-tadevosyan/NeMo that referenced this pull request Mar 13, 2026
* Adding flexible input source for Diarization Mixin

Signed-off-by: taejinp <tango4j@gmail.com>

* Apply isort and black reformatting

Signed-off-by: tango4j <tango4j@users.noreply.github.com>

---------

Signed-off-by: taejinp <tango4j@gmail.com>
Signed-off-by: tango4j <tango4j@users.noreply.github.com>
Co-authored-by: tango4j <tango4j@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
test — e129e4e9 Deployed Dec 16, 2025 by tango4j
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants