code: def rank_loss(sentence_emb, image_emb, margin=0.2):
      """Experimental rank loss, thanks to kkurach@ for the code."""
      with tf.name_scope("rank_loss"):
          # Normalize first as this is assumed in cosine similarity later.
          sentence_emb = tf.nn.l2_normalize(sentence_emb, 1)
          image_emb = tf.nn.l2_normalize(image_emb, 1)
          # Both sentence_emb and image_emb have size [batch, depth].
          scores = tf.matmul(
              image_emb, tf.transpose(sentence_emb)
          )  # [batch, batch]
          diagonal = tf.diag_part(scores)  # [batch]
          cost_s = tf.maximum(
              0.0, margin - diagonal + scores
          )  # [batch, batch]
          cost_im = tf.maximum(
              0.0, margin - tf.reshape(diagonal, [-1, 1]) + scores
          )  # [batch, batch]
          # Clear diagonals.
          batch_size = tf.shape(sentence_emb)[0]
          empty_diagonal_mat = tf.ones_like(cost_s) - tf.eye(batch_size)
          cost_s *= empty_diagonal_mat
          cost_im *= empty_diagonal_mat
          return tf.reduce_mean(cost_s) + tf.reduce_mean(cost_im)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from six.moves import range
  from six.moves import zip
  from tensor2tensor.layers import common_attention
  from tensor2tensor.layers import common_hparams
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import modalities
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
label_desc: Use image node_id 3 for calling a global function with example usage: rank_loss(sentence_emb, image_emb, margin) and returns: unknown