Tensorflow is an open-source machine learning library developed by Google. One of its applications is to develop deep neural networks.
tensorflow.nn provides support for many basic neural network operations.
One of the many activation functions is the hyperbolic tangent function (also known as tanh) which is defined as .
The hyperbolic tangent function outputs in the range (-1, 1), thus mapping strongly negative inputs to negative values. Unlike the sigmoid function, only near-zero values are mapped to near-zero outputs, and this solves the “vanishing gradients” problem to some extent. The hyperbolic tangent function is differentiable at every point and its derivative comes out to be . Since the expression involves the tanh function, its value can be reused to make the backward propagation faster.
Despite the lower chances of the network getting “stuck” when compared with the sigmoid function, the hyperbolic tangent function still suffers from “vanishing gradients”. Rectified Linear Unit (ReLU) can be used to overcome this problem.
tf.tanh] provides support for the hyperbolic tangent function in Tensorflow.
Syntax: tf.nn.tanh(x, name=None) or tf.tanh(x, name=None)
x: A tensor of any of the following types: float16, float32, double, complex64, or complex128.
name (optional): The name for the operation.
Return : A tensor with the same type as that of x.
Input type: Tensor("Const_2:0", shape=(6, ), dtype=float32) Input: [ 1. -0.5 3.4000001 -2.0999999 0. -6.5 ] Return type: Tensor("tanh_2:0", shape=(6, ), dtype=float32) Output: [ 0.76159418 -0.46211717 0.9977749 -0.97045201 0. -0.99999547]
Code #2: Visualization
Input: [-5. -4.28571429 -3.57142857 -2.85714286 -2.14285714 -1.42857143 -0.71428571 0. 0.71428571 1.42857143 2.14285714 2.85714286 3.57142857 4.28571429 5. ] Output: [-0.9999092 -0.99962119 -0.99842027 -0.99342468 -0.97284617 -0.89137347 -0.61335726 0. 0.61335726 0.89137347 0.97284617 0.99342468 0.99842027 0.99962119 0.9999092 ]
- Python - tensorflow.eye()
- Python - tensorflow.raw_ops.Tan()
- Python - tensorflow.raw_ops.Sin()
- Python | Tensorflow exp() method
- Python - tensorflow.math.pow()
- Python - tensorflow.GradientTape()
- Python - tensorflow.gradients()
- Python - tensorflow.raw_ops.Exp()
- Python - tensorflow.DeviceSpec
- Python - tensorflow.dynamic_stitch()
- Python - tensorflow.math.less()
- Python - tensorflow.dynamic_partition()
- Python - tensorflow.constant_initializer()
- Python - tensorflow.raw_ops.Log()
- Python - tensorflow.get_static_value()
- Python - tensorflow.device()
- Python | Tensorflow abs() method
- Python | Tensorflow nn.sigmoid()
- Python - tensorflow.math.cos()
- Python - tensorflow.clip_by_norm()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : sanskar27jain