Computes the cosine similarity between the labels and predictions

metric_cosine_similarity(
  ...,
  axis = -1L,
  name = "cosine_similarity",
  dtype = NULL
)

Arguments

...

Passed on to the underlying metric. Used for forwards and backwards compatibility.

axis

(Optional) (1-based) Defaults to -1. The dimension along which the metric is computed.

name

(Optional) string name of the metric instance.

dtype

(Optional) data type of the metric result.

Value

A (subclassed) Metric instance that can be passed directly to compile(metrics = ), or used as a standalone object. See ?Metric for example usage.

Details

cosine similarity = (a . b) / ||a|| ||b||

See: Cosine Similarity.

This metric keeps the average cosine similarity between predictions and labels over a stream of data.

Note

If you want to compute the cosine_similarity for each case in a mini-batch you can use loss_cosine_similarity().

See also