class_docstr: SSLDisentangler is a Conformer based model for extracting disentangled content and speaker embeddings
  from an audio waveform. This model uses a pre-trained Conformer SSL model. To extract the linguistic content 
  and speaker representations using a pre-trained Conformer, two randomly initialized downstream 
  heads are added and the entire setup is finetuned in multi-task manner for speech recognition and speaker verification. 
  These representations can be used by FastPitchModel_SSL for voice conversion by swapping the speaker embedding 
  of a given source utterance, with the speaker embedding of a target speaker.
class_docstr_tok: ["SSLDisentangler","is","a","Conformer","based","model","for","extracting","disentangled","content","and","speaker","embeddings","from","an","audio","waveform",".","This","model","uses","a","pre-trained","Conformer","SSL","model",".","To","extract","the","linguistic","content","and","speaker","representations","using","a","pre-trained","Conformer",",","two","randomly","initialized","downstream","heads","are","added","and","the","entire","setup","is","finetuned","in","multi-task","manner","for","speech","recognition","and","speaker","verification",".","These","representations","can","be","used","by","FastPitchModel_SSL","for","voice","conversion","by","swapping","the","speaker","embedding","of","a","given","source","utterance",",","with","the","speaker","embedding","of","a","target","speaker","."]
code: def __init__(self, cfg: DictConfig, trainer: Trainer = None):
      super().__init__(cfg=cfg, trainer=trainer)
      self.preprocessor_disentangler = SSLDisentangler.from_config_dict(
          self._cfg.preprocessor
      )
      self.encoder = SSLDisentangler.from_config_dict(self._cfg.encoder)
      self._text_tokenizer = EnglishCharsTokenizer(add_blank_at="last")
      self._tb_logger = None
  
      self.downstream_nets = torch.nn.ModuleDict()
      for task in self._cfg.downstream_heads.task_names:
          if task == "speaker_verification":
              # setting up downstream heads and loss functions for speaker verification task
              in_dim = self._cfg.encoder.d_model
              out_dim = self._cfg.downstream_heads.speaker_embed_size
              num_speakers = self._cfg.downstream_heads.num_speakers
              self.downstream_nets[task] = torch.nn.Linear(
                  in_dim, out_dim
              )
              self.sv_linear = torch.nn.Linear(out_dim, num_speakers)
              self.sv_loss = AngularSoftmaxLoss(scale=30, margin=0.4)
  
          elif task == "content":
              # setting up downstream heads and loss functions for text/content recognition task
              in_dim = self._cfg.encoder.d_model
              out_dim = self._cfg.downstream_heads.content_embed_size
              num_chars = len(
                  self._text_tokenizer.tokens
              )  # list of english tokens
              self.downstream_nets[task] = torch.nn.Linear(
                  in_dim, out_dim
              )
              self.content_linear = torch.nn.Linear(out_dim, num_chars)
              self.ctc_loss = torch.nn.CTCLoss(
                  blank=self._text_tokenizer.blank, zero_infinity=True
              )
              self.pitch_augment = self._cfg.get("pitch_augment", False)
              self.augment_ctc = self._cfg.get("augment_ctc", False)
              self.aug_loss_type = self._cfg.get("aug_loss_type", "mse")
              self.stop_gradient = self._cfg.get("stop_gradient", False)
              assert (
                  self.stop_gradient and self.augment_ctc
              ) == False, "stop_gradient and augment_ctc cannot be true at the same time"
              self.mse_loss = torch.nn.MSELoss()
  
              self.ctc_decoder = GreedyCTCDecoder(
                  self._text_tokenizer.tokens,
                  self._text_tokenizer.blank,
              )
  
          else:
              raise ValueError(
                  f"{task} is not a valid task. Task must be speaker_verification or content."
              )
  
      self.automatic_optimization = False
  
      stft_cfg = self._cfg.preprocessor
      librosa_mel_filter = librosa.filters.mel(
          sr=stft_cfg.sample_rate,
          n_fft=stft_cfg.n_fft,
          n_mels=stft_cfg.features,
          fmin=0,
          fmax=8000,
      )
      fb = torch.tensor(
          librosa_mel_filter,
          dtype=torch.float,
      ).unsqueeze(0)
  
      self.register_buffer("fb", fb)
  
imports: import itertools
  from typing import Iterable, Optional
  import editdistance
  import librosa
  import torch
  from hydra.utils import instantiate
  from omegaconf import DictConfig, OmegaConf
  from pytorch_lightning import Trainer
  from pytorch_lightning.loggers import TensorBoardLogger
  from pytorch_lightning.utilities.combined_loader import CombinedLoader
  from nemo.collections.asr.losses.angularloss import AngularSoftmaxLoss
  from nemo.collections.tts.data.dataset import TTSDataset
  from nemo.collections.tts.modules.ssl_tts import GreedyCTCDecoder
  from nemo.collections.tts.torch.tts_tokenizers import BaseTokenizer, EnglishCharsTokenizer
  from nemo.core.classes import ModelPT
  from nemo.core.classes.common import PretrainedModelInfo
  from nemo.core.optim.lr_scheduler import WarmupPolicy
  from nemo.utils import logging
  from nemo.utils.decorators import experimental
label_desc: Use image node_id 1 to create a new SSLDisentangler object from inherited base classes: ModelPT with example: obj = SSLDisentangler(cfg, trainer)