Open In App

Tensorflow.js tf.softplus() Function

Last Updated : 18 May, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.

The .softplus() function is used to find softplus of the stated input tensor i.e. log(exp(x) + 1) and is done element wise.

Syntax :  

tf.softplus(x)

Parameters:  

  • x: It is the stated tensor input, and it can be of type tf.Tensor, TypedArray, or Array.

Return Value: It returns the tf.Tensor object.

Example 1:  

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining tensor input elements
const y = tf.tensor1d([11, 17, 0, NaN, -41]);
  
// Calling softplus() method and
// Printing output
y.softplus().print();


Output:

Tensor
    [11.0000162, 17, 0.6931472, NaN, 0]

Example 2:

Javascript




// Importing the tensorflow.js library 
import * as tf from "@tensorflow/tfjs"
  
// Defining tensor input
var val = [1.5, .4, .23, null, 'a'];
  
// Calling tensor1d method
const y = tf.tensor1d(val);
  
// Calling softplus() method
var res = tf.softplus(y)
  
// Printing output
res.print();


Output:

Tensor
    [1.7014132, 0.9130152, 0.8147451, 0.6931472, NaN]

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads