docstr: Calculates the loss on each embedding $L(e_{ji})$ by contrast loss with closest centroid
docstr_tok: ["Calculates","the","loss","on","each","embedding","$","L","(","e_","{","ji","}",")","$","by","contrast","loss","with","closest","centroid"]
code: def embed_loss_contrast(self, dvecs, cos_sim_matrix):
      """
      Calculates the loss on each embedding $L(e_{ji})$ by contrast loss with closest centroid
      """
      N, M, _ = dvecs.shape
      L = []
      for j in range(N):
          L_row = []
          for i in range(M):
              centroids_sigmoids = torch.sigmoid(cos_sim_matrix[j, i])
              excl_centroids_sigmoids = torch.cat(
                  (centroids_sigmoids[:j], centroids_sigmoids[j + 1 :])
              )
              L_row.append(
                  1.0
                  - torch.sigmoid(cos_sim_matrix[j, i, j])
                  + torch.max(excl_centroids_sigmoids)
              )
          L_row = torch.stack(L_row)
          L.append(L_row)
      return torch.stack(L)
  
file_path: TTS/TTS/speaker_encoder/losses.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  import numpy
label_desc: Use image node_id 5 for calling the GE2ELoss obj's underlying member method code with example usage: obj.embed_loss_contrast(dvecs, cos_sim_matrix) and returns: torch