Open In App

Tensorflow.js tf.softmax() Function

Improve
Improve
Like Article
Like
Save
Share
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. 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:

  • Logits: the logits array.
  • dim: 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, 1, 3]);
a.softmax().print();


 

 

Output:

 

Tensor
    [0.4683105, 0.0633789, 0.4683105]

 

Example 2:

 

Javascript




// 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

 


Last Updated : 14 May, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads