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 tf.logSoftmax() function is used to compute the log softmax.
Syntax:
tf.logSoftmax(logits, axis?)
Parameters:
- logits: the logits array
- axis: The dimension softmax would be performed on
Return Value: It returns tf.Tensor
Example 1:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" const a = tf.tensor1d([3, 2, 6]); a.logSoftmax().print(); |
Output:
Tensor [-3.0658839, -4.0658841, -0.0658839]
Example 2:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" const a = tf.tensor2d([2, 4, 6, 1, 3,7], [2, 3]); a.logSoftmax().print(); |
Output:
Tensor [[-4.1429315, -2.1429317, -0.1429316], [-6.0205812, -4.0205812, -0.0205811]]
Reference: https://js.tensorflow.org/api/latest/#logSoftmax