How to use sigmoid activation in neural networks | tf.keras

Sigmoid activation function takes a real value as input and outputs a value between 0 and 1. Its a non linear activation function with fixed output range.

  1. using sigmoid activation function on input `x', produces output with function (1.0 / (1.0 + exp(-x)))

tf.keras.activations module of tf.keras api provides built-in activation to use, refer following code to use `sigmoid` activation function on tensors.


import tensorflow as tf
input = tf.constant([-1.3, -20.3, -25, 19, 38, 21.09], dtype = tf.float32)
output = tf.keras.activations.sigmoid(input)
print(output)

Example output:


tf.Tensor(
[2.1416503e-01 1.5269414e-09 1.3887944e-11 1.0000000e+00 1.0000000e+00
 1.0000000e+00], shape=(6,), dtype=float32)


Follow US on Twitter: