class_docstr: MaxMarginRanking loss used in COOT paper (Eq. 1): https://arxiv.org/abs/2011.00597
  Inputs:
      - x_embedding: the embedding tensor for a modality with shape (Batch x feature_dimension).
      - y_embedding: the embedding tensor for another input modality with same shape of x_embedding.
        i.e. in COOT paper x_embedding could be video features and y_embedding language features.
      - margin: constant margin in eq. 1 of COOT paper.
  Outputs:
      - **loss**: loss tensor with shape (batch_size,).
class_docstr_tok: ["MaxMarginRanking","loss","used","in","COOT","paper","(","Eq",".","1",")",":","https",":","\/\/arxiv.org\/abs\/2011.00597","Inputs",":","-","x_embedding",":","the","embedding","tensor","for","a","modality","with","shape","(","Batch","x","feature_dimension",")",".","-","y_embedding",":","the","embedding","tensor","for","another","input","modality","with","same","shape","of","x_embedding",".","i.e",".","in","COOT","paper","x_embedding","could","be","video","features","and","y_embedding","language","features",".","-","margin",":","constant","margin","in","eq",".","1","of","COOT","paper",".","Outputs",":","-","*","*","loss","*","*",":","loss","tensor","with","shape","(","batch_size",",",")","."]
docstr: calculate marxmargin ranking loss
docstr_tok: ["calculate","marxmargin","ranking","loss"]
code: def forward(self, x_embedding, y_embedding):
      """calculate marxmargin ranking loss"""
  
      scores = self.sim(
          x_embedding, y_embedding
      )  # calculate the cosine similarity
      diagonal = scores.diag().view(
          x_embedding.size(0), 1
      )  # extract the diagonal scores ( i.e. video_i, sentence_i)
      d1 = diagonal.expand_as(scores)
      d2 = diagonal.t().expand_as(scores)
      cost_x1 = (self.margin + scores - d1).clamp(
          min=0
      )  # First term in eq.1 of COOT paper
      cost_x2 = (self.margin + scores - d2).clamp(
          min=0
      )  # Second term in eq.1 of COOT paper
      mask = torch.eye(scores.size(0)) > 0.5
  
      if self.use_cuda:
          mask = mask.cuda()
  
      cost_x1 = cost_x1.masked_fill_(mask, 0)
      cost_x2 = cost_x2.masked_fill_(mask, 0)
      return (cost_x1.sum() + cost_x2.sum()).div(
          x_embedding.shape[0] * y_embedding.shape[0]
      )
  
file_path: gluon-cv/gluoncv/torch/utils/loss.py
imports: from torch import nn
  import torch
label_desc: Use image node_id 3 for calling the MaxMarginRankingLoss obj's underlying member method code with example usage: obj.forward(x_embedding, y_embedding) and returns: unknown