Thursday, December 11, 2025
HomeLanguagesJavascriptTensorflow.js tf.softmax() Function

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:

  • 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

 

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32441 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6813 POSTS0 COMMENTS
Nicole Veronica
11950 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12024 POSTS0 COMMENTS
Shaida Kate Naidoo
6943 POSTS0 COMMENTS
Ted Musemwa
7195 POSTS0 COMMENTS
Thapelo Manthata
6889 POSTS0 COMMENTS
Umr Jansen
6880 POSTS0 COMMENTS