Tensorflow.js tf.losses.softmaxCrossEntropy() 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 Tensorflow.js tf.losses.softmaxrossEntropy() function Computes the softmax cross entropy loss between two tensors and returns a new tensor.
tf.losses.softmaxCrossEntropy(onehotLabels, logits, weights, labelSmoothing, reduction)
Parameters: This function accepts five parameters (in which the last three are optional) which are illustrated below:
- onehotLabels: It is a hot encoded label that has the same dimensions as predictions.
- logits: It is the predicted outputs.
- weights: These are those tensors whose rank is either 0 or 1, and they must be broad castable to loss of shape.
- labelSmoothing: If the value of this parameter is greater than 0, then it smooths the labels.
- reduction: It is the type of reduction to apply to loss. It must be of Reduction type.
Note: Parameters like weights, labelSmoothing, and reduction are optional.
Return Value: It returns a tensor having softmax cross-entropy loss between two tensors.
Example 2: In this example, we are passing on an optional parameter that is label smoothing. If it is greater than 0, then smooth the labels.