Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Tensorflow.js tf.softmax() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

 

My Personal Notes arrow_drop_up
Last Updated : 14 May, 2021
Like Article
Save Article
Similar Reads
Related Tutorials