Tensorflow.js tf.losses.cosineDistance() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.
The tf.losses.cosineDistance() function is used to Compute the cosine distance loss between two tensors.
tf.losses.cosineDistance(labels, predictions, axis, weights?, reduction?)
Parameters: This function accepts five parameters in which the last two are optional, which are illustrated below:
- labels: The ground truth output tensor. The dimensions will be the same as predictions.
- predictions: The predicted outputs.
- axis: The cosine distance is computed along this dimension.
- weights: It is a Tensor having rank 0, or the same rank as labels, and it must be broadcastable to labels that mean all the dimensions must be either 1, or the same as the corresponding losses dimension. This parameter is optional.
- reduction: The type of reduction to apply to loss. This is also an optional parameter.
Return Value: It returns a Tensor which is a cosine distance loss between two tensors.
Example 2: In this example, we will pass one extra parameter that is weight. This is an optional parameter.