Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file class based inference API for diarization #5945

Merged
merged 5 commits into from
Feb 28, 2023
Merged

Conversation

SeanNaren
Copy link
Collaborator

@SeanNaren SeanNaren commented Feb 7, 2023

What does this PR do?

Supports:

from nemo.collections.asr.models import NeuralDiarizer

diarizer = NeuralDiarizer.from_pretrained(model_name='diar_msdd_telephonic')

annotation = diarizer("an4_diarize_test.wav")

print(annotation.to_rttm())

User can change the device:

import torch
from nemo.collections.asr.models import NeuralDiarizer

diarizer = NeuralDiarizer.from_pretrained(model_name='diar_msdd_telephonic')
diarizer.to(torch.device('cuda'))

Supports passing the maximum number of speakers, or the actual number of speakers in a file (oracle):

annotation = diarizer("an4_diarize_test.wav", num_speakers=2)

annotation = diarizer("an4_diarize_test.wav", max_speakers=4)

Relies on a temporary directory, which can be specified if preferred:

annotation = diarizer("an4_diarize_test.wav", out_dir="my_temp/")

List of available models:

from nemo.collections.asr.models.msdd_models import NeuralDiarizer

print(NeuralDiarizer.list_available_models())
"""
PretrainedModelInfo(
	pretrained_model_name=diar_msdd_telephonic,
	description=For details about this model, please visit https://ngc.nvidia.com/catalog/models/nvidia:nemo:diar_msdd_telephonic,
location=https://api.ngc.nvidia.com/v2/models/nvidia/nemo/diar_msdd_telephonic/versions/1.0.0/files/diar_msdd_telephonic.nemo
)
"""

TODO

  • Add tests, ensure that config options are passed correctly and updated correctly. The config logic is quite messy due to mutable objects, but this should be saved for a larger refactor.
  • Hopefully in the future, NeuralDiarizer will be a NeMo PT model file too, save for a later refactor

Collection: ASR, Speaker Tasks

Changelog

  • Add file class based inference API for Diarization.

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

@SeanNaren SeanNaren requested review from tango4j, nithinraok and fayejf and removed request for tango4j and nithinraok February 7, 2023 15:15
@github-actions github-actions bot added the ASR label Feb 7, 2023
nemo/collections/asr/models/msdd_models.py Outdated Show resolved Hide resolved
nemo/collections/asr/models/msdd_models.py Outdated Show resolved Hide resolved
nemo/collections/asr/models/msdd_models.py Outdated Show resolved Hide resolved
nemo/collections/asr/models/msdd_models.py Show resolved Hide resolved
nemo/collections/asr/models/msdd_models.py Outdated Show resolved Hide resolved
nemo/collections/asr/models/msdd_models.py Outdated Show resolved Hide resolved
nemo/collections/asr/models/clustering_diarizer.py Outdated Show resolved Hide resolved
nemo/collections/asr/models/configs/msdd_config.py Outdated Show resolved Hide resolved
nemo/collections/asr/models/msdd_models.py Show resolved Hide resolved
nemo/collections/asr/models/msdd_models.py Outdated Show resolved Hide resolved
nemo/collections/asr/models/msdd_models.py Outdated Show resolved Hide resolved
nemo/collections/asr/models/msdd_models.py Outdated Show resolved Hide resolved
@tango4j
Copy link
Collaborator

tango4j commented Feb 7, 2023

I resolved the conflict in speaker_utils.py and tested with the script you provided.

@SeanNaren I think it is required to add a simple CI-test for this too? I guess it won't be that difficult.

@SeanNaren
Copy link
Collaborator Author

Thanks guys. I have made modifications as per requested to the code.

I think it is required to add a simple CI-test for this too? I guess it won't be that difficult.

Yep, once we're happy with the API and stuff, can start to add tests for functionality.

The current code seems to be a one run setup; the code isn't setup for diarize to be called multiple times. It instantiates all the models again in the pipeline.

I'll be modifying this behaviour.

@SeanNaren
Copy link
Collaborator Author

High level updates:

  • Tried to reduce logging verbosity as much as I can. This is controlled by the verbose flag. This will reduce info logging to a minimum. Much more readable, however I'd like to reduce the amount of spam even further
  • NeuralDiarizer is now based on a LightningModule allowing us to easily swap between devices
  • It supports multiple files now. Not the cleanest as we're updating a config data-class to do so, but works for now

@SeanNaren SeanNaren marked this pull request as ready for review February 8, 2023 17:08
@tango4j
Copy link
Collaborator

tango4j commented Feb 8, 2023

I have sent you the branch feat/inference_diar_add with the necessary changes to make sure these things:

  • we only use MSDD for telephonic and the rest is clustering diarizer
  • download yaml file from raw.githubusercontent.com for automate the yaml file
    update for API.

https://github.com/NVIDIA/NeMo/blob/feat/inference_diar_add/nemo/collections/asr/models/configs/msdd_config.py
https://github.com/NVIDIA/NeMo/blob/feat/inference_diar_add/nemo/collections/asr/models/msdd_models.py

Few points that I strongly insist to change:

  • MSDD is currently writing to pred_ovl_rttm folder. We should change it to pred_rttm to unify the output folder Line in msdd_models.py
  • Config file should be automatically downloaded from NeMo repo. I implemented all to get it work.
  • I temporarily changed __call__ function to diarize_audio and this could probably changed to use __call__ but I should probably spend more time on this. Also there are some ugly config assignment to get clustering diarizer work in current format.

Please ping me if you need to clarify something.

@SeanNaren
Copy link
Collaborator Author

SeanNaren commented Feb 14, 2023

After offline discussion the high level changes are as below:

  • Move telephonic configuration to the data-class. This will be our new “default” for the neural diarizer (especially considering the pre-trained model is labelled telephonic). Remove the telephonic yaml file
  • The general and meeting yaml files will inherit parameters from the data-class config, just like ASR does. We remove all the parameters that are not changed as they will be inherited from the data-class when loaded

When changes to the defaults are made, they are made in the data-class config file (the python data-class). When changes regarding meeting or general are made, they are made in the yaml files. This means parameters are not duplicated, but there is two different places to update (which I think is fine as maintainers, as the config file is mainly to try different configurations out).

One note to make, is that our neural diarizer model is telephonic. If we release further adapted models to different domains (which is not certain yet) we will need to come up with a mechanism via the API to enable this.

@tango4j
Copy link
Collaborator

tango4j commented Feb 14, 2023

After offline discussion the high level changes are as below:

  • Move telephonic configuration to the data-class. This will be our new “default” for the neural diarizer (especially considering the pre-trained model is labelled telephonic). Remove the telephonic yaml file
  • The general and meeting yaml files will inherit parameters from the data-class config, just like ASR does. We remove all the parameters that are not changed as they will be inherited from the data-class when loaded

When changes to the defaults are made, they are made in the data-class config file (the python data-class). When changes regarding meeting or general are made, they are made in the yaml files. This means parameters are not duplicated, but there is two different places to update (which I think is fine as maintainers, as the config file is mainly to try different configurations out).

One note to make, is that our neural diarizer model is telephonic. If we release further adapted models to different domains (which is not certain yet) we will need to come up with a mechanism via the API to enable this.

I recognize that making data class is necessary but editing diarization yaml file this way is too confusing. Even I am having a hard time grasping what is happening with the configuration. Also, setting telephonic as a default configuration for the whole diarization pipeline is also confusing.

Can we just duplicate the configuration (for now, it is telephonic) and just revert all yaml files? This is too much of change on the original diarization pipeline, which is only focusing on API purpose.

@SeanNaren
Copy link
Collaborator Author

Thanks @tango4j I have updated the PR based on your suggestions.

Would we be able to review and merge this now?

Copy link
Collaborator

@tango4j tango4j left a comment

Choose a reason for hiding this comment

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

Couple of points to be addressed.
Also it would be great if we can remove the scale-specific tqdm in clustering diarizer.
It is overkill to show it.

nemo/collections/asr/models/msdd_models.py Show resolved Hide resolved
nemo/collections/asr/models/clustering_diarizer.py Outdated Show resolved Hide resolved
@SeanNaren
Copy link
Collaborator Author

Thanks @tango4j everything addressed.

I've reduced the TQDM logging by introducing verbosity to those functions. Everything left is just general NeMo logging, which also needs to definitely be reduced (but in a different PR I believe).

tango4j
tango4j previously approved these changes Feb 17, 2023
Copy link
Collaborator

@tango4j tango4j left a comment

Choose a reason for hiding this comment

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

I will do PRs when I need to update the configs later.
Thank you for your effort on building this.

nemo/collections/asr/models/clustering_diarizer.py Outdated Show resolved Hide resolved
nemo/collections/asr/models/clustering_diarizer.py Outdated Show resolved Hide resolved
`NeuralDiarizer`
"""
cfg = NeuralDiarizerInferenceConfig.init_config(
diar_model_path=model_name, vad_model_path=vad_model_name, map_location=map_location, verbose=verbose,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very cool

Signed-off-by: SeanNaren <[email protected]>
Copy link
Collaborator

@nithinraok nithinraok left a comment

Choose a reason for hiding this comment

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

Great work Sean.

@SeanNaren SeanNaren merged commit 1f686da into main Feb 28, 2023
@SeanNaren SeanNaren deleted the feat/inference_diar branch February 28, 2023 18:29
titu1994 pushed a commit to titu1994/NeMo that referenced this pull request Mar 24, 2023
hsiehjackson pushed a commit to hsiehjackson/NeMo that referenced this pull request Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants