class_docstr: Compute CycleConsistency loss in COOT paper (Eq. 8)
  
  Args:
      clip_emb: Embeddings of clips
      clip_mask: Mask
      clip_lens: Number of clips per each video
      sentence_emb: Embeddings of sentences
      sentence_mask: Mask for input language
      sentence_lens: Number of sentences per paragraph
  
  Outputs:
      - ** clip to clip loss**: loss tensor with shape (batch_size,).
      - ** sentence to sentence loss**: loss tensor with shape (batch_size,).
class_docstr_tok: ["Compute","CycleConsistency","loss","in","COOT","paper","(","Eq",".","8",")","Args",":","clip_emb",":","Embeddings","of","clips","clip_mask",":","Mask","clip_lens",":","Number","of","clips","per","each","video","sentence_emb",":","Embeddings","of","sentences","sentence_mask",":","Mask","for","input","language","sentence_lens",":","Number","of","sentences","per","paragraph","Outputs",":","-","*","*","clip","to","clip","loss","*","*",":","loss","tensor","with","shape","(","batch_size",",",")",".","-","*","*","sentence","to","sentence","loss","*","*",":","loss","tensor","with","shape","(","batch_size",",",")","."]
code: def _get_loss(self, emb_mask, emb_lens, emb_max_len, beta):
      idx_orig = torch.arange(emb_max_len)
      batch_size, _ = emb_mask.shape
      if self.use_cuda:
          idx_orig = idx_orig.cuda(non_blocking=True)
      idx_orig.unsqueeze_(0)
      index_nn = torch.sum(idx_orig.unsqueeze(1) * beta, dim=-1)
      idx_nn_rep, idx_orig_rep, emb_mask_rep = self._get_mxn_repr(
          index_nn, emb_mask, idx_orig, emb_mask
      )
      distance = self.loss_distance_fn(
          idx_nn_rep.unsqueeze(-1), idx_orig_rep.unsqueeze(-1)
      )
      distance.masked_fill_(emb_mask_rep == 0, 0)
      l_seq = distance.diagonal(dim1=-2, dim2=-1)
      if self.num_samples != -1:
          n_samp = torch.min(emb_lens, self.num_samples_tensor)
          total_loss = 0
          for _, (c_loss, c_mask, c_nsamp) in enumerate(
              zip(l_seq, emb_mask, n_samp)
          ):
              idx = torch.multinomial(c_mask, int(c_nsamp))
              total_loss += c_loss[idx].mean()
          return total_loss / batch_size
  
      else:
          return (l_seq.sum(dim=-1) / emb_lens).mean(dim=-1)
  
file_path: gluon-cv/gluoncv/torch/utils/loss.py
imports: from torch import nn
  import torch
label_desc: Use image node_id 7 for calling the CycleConsistencyCootLoss obj's underlying member method code with example usage: obj._get_loss(emb_mask, emb_lens, emb_max_len, beta) and returns: unknown, unknown