class_docstr: Contrastive Model, currently mainly focused on memory bank and CSC.
class_docstr_tok: ["Contrastive","Model",",","currently","mainly","focused","on","memory","bank","and","CSC","."]
code: def sim_loss(self, q, k):
      similarity = torch.einsum("nc,nc->n", [q, k])  # N-dim
      # similarity += delta_t # higher if time distance is larger
      # sim = sim - max_margin + delta_t * k
      similarity /= self.T  # history-compatible
      loss = -similarity.mean()
      return loss
  
imports: import math
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import slowfast.models.losses
  import slowfast.utils.distributed
  import slowfast.utils.logging
  from slowfast.models.video_model_builder import X3D, MViT, ResNet, SlowFast
  from .build import MODEL_REGISTRY
label_desc: Use image node_id 8 for calling the ContrastiveModel obj's underlying member method code with example usage: obj.sim_loss(q, k) and returns: loss