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","."]
docstr: Core model that accepts multi-scale cosine similarity values and estimates per-speaker binary label.
  
  Args:
      ms_emb_seq (Tensor):
          Multiscale input embedding sequence
          Shape: (batch_size, length, scale_n, emb_dim)
      length (Tensor):
          The actual length of embedding sequences without zero padding
          Shape: (batch_size,)
      ms_avg_embs (Tensor):
          Cluster-average speaker embedding vectors.
          Shape: (batch_size, scale_n, self.emb_dim, max_spks)
      targets (Tensor):
          Ground-truth labels for the finest segment.
          Shape: (batch_size, feats_len, max_spks)
  
  Returns:
      preds (Tensor):
          Predicted binary speaker label for each speaker.
          Shape: (batch_size, feats_len, max_spks)
      scale_weights (Tensor):
          Multiscale weights per each base-scale segment.
          Shape: (batch_size, length, scale_n, max_spks)
docstr_tok: ["Core","model","that","accepts","multi-scale","cosine","similarity","values","and","estimates","per-speaker","binary","label",".","Args",":","ms_emb_seq","(","Tensor",")",":","Multiscale","input","embedding","sequence","Shape",":","(","batch_size",",","length",",","scale_n",",","emb_dim",")","length","(","Tensor",")",":","The","actual","length","of","embedding","sequences","without","zero","padding","Shape",":","(","batch_size",",",")","ms_avg_embs","(","Tensor",")",":","Cluster-average","speaker","embedding","vectors",".","Shape",":","(","batch_size",",","scale_n",",","self.emb_dim",",","max_spks",")","targets","(","Tensor",")",":","Ground-truth","labels","for","the","finest","segment",".","Shape",":","(","batch_size",",","feats_len",",","max_spks",")","Returns",":","preds","(","Tensor",")",":","Predicted","binary","speaker","label","for","each","speaker",".","Shape",":","(","batch_size",",","feats_len",",","max_spks",")","scale_weights","(","Tensor",")",":","Multiscale","weights","per","each","base-scale","segment",".","Shape",":","(","batch_size",",","length",",","scale_n",",","max_spks",")"]
code: def core_model(self, ms_emb_seq, length, ms_avg_embs, targets):
      """
      Core model that accepts multi-scale cosine similarity values and estimates per-speaker binary label.
  
      Args:
          ms_emb_seq (Tensor):
              Multiscale input embedding sequence
              Shape: (batch_size, length, scale_n, emb_dim)
          length (Tensor):
              The actual length of embedding sequences without zero padding
              Shape: (batch_size,)
          ms_avg_embs (Tensor):
              Cluster-average speaker embedding vectors.
              Shape: (batch_size, scale_n, self.emb_dim, max_spks)
          targets (Tensor):
              Ground-truth labels for the finest segment.
              Shape: (batch_size, feats_len, max_spks)
  
      Returns:
          preds (Tensor):
              Predicted binary speaker label for each speaker.
              Shape: (batch_size, feats_len, max_spks)
          scale_weights (Tensor):
              Multiscale weights per each base-scale segment.
              Shape: (batch_size, length, scale_n, max_spks)
  
      """
      self.batch_size = ms_emb_seq.shape[0]
      self.length = ms_emb_seq.shape[1]
      self.emb_dim = ms_emb_seq.shape[-1]
  
      _ms_emb_seq = ms_emb_seq.unsqueeze(4).expand(
          -1, -1, -1, -1, self.num_spks
      )
      ms_emb_seq_single = ms_emb_seq
      ms_avg_embs = ms_avg_embs.unsqueeze(1).expand(
          -1, self.length, -1, -1, -1
      )
  
      ms_avg_embs_perm = ms_avg_embs.permute(0, 1, 2, 4, 3).reshape(
          self.batch_size, self.length, -1, self.emb_dim
      )
  
      if self.weighting_scheme == "conv_scale_weight":
          scale_weights = self.conv_scale_weights(
              ms_avg_embs_perm, ms_emb_seq_single
          )
      elif self.weighting_scheme == "attn_scale_weight":
          scale_weights = self.attention_scale_weights(
              ms_avg_embs_perm, ms_emb_seq_single
          )
      else:
          raise ValueError(
              f"No such weighting scheme as {self.weighting_scheme}"
          )
      scale_weights = scale_weights.to(ms_emb_seq.device)
  
      if self.context_vector_type == "cos_sim":
          context_emb = self.cosine_similarity(
              scale_weights, ms_avg_embs, _ms_emb_seq
          )
      elif self.context_vector_type == "elem_prod":
          context_emb = self.element_wise_product(
              scale_weights, ms_avg_embs, _ms_emb_seq
          )
      else:
          raise ValueError(
              f"No such context vector type as {self.context_vector_type}"
          )
  
      context_emb = self.dropout(F.relu(context_emb))
      lstm_output = self.lstm(context_emb)
      lstm_hidden_out = self.dropout(F.relu(lstm_output[0]))
      spk_preds = self.hidden_to_spks(lstm_hidden_out)
      preds = nn.Sigmoid()(spk_preds)
      return preds, scale_weights
  
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 5 for calling the MSDD_module obj's underlying member method code with example usage: obj.core_model(ms_emb_seq, length, ms_avg_embs, targets) and returns: preds,  scale_weights