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: Calculate cosine similarity values among cluster-average embedding vectors and input embedding vector sequences.
  This function is selected by assigning self.context_vector_type = "cos_sim".
  
  Args:
      scale_weights (Tensor):
          Multiscale weight vector.
          Shape: (batch_size, feats_len, scale_n, max_spks)
      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 a single channel input from the
          given audio stream input.
          Shape: (batch_size, length, num_spks, emb_dim)
  
  Returns:
      context_emb (Tensor):
          Output of `dist_to_emb` linear layer containing context for speaker label estimation.
docstr_tok: ["Calculate","cosine","similarity","values","among","cluster-average","embedding","vectors","and","input","embedding","vector","sequences",".","This","function","is","selected","by","assigning","self.context_vector_type","=","``","cos_sim","''",".","Args",":","scale_weights","(","Tensor",")",":","Multiscale","weight","vector",".","Shape",":","(","batch_size",",","feats_len",",","scale_n",",","max_spks",")","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","a","single","channel","input","from","the","given","audio","stream","input",".","Shape",":","(","batch_size",",","length",",","num_spks",",","emb_dim",")","Returns",":","context_emb","(","Tensor",")",":","Output","of","`","dist_to_emb","`","linear","layer","containing","context","for","speaker","label","estimation","."]
code: def cosine_similarity(self, scale_weights, ms_avg_embs, _ms_emb_seq):
      """
      Calculate cosine similarity values among cluster-average embedding vectors and input embedding vector sequences.
      This function is selected by assigning self.context_vector_type = "cos_sim".
  
      Args:
          scale_weights (Tensor):
              Multiscale weight vector.
              Shape: (batch_size, feats_len, scale_n, max_spks)
          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 a single channel input from the
              given audio stream input.
              Shape: (batch_size, length, num_spks, emb_dim)
  
      Returns:
          context_emb (Tensor):
              Output of `dist_to_emb` linear layer containing context for speaker label estimation.
      """
      cos_dist_seq = self.cos_dist(_ms_emb_seq, ms_avg_embs)
      context_vectors = torch.mul(scale_weights, cos_dist_seq)
      context_vectors = context_vectors.view(
          self.batch_size, self.length, -1
      )
      context_emb = self.dist_to_emb(context_vectors)
      return context_emb
  
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 7 for calling the MSDD_module obj's underlying member method code with example usage: obj.cosine_similarity(scale_weights, ms_avg_embs, _ms_emb_seq) and returns: context_emb