code: def cosine_similarity(y_true, y_pred, axis=-1):
      """Computes the cosine similarity between labels and predictions.
  
      Formula:
  
      ```python
      loss = sum(l2_norm(y_true) * l2_norm(y_pred))
      ```
  
      Args:
          y_true: Tensor of true targets.
          y_pred: Tensor of predicted targets.
          axis: Axis along which to determine similarity. Defaults to `-1`.
  
      Returns:
          Cosine similarity tensor.
  
      Example:
  
      >>> y_true = [[0., 1.], [1., 1.], [1., 1.]]
      >>> y_pred = [[1., 0.], [1., 1.], [-1., -1.]]
      >>> loss = keras.losses.cosine_similarity(y_true, y_pred, axis=-1)
      [0., 0.99999994, -0.99999994]
      """
      y_pred = ops.convert_to_tensor(y_pred)
      y_true = ops.convert_to_tensor(y_true, dtype=y_pred.dtype)
      y_true, y_pred = squeeze_to_same_rank(y_true, y_pred)
      y_pred = normalize(y_pred, axis=axis)
      y_true = normalize(y_true, axis=axis)
      return ops.sum(y_true * y_pred, axis=axis)
  
imports: import warnings
  from keras import initializers
  from keras import ops
  from keras.api_export import keras_export
  from keras.losses.loss import squeeze_to_same_rank
  from keras.losses.losses import log_cosh
  from keras.losses.losses import mean_absolute_error
  from keras.losses.losses import mean_absolute_percentage_error
  from keras.losses.losses import mean_squared_error
  from keras.losses.losses import mean_squared_logarithmic_error
  from keras.metrics import reduction_metrics
  from keras.utils.numerical_utils import normalize
label_desc: Use image node_id 1 for calling a global function with example usage: cosine_similarity(y_true, y_pred, axis) and returns: ops