docstr: Make the cosine similarity matrix with dims (N,M,N)
docstr_tok: ["Make","the","cosine","similarity","matrix","with","dims","(","N",",","M",",","N",")"]
code: def calc_cosine_sim(self, dvecs, centroids):
      """
      Make the cosine similarity matrix with dims (N,M,N)
      """
      cos_sim_matrix = []
      for spkr_idx, speaker in enumerate(dvecs):
          cs_row = []
          for utt_idx, utterance in enumerate(speaker):
              new_centroids = self.calc_new_centroids(
                  dvecs, centroids, spkr_idx, utt_idx
              )
              # vector based cosine similarity for speed
              cs_row.append(
                  torch.clamp(
                      torch.mm(
                          utterance.unsqueeze(1).transpose(0, 1),
                          new_centroids.transpose(0, 1),
                      )
                      / (
                          torch.norm(utterance)
                          * torch.norm(new_centroids, dim=1)
                      ),
                      1e-6,
                  )
              )
          cs_row = torch.cat(cs_row, dim=0)
          cos_sim_matrix.append(cs_row)
      return torch.stack(cos_sim_matrix)
  
imports: import torch
  import torch.nn.functional
  from torch import nn
label_desc: Use image node_id 3 for calling the GE2ELoss obj's underlying member method code with example usage: obj.calc_cosine_sim(dvecs, centroids) and returns: torch