Open In App

Tensorflow.js tf.softmax() 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 tf.softmax() function is used to compute the softmax normalized vector given the logits.



Syntax:

tf.softmax (logits, dim?)

Parameters: This function accept two parameters which are illustrated below:



Return Value: It returns tf.Tensor

Example 1:




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
const a = tf.tensor1d([3, 1, 3]);
a.softmax().print();

 

 

Output:

 

Tensor
    [0.4683105, 0.0633789, 0.4683105]

 

Example 2:

 




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
const a = tf.tensor1d([3, 1, 3]);
a.softmax().print();

 

 

Output:

 

Tensor
    [[0.9525742, 0.0474259],
     [0.7310586, 0.2689414],
     [0.9933072, 0.0066929]]

 

Reference: https://js.tensorflow.org/api/latest/#softmax

 

Article Tags :