code: def contrastive_loss(logits: tf.Tensor) -> tf.Tensor:
      return tf.math.reduce_mean(
          tf.keras.metrics.sparse_categorical_crossentropy(
              y_true=tf.range(shape_list(logits)[0]),
              y_pred=logits,
              from_logits=True,
          )
      )
  
imports: from __future__ import annotations
  import re
  from typing import Optional, Tuple, Union
  import tensorflow
  from tensorflow.keras.layers import Dense
  from ...configuration_utils import PretrainedConfig
  from ...modeling_tf_utils import TFPreTrainedModel, unpack_inputs
  from ...tf_utils import shape_list
  from ...utils import DUMMY_INPUTS, add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from ..auto.configuration_auto import AutoConfig
  from ..auto.modeling_tf_auto import TFAutoModel
  from ..clip.modeling_tf_clip import CLIPVisionConfig, TFCLIPOutput, TFCLIPVisionModel
  from .configuration_vision_text_dual_encoder import VisionTextDualEncoderConfig
label_desc: Use image node_id 1 for calling a global function with example usage: contrastive_loss(logits) and returns: tf