// Importing the tensorflow.js library
const tf = require("@tensorflow/tfjs");
// Defining label tensor
const y_true = tf.tensor2d(
[0., 1., 0., 0., 0., 0., 1.,
0., 1., 1., 0., 1.], [4, 3]
);
// Defining predicted tensor
const y_pred = tf.tensor2d(
[1., 1., 0., 1., 0., 0., 1.,
1., 1., 0., 0., 1.], [4, 3]
);
// Calculating absolute difference
const absolute_difference = tf.losses.absoluteDifference(
y_true, y_pred, [0.7, 0.3, 0.2])
absolute_difference.print()