class_docstr: Computes the cosine similarity between the labels and predictions.
  
  Formula:
  
  ```python
  loss = sum(l2_norm(y_true) * l2_norm(y_pred))
  ```
  See: [Cosine Similarity](https://en.wikipedia.org/wiki/Cosine_similarity).
  This metric keeps the average cosine similarity between `predictions` and
  `labels` over a stream of data.
  
  Args:
      name: (Optional) string name of the metric instance.
      dtype: (Optional) data type of the metric result.
      axis: (Optional) Defaults to `-1`. The dimension along which the cosine
          similarity is computed.
  
  Examples:
  
  Standalone usage:
  
  >>> # l2_norm(y_true) = [[0., 1.], [1./1.414, 1./1.414]]
  >>> # l2_norm(y_pred) = [[1., 0.], [1./1.414, 1./1.414]]
  >>> # l2_norm(y_true) . l2_norm(y_pred) = [[0., 0.], [0.5, 0.5]]
  >>> # result = mean(sum(l2_norm(y_true) . l2_norm(y_pred), axis=1))
  >>> #        = ((0. + 0.) +  (0.5 + 0.5)) / 2
  >>> m = keras.metrics.CosineSimilarity(axis=1)
  >>> m.update_state([[0., 1.], [1., 1.]], [[1., 0.], [1., 1.]])
  >>> m.result()
  0.49999997
  >>> m.reset_state()
  >>> m.update_state([[0., 1.], [1., 1.]], [[1., 0.], [1., 1.]],
  ...                sample_weight=[0.3, 0.7])
  >>> m.result()
  0.6999999
  
  Usage with `compile()` API:
  
  ```python
  model.compile(
      optimizer='sgd',
      loss='mse',
      metrics=[keras.metrics.CosineSimilarity(axis=1)])
  ```
class_docstr_tok: ["Computes","the","cosine","similarity","between","the","labels","and","predictions",".","Formula",":","``","`","python","loss","=","sum","(","l2_norm","(","y_true",")","*","l2_norm","(","y_pred",")",")","``","`","See",":","[","Cosine","Similarity","]","(","https",":","\/\/en.wikipedia.org\/wiki\/Cosine_similarity",")",".","This","metric","keeps","the","average","cosine","similarity","between","`","predictions","`","and","`","labels","`","over","a","stream","of","data",".","Args",":","name",":","(","Optional",")","string","name","of","the","metric","instance",".","dtype",":","(","Optional",")","data","type","of","the","metric","result",".","axis",":","(","Optional",")","Defaults","to","`","-1","`",".","The","dimension","along","which","the","cosine","similarity","is","computed",".","Examples",":","Standalone","usage",":",">",">",">","#","l2_norm","(","y_true",")","=","[","[","0.",",","1",".","]",",","[","1.\/1.414",",","1.\/1.414","]","]",">",">",">","#","l2_norm","(","y_pred",")","=","[","[","1.",",","0",".","]",",","[","1.\/1.414",",","1.\/1.414","]","]",">",">",">","#","l2_norm","(","y_true",")",".","l2_norm","(","y_pred",")","=","[","[","0.",",","0",".","]",",","[","0.5",",","0.5","]","]",">",">",">","#","result","=","mean","(","sum","(","l2_norm","(","y_true",")",".","l2_norm","(","y_pred",")",",","axis=1",")",")",">",">",">","#","=","(","(","0",".","+","0",".",")","+","(","0.5","+","0.5",")",")","\/","2",">",">",">","m","=","keras.metrics.CosineSimilarity","(","axis=1",")",">",">",">","m.update_state","(","[","[","0.",",","1",".","]",",","[","1.",",","1",".","]","]",",","[","[","1.",",","0",".","]",",","[","1.",",","1",".","]","]",")",">",">",">","m.result","(",")","0.49999997",">",">",">","m.reset_state","(",")",">",">",">","m.update_state","(","[","[","0.",",","1",".","]",",","[","1.",",","1",".","]","]",",","[","[","1.",",","0",".","]",",","[","1.",",","1",".","]","]",",","...","sample_weight=","[","0.3",",","0.7","]",")",">",">",">","m.result","(",")","0.6999999","Usage","with","`","compile","(",")","`","API",":","``","`","python","model.compile","(","optimizer='sgd","'",",","loss='mse","'",",","metrics=","[","keras.metrics.CosineSimilarity","(","axis=1",")","]",")","``","`"]
code: def __init__(self, name="cosine_similarity", dtype=None, axis=-1):
      super().__init__(cosine_similarity, name, dtype=dtype, axis=axis)
      # Metric should be maximized during optimization.
      self._direction = "up"
  
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 to create a new CosineSimilarity object from inherited base classes: reduction_metrics with example: obj = CosineSimilarity(name, dtype, axis)