code: def get_contrastive_labels(
      inners: jnp.ndarray,
      text_mask: jnp.ndarray,
      loss_exclude_hn_other_vid: bool = True,
  ) -> Tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray]:
      """Labels the inner products compute from `compute_inners`.
  
      Given an output from `_compute_inners` and text_mask, returns:
      -labels: indicates where is positive by 1.
      -masking: indicates where is masking by large neg number.
  
      Args:
        inners: The inner products returned from `compute_inners`.
        text_mask: This is 1 where we need to mask it out (padding), of
          shape D x 1 where D = batch_size x max_num_captions
        loss_exclude_hn_other_vid: Hard negative for element i of the batch is
          ignored (ie. used neither as negative not positive) for batch elements j.
  
      Returns:
      -labels: 0 where negative or padding, 1 where positive
      -masking: 0 where positive or negative caption, -100000 where padding
      """
      # labels 1 for positive, 0 for negative
      labels = jnp.zeros(inners.shape, dtype=inners.dtype)
      bs = inners.shape[0]
      max_num_captions = int(text_mask.shape[0] / bs)
      mask_hn_other_vid = jnp.ones(max_num_captions, dtype=inners.dtype)
      if loss_exclude_hn_other_vid:
          mask_hn_other_vid = mask_hn_other_vid.at[0].set(0)
          mask_hn_other_vid = jnp.transpose(
              jnp.tile(
                  jnp.expand_dims(jnp.tile(mask_hn_other_vid, bs), 1),
                  bs,
              )
          )
      inverse_mask_hn_other_vid = jnp.ones(
          inners.shape, dtype=inners.dtype
      )
      # 0 for those we want in logsoftmax, -1000000 for those we want to ignore
      large_neg_number = -1000000
      for idx in range(bs):
          labels = labels.at[idx, idx * max_num_captions].set(1)
          if loss_exclude_hn_other_vid:
              start = idx * max_num_captions
              end = idx * max_num_captions + max_num_captions
              mask_hn_other_vid = mask_hn_other_vid.at[
                  idx, start:end
              ].set(jnp.squeeze(text_mask[start:end]))
      masking = (
          jnp.transpose(jnp.tile(text_mask, bs)) * large_neg_number
      )
      if loss_exclude_hn_other_vid:
          inverse_mask_hn_other_vid = (
              inverse_mask_hn_other_vid - mask_hn_other_vid
          )
          masking = mask_hn_other_vid * large_neg_number
      return labels, masking, inverse_mask_hn_other_vid
  
file_path: scenic/scenic/projects/verbs_in_action/losses.py
imports: from typing import Tuple
  import flax.linen
  import jax.numpy
  import numpy
  from scenic.projects.verbs_in_action import utils
label_desc: Use image node_id 5 for calling a global function with example usage: get_contrastive_labels(inners, text_mask, loss_exclude_hn_other_vid) and returns: labels,  masking,  inverse_mask_hn_other_vid