code: def compute_constrastive_loss(
      config,
      contrastive_loss,
      vid_emb,
      par_emb,
      clip_emb,
      sent_emb,
      vid_context,
      par_context,
  ):
      """Normalize embeddings and calculate alignment loss in different levels:
       Video-paragraph, clip-sentence, global context
  
      Args:
          contrastive_loss (loss function): MaxMargingRanking loss
          vid_emb (tensor): video embeddings with shape batch*dim
          par_emb (tensor): paragraph embeddings with shape batch*dim
          clip_emb (tensor): clip embeddings
          sent_emb (tensor): sentence embeddings
          vid_context (tensor): video global context
          par_context (tensor): paragraph global context
  
      Returns:
          total loss
      """
      vid_context_norm = F.normalize(vid_context)
      clip_emb_norm = F.normalize(clip_emb)
      vid_emb_norm = F.normalize(vid_emb)
      par_context_norm = F.normalize(par_context)
      sent_emb_norm = F.normalize(sent_emb)
      par_emb_norm = F.normalize(par_emb)
  
      loss = contrastive_loss(vid_emb_norm, par_emb_norm)
      loss += (
          config.CONFIG.TRAIN.LOSS_CONTRASTIVE_CLIP_W
          * contrastive_loss(clip_emb_norm, sent_emb_norm)
      )
      loss += contrastive_loss(vid_context_norm, par_context_norm)
      loss += (
          contrastive_loss(vid_emb_norm, vid_emb_norm)
          + contrastive_loss(par_emb_norm, par_emb_norm)
      ) / 2
      loss += (
          contrastive_loss(clip_emb_norm, clip_emb_norm)
          + contrastive_loss(sent_emb_norm, sent_emb_norm)
      ) / 2
      return loss
  
imports: import ctypes
  import datetime
  import logging
  import multiprocessing
  import os
  from pathlib import Path
  import random
  import sys
  from typing import Tuple, Dict
  import numpy
  import torch
  import torch.backends.cudnn
  from torch import cuda
  import torch.nn.functional
label_desc: Use image node_id 19 for calling a global function with example usage: compute_constrastive_loss(config, contrastive_loss, vid_emb, par_emb, clip_emb, sent_emb, vid_context, par_context) and returns: loss