DiariZen

repository·main·Indexed 19 days ago

https://github.com/butspeechfit/diarizen

A speaker diarization toolkit driven by AudioZen and Pyannote 3.1 that utilizes Spatially Aware WavLM models to identify 'who spoke when' in audio recordings. It includes the DiariZenPipeline for inference, support for RTTM format output, and modules for End-to-End Neural Diarization (EEND). The toolkit also provides utilities for structured pruning of WavLM, model checkpoint averaging, and specialized learning rate schedulers like NoamOpt.

Tokens
34.4K
Snippets
101
Records
129
Agent score
67%

What's inside diarizen

  1. Overview of the DiariZen EEND Module

    main
    The DiariZen EEND (End-to-End Neural Diarization) module provides scripts for training and performing global inference for speaker diarization. It leverages self-supervised learning (SSL) features, specifically showing high performance when using updated WavLM features.
  2. Compatibility Note: Modified pyannote files in this repository

    main

    Note that this specific repository contains modifications to the original pyannote.audio code for compatibility purposes. If you intend to use the new/original Pyannote code, ensure you are aware of which files have been modified. The modified files in this repository are:

    • pyannote/audio/core/model.py
    • pyannote/audio/core/inference.py
    • pyannote/audio/pipelines/utils/getter.py
    • pyannote/audio/pipelines/utils/diarization.py
    • pyannote/audio/pipelines/speaker_diarization.py
  3. Streaming speaker diarization support

    main

    pyannote.audio does not support streaming speaker diarization out of the box.

    If you require streaming capabilities, the following alternatives are recommended:

    • diart: A project providing streaming speaker diarization based on pyannote.audio (GitHub).
    • Streaming VAD: For streaming Voice Activity Detection, refer to the official blog post on streaming VAD based on pyannote.audio.
  4. Improve diarization performance via fine-tuning

    main

    To improve the performance of diarization models for your specific use case, follow this workflow:

    1. Annotate: Manually annotate dozens of conversations with high precision.
    2. Split: Divide your annotated data into training (80%), development (10%), and test (10%) subsets.
    3. Format: Set up the data using pyannote.database.
    4. Adapt: Follow the recipe for adapting a pretrained pipeline found in tutorials/adapting_pretrained_pipeline.ipynb.
  5. Run hyperparameter sweeps on a Slurm cluster

    main

    To perform grid searches or launch multiple jobs on a Slurm cluster, use the hydra-submitit-launcher.

    1. Install the launcher:
    pip install hydra-submitit-launcher --upgrade
    1. Launch a multi-run job using the --multirun flag and specifying the submitit_slurm launcher. You can sweep over parameters by providing comma-separated values:
    pyannote-audio-train \
        --multirun hydra/launcher=submitit_slurm \
        model=PyanNet +model.lstm.num_layers=2,3,4 +model.lstm.bidirectional=true,false \
        task=VoiceActivityDetection \
        registry="AMI-diarization-setup/pyannote/database.yml" \
        protocol=AMI.SpeakerDiarization.only_words

    Warning: There are known compatibility issues between pytorch-lightning, hydra-submitit, and multi-GPU setups.

  6. Install DiariZen

    main

    To install DiariZen, follow these steps to set up a virtual environment, install PyTorch with CUDA 12.1 support, and install the required dependencies including pyannote-audio and dscore submodules.

    # create virtual python environment
    conda create --name diarizen python=3.10
    conda activate diarizen
    
    # install pytorch (CUDA 12.1 build)
    pip install torch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 \
        --index-url https://download.pytorch.org/whl/cu121
    
    # install diarizen 
    pip install -r requirements.txt && pip install -e .
    
    # install pyannote-audio
    cd pyannote-audio && pip install -e .[dev,testing] -c ../constraints.txt && cd ..
    
    # install dscore
    git submodule init
    git submodule update
  7. Run inference with DiariZenPipeline

    main

    Use the DiariZenPipeline class to perform speaker diarization on audio files. You can load pre-trained models from Hugging Face and iterate through the resulting speaker turns.

    from diarizen.pipelines.inference import DiariZenPipeline
    
    # load pre-trained model
    diar_pipeline = DiariZenPipeline.from_pretrained("BUT-FIT/diarizen-wavlm-large-s80-md")
    
    # apply diarization pipeline
    diar_results = diar_pipeline('./example/EN2002a_30s.wav')
    
    # print results
    for turn, _, speaker in diar_results.itertracks(yield_label=True):
        print(f"start={turn.start:.1f}s stop={turn.end:.1f}s speaker_{speaker}")
  8. Use gated models and pipelines offline

    main

    While pyannote.audio uses a gating process (requiring authentication via Hugging Face) to track usage, this does not prevent offline usage in production environments (e.g., inside a docker run command). Once the models or pipelines are authenticated and downloaded, they can be used without repeated authentication. Refer to the following tutorials for specific implementation patterns:

    • For models: tutorials/applying_a_model.ipynb
    • For pipelines: tutorials/applying_a_pipeline.ipynb
  9. Configure training parameters with Hydra

    main

    pyannote-audio-train is powered by Hydra. You can override any configuration parameter using dot notation in the command line.

    Inspect Configuration

    To see the actual configuration being used for a training job, add the --cfg job flag:

    pyannote-audio-train --cfg job model=PyanNet task=VoiceActivityDetection ...

    Override Parameters

    To change a parameter like task.duration, append it to your command:

    pyannote-audio-train \
        model=PyanNet \
        task=VoiceActivityDetection task.duration=2.0 \
        registry="AMI-diarization-setup/pyannote/database.yml" \
        protocol=AMI.SpeakerDiarization.only_words
    pyannote-audio-train --cfg job \
        model=PyanNet \
        task=VoiceActivityDetection \
        registry="AMI-diarization-setup/pyannote/database.yml" \
        protocol=AMI.SpeakerDiarization.only_words