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: Use weighted inner product for calculating each scale weight. W_a matrix has (emb_dim * emb_dim) learnable parameters
  and W_a matrix is initialized with an identity matrix. Compared to "conv_scale_weight" method, this method shows more evenly
  distributed scale weights.
  
  Args:
      ms_avg_embs_perm (Tensor):
          Tensor containing cluster-average speaker embeddings for each scale.
          Shape: (batch_size, length, scale_n, emb_dim)
      ms_emb_seq (Tensor):
          Tensor containing multi-scale speaker embedding sequences. `ms_emb_seq` is input from the
          given audio stream input.
          Shape: (batch_size, length, num_spks, emb_dim)
  
  Returns:
      scale_weights (Tensor):
          Weight vectors that determine the weight of each scale.
          Shape: (batch_size, length, num_spks, emb_dim)
docstr_tok: ["Use","weighted","inner","product","for","calculating","each","scale","weight",".","W_a","matrix","has","(","emb_dim","*","emb_dim",")","learnable","parameters","and","W_a","matrix","is","initialized","with","an","identity","matrix",".","Compared","to","``","conv_scale_weight","''","method",",","this","method","shows","more","evenly","distributed","scale","weights",".","Args",":","ms_avg_embs_perm","(","Tensor",")",":","Tensor","containing","cluster-average","speaker","embeddings","for","each","scale",".","Shape",":","(","batch_size",",","length",",","scale_n",",","emb_dim",")","ms_emb_seq","(","Tensor",")",":","Tensor","containing","multi-scale","speaker","embedding","sequences",".","`","ms_emb_seq","`","is","input","from","the","given","audio","stream","input",".","Shape",":","(","batch_size",",","length",",","num_spks",",","emb_dim",")","Returns",":","scale_weights","(","Tensor",")",":","Weight","vectors","that","determine","the","weight","of","each","scale",".","Shape",":","(","batch_size",",","length",",","num_spks",",","emb_dim",")"]
code: def attention_scale_weights(self, ms_avg_embs_perm, ms_emb_seq):
      """
      Use weighted inner product for calculating each scale weight. W_a matrix has (emb_dim * emb_dim) learnable parameters
      and W_a matrix is initialized with an identity matrix. Compared to "conv_scale_weight" method, this method shows more evenly
      distributed scale weights.
  
      Args:
          ms_avg_embs_perm (Tensor):
              Tensor containing cluster-average speaker embeddings for each scale.
              Shape: (batch_size, length, scale_n, emb_dim)
          ms_emb_seq (Tensor):
              Tensor containing multi-scale speaker embedding sequences. `ms_emb_seq` is input from the
              given audio stream input.
              Shape: (batch_size, length, num_spks, emb_dim)
  
      Returns:
          scale_weights (Tensor):
              Weight vectors that determine the weight of each scale.
              Shape: (batch_size, length, num_spks, emb_dim)
      """
      self.W_a(ms_emb_seq.flatten(0, 1))
      mat_a = self.W_a(ms_emb_seq.flatten(0, 1))
      mat_b = ms_avg_embs_perm.flatten(0, 1).permute(0, 2, 1)
  
      weighted_corr = torch.matmul(mat_a, mat_b).reshape(
          -1, self.scale_n, self.scale_n, self.num_spks
      )
      scale_weights = torch.sigmoid(
          torch.diagonal(weighted_corr, dim1=1, dim2=2)
      )
      scale_weights = scale_weights.reshape(
          self.batch_size, self.length, self.scale_n, self.num_spks
      )
      scale_weights = self.softmax(scale_weights)
      return 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 8 for calling the MSDD_module obj's underlying member method code with example usage: obj.attention_scale_weights(ms_avg_embs_perm, ms_emb_seq) and returns: scale_weights