class_docstr: Implementation of the Angular Prototypical loss defined in https://arxiv.org/abs/2003.11982
      Accepts an input of size (N, M, D)
          where N is the number of speakers in the batch,
          M is the number of utterances per speaker,
          and D is the dimensionality of the embedding vector
      Args:
          - init_w (float): defines the initial value of w
          - init_b (float): definies the initial value of b
class_docstr_tok: ["Implementation","of","the","Angular","Prototypical","loss","defined","in","https",":","\/\/arxiv.org\/abs\/2003.11982","Accepts","an","input","of","size","(","N",",","M",",","D",")","where","N","is","the","number","of","speakers","in","the","batch",",","M","is","the","number","of","utterances","per","speaker",",","and","D","is","the","dimensionality","of","the","embedding","vector","Args",":","-","init_w","(","float",")",":","defines","the","initial","value","of","w","-","init_b","(","float",")",":","definies","the","initial","value","of","b"]
docstr: Calculates the AngleProto loss for an input of dimensions (num_speakers, num_utts_per_speaker, dvec_feats)
docstr_tok: ["Calculates","the","AngleProto","loss","for","an","input","of","dimensions","(","num_speakers",",","num_utts_per_speaker",",","dvec_feats",")"]
code: def forward(self, x, _label=None):
      """
      Calculates the AngleProto loss for an input of dimensions (num_speakers, num_utts_per_speaker, dvec_feats)
      """
  
      assert x.size()[1] >= 2
  
      out_anchor = torch.mean(x[:, 1:, :], 1)
      out_positive = x[:, 0, :]
      num_speakers = out_anchor.size()[0]
  
      cos_sim_matrix = F.cosine_similarity(
          out_positive.unsqueeze(-1).expand(-1, -1, num_speakers),
          out_anchor.unsqueeze(-1)
          .expand(-1, -1, num_speakers)
          .transpose(0, 2),
      )
      torch.clamp(self.w, 1e-6)
      cos_sim_matrix = cos_sim_matrix * self.w + self.b
      label = torch.arange(num_speakers).to(cos_sim_matrix.device)
      L = self.criterion(cos_sim_matrix, label)
      return L
  
imports: import torch
  import torch.nn.functional
  from torch import nn
label_desc: Use image node_id 2 for calling the AngleProtoLoss obj's underlying member method code with example usage: obj.forward(x, _label) and returns: L