Tensorflow.js tf.losses.logLoss() Function Last Updated : 17 Jun, 2021 Comments Improve Suggest changes Like Article Like Report 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.logLoss() function calculates the log loss between two given tensors. Syntax: tf.losses.logLoss (labels, predictions, weights?, epsilon?, reduction?) Parameters: labels: It specifies the truth output tensor. The absolute difference is predicted based on this tensor.predictions: It specifies the predicted output tensor with the same dimensions as labels.weights: It specifies a tensor of rank either equal to that of labels so that it can be broadcastable or 0. It is an optional parameter.epsilon: A small constant value to avoid taking log of zero. It is an optional parameter.reduction: It specifies the type of reduction to the loss. It is optional. Return Value: It returns a tf.Tensor which is calculated by logLoss() function. Example 1: In this example we will take two 2d tensors as labels and prediction. Then we will find the log loss of these two tensors. JavaScript // Importing the tensorflow.js library const tf = require("@tensorflow/tfjs"); // Defining label tensor const x_label = tf.tensor2d([ [0., 1., 0.], [1., 0., 1.] ]); // Defining prediction tensor const x_pred = tf.tensor2d([ [1., 1., 1.], [0., 0., 0. ] ]); // Calculating log loss const log_loss = tf.losses.logLoss(x_label,x_pred) // Printing the output log_loss.print() Output: Tensor 10.745397567749023 Example 2: In this example we will log loss of two given tensors and avoid taking log of zero using a small constant value, epsilon. JavaScript // Importing the tensorflow.js library const tf = require("@tensorflow/tfjs"); // Defining label tensor const x_label = tf.tensor2d([ [1, 0, 0], [1, 1, 0] ]); // Defining prediction tensor const x_pred = tf.tensor2d([ [1, 1, 1], [0, 0, 0] ]); const epsilon = 0.1; // Calculating log loss const log_loss = tf.losses.logLoss(x_label,x_pred,epsilon) // Printing the output log_loss.print() Output: Tensor 1.0745397806167603 Reference: https://js.tensorflow.org/api/latest/#losses.logLoss Comment More infoAdvertise with us Next Article Tensorflow.js tf.losses.logLoss() Function A abhinavjain194 Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js Similar Reads Tensorflow.js tf.losses.hingeLoss() 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.hingeLoss() function calculates the hinge loss between two given tensors. Syntax: tf.losses.hingeLoss (lab 2 min read Tensorflow.js tf.log() Function Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .log() function is used to find the natural logarithm of the stated tensor input i.e. ln(x) and is done eleme 1 min read Tensorflow.js tf.logSumExp() 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.logSumExp() function is used to calculate log sum exp of elements of a Tensor across its dimension. It reduces the given input 2 min read Tensorflow.js tf.losses.huberLoss() 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. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js. The Ten 2 min read Tensorflow.js tf.log1p() Function Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .log1p() function is used to find the natural logarithm of the stated tensor input plus one i.e. ln(1 + x) an 1 min read Like