class_docstr: Multi-scale Diarization Decoder (MSDD) for overlap-aware diarization and improved diarization accuracy from clustering diarizer.
  Based on the paper: Taejin Park et. al, "Multi-scale Speaker Diarization with Dynamic Scale Weighting", Interspeech 2022.
  Arxiv version: https://arxiv.org/pdf/2203.15974.pdf
  
  Args:
      num_spks (int):
          Max number of speakers that are processed by the model. In `MSDD_module`, `num_spks=2` for pairwise inference.
      hidden_size (int):
          Number of hidden units in sequence models and intermediate layers.
      num_lstm_layers (int):
          Number of the stacked LSTM layers.
      dropout_rate (float):
          Dropout rate for linear layers, CNN and LSTM.
      cnn_output_ch (int):
          Number of channels per each CNN layer.
      emb_dim (int):
          Dimension of the embedding vectors.
      scale_n (int):
          Number of scales in multi-scale system.
      clamp_max (float):
          Maximum value for limiting the scale weight values.
      conv_repeat (int):
          Number of CNN layers after the first CNN layer.
      weighting_scheme (str):
          Name of the methods for estimating the scale weights.
      context_vector_type (str):
          If 'cos_sim', cosine similarity values are used for the input of the sequence models.
          If 'elem_prod', element-wise product values are used for the input of the sequence models.
class_docstr_tok: ["Multi-scale","Diarization","Decoder","(","MSDD",")","for","overlap-aware","diarization","and","improved","diarization","accuracy","from","clustering","diarizer",".","Based","on","the","paper",":","Taejin","Park","et",".","al",",","``","Multi-scale","Speaker","Diarization","with","Dynamic","Scale","Weighting","''",",","Interspeech","2022",".","Arxiv","version",":","https",":","\/\/arxiv.org\/pdf\/2203.15974.pdf","Args",":","num_spks","(","int",")",":","Max","number","of","speakers","that","are","processed","by","the","model",".","In","`","MSDD_module","`",",","`","num_spks=2","`","for","pairwise","inference",".","hidden_size","(","int",")",":","Number","of","hidden","units","in","sequence","models","and","intermediate","layers",".","num_lstm_layers","(","int",")",":","Number","of","the","stacked","LSTM","layers",".","dropout_rate","(","float",")",":","Dropout","rate","for","linear","layers",",","CNN","and","LSTM",".","cnn_output_ch","(","int",")",":","Number","of","channels","per","each","CNN","layer",".","emb_dim","(","int",")",":","Dimension","of","the","embedding","vectors",".","scale_n","(","int",")",":","Number","of","scales","in","multi-scale","system",".","clamp_max","(","float",")",":","Maximum","value","for","limiting","the","scale","weight","values",".","conv_repeat","(","int",")",":","Number","of","CNN","layers","after","the","first","CNN","layer",".","weighting_scheme","(","str",")",":","Name","of","the","methods","for","estimating","the","scale","weights",".","context_vector_type","(","str",")",":","If","'cos_sim","'",",","cosine","similarity","values","are","used","for","the","input","of","the","sequence","models",".","If","'elem_prod","'",",","element-wise","product","values","are","used","for","the","input","of","the","sequence","models","."]
code: def __init__(
      self,
      num_spks: int = 2,
      hidden_size: int = 256,
      num_lstm_layers: int = 2,
      dropout_rate: float = 0.5,
      cnn_output_ch: int = 16,
      emb_dim: int = 192,
      scale_n: int = 5,
      clamp_max: float = 1.0,
      conv_repeat: int = 1,
      weighting_scheme: str = "conv_scale_weight",
      context_vector_type: str = "cos_sim",
  ):
      super().__init__()
      self._speaker_model = None
      self.batch_size: int = 1
      self.length: int = 50
      self.emb_dim: int = emb_dim
      self.num_spks: int = num_spks
      self.scale_n: int = scale_n
      self.cnn_output_ch: int = cnn_output_ch
      self.conv_repeat: int = conv_repeat
      self.chan: int = 2
      self.eps: float = 1e-6
      self.num_lstm_layers: int = num_lstm_layers
      self.weighting_scheme: str = weighting_scheme
      self.context_vector_type: bool = context_vector_type
  
      self.softmax = torch.nn.Softmax(dim=2)
      self.cos_dist = torch.nn.CosineSimilarity(dim=3, eps=self.eps)
      self.lstm = nn.LSTM(
          hidden_size,
          hidden_size,
          num_layers=self.num_lstm_layers,
          batch_first=True,
          bidirectional=True,
          dropout=dropout_rate,
      )
  
      if self.weighting_scheme == "conv_scale_weight":
          self.conv = nn.ModuleList(
              [
                  ConvLayer(
                      in_channels=1,
                      out_channels=cnn_output_ch,
                      kernel_size=(
                          self.scale_n + self.scale_n * num_spks,
                          1,
                      ),
                      stride=(1, 1),
                  )
              ]
          )
          for conv_idx in range(1, conv_repeat + 1):
              self.conv.append(
                  ConvLayer(
                      in_channels=1,
                      out_channels=cnn_output_ch,
                      kernel_size=(self.cnn_output_ch, 1),
                      stride=(1, 1),
                  )
              )
          self.conv_bn = nn.ModuleList()
          for conv_idx in range(self.conv_repeat + 1):
              self.conv_bn.append(
                  nn.BatchNorm2d(self.emb_dim, affine=False)
              )
          self.conv_to_linear = nn.Linear(
              emb_dim * cnn_output_ch, hidden_size
          )
          self.linear_to_weights = nn.Linear(hidden_size, self.scale_n)
  
      elif self.weighting_scheme == "attn_scale_weight":
          self.W_a = nn.Linear(emb_dim, emb_dim, bias=False)
          nn.init.eye_(self.W_a.weight)
      else:
          raise ValueError(
              f"No such weighting scheme as {self.weighting_scheme}"
          )
  
      self.hidden_to_spks = nn.Linear(2 * hidden_size, self.num_spks)
      if self.context_vector_type == "cos_sim":
          self.dist_to_emb = nn.Linear(
              self.scale_n * self.num_spks, hidden_size
          )
          self.dist_to_emb.apply(self.init_weights)
      elif self.context_vector_type == "elem_prod":
          self.product_to_emb = nn.Linear(
              self.emb_dim * self.num_spks, hidden_size
          )
      else:
          raise ValueError(
              f"No such context vector type as {self.context_vector_type}"
          )
  
      self.dropout = nn.Dropout(dropout_rate)
      self.hidden_to_spks.apply(self.init_weights)
      self.lstm.apply(self.init_weights)
      self.clamp_max = clamp_max
  
imports: from collections import OrderedDict
  import torch
  import torch.nn
  import torch.nn.functional
  from nemo.core.classes.common import typecheck
  from nemo.core.classes.exportable import Exportable
  from nemo.core.classes.module import NeuralModule
  from nemo.core.neural_types import EncodedRepresentation, LengthsType, NeuralType, SpectrogramType
  from nemo.core.neural_types.elements import ProbsType
label_desc: Use image node_id 4 to create a new MSDD_module object from inherited base classes: NeuralModule, Exportable with example: obj = MSDD_module(num_spks, hidden_size, num_lstm_layers, dropout_rate, cnn_output_ch, emb_dim, scale_n, clamp_max, conv_repeat, weighting_scheme, context_vector_type)