code: def _calculate_similarity(self, logits, negatives, targets):
      neg_is_pos = (targets == negatives).all(-1)
      # NxT' - true where the negative is actually the positive
      targets = targets.unsqueeze(0)
      # 1xT'xC
      targets = torch.cat([targets, negatives], dim=0)
      # (1+N)xT'XC
      logits = torch.cosine_similarity(
          logits.float().unsqueeze(0).expand(targets.shape[0], -1, -1),
          targets.float(),
          dim=-1,
      ).type_as(logits)
      # (1+N)xT'
      logits /= self.logit_temp
      if neg_is_pos.any():
          logits[1:][neg_is_pos] = float("-inf")
      return logits
  
file_path: NeMo/nemo/collections/asr/losses/ssl_losses/contrastive.py
imports: import torch
  import torch.nn.functional
  from torch import nn
  from nemo.core import Loss, typecheck
  from nemo.core.neural_types import AcousticEncodedRepresentation, LengthsType, LossType, NeuralType, SpectrogramType
label_desc: Use image node_id 7 for calling the ContrastiveLoss obj's underlying member method code with example usage: obj._calculate_similarity(logits, negatives, targets) and returns: logits