liveBook · Manning

Tanh

As explained in Math and Architectures of Deep Learning

A hyperbolic tangent activation function used to introduce nonlinearity in neural networks.

The hyperbolic tangent, or tanh, is an activation function that adds nonlinearity to neural networks. Like sigmoid, it transforms each input nonlinearly, but its outputs range from −1 to 1 rather than 0 to 1, so the response is centered around zero. section 8.1.2

Its training advantage follows from the behavior of its gradient:

  • Near x = 0, tanh has a larger derivative than sigmoid, producing stronger weight updates and potentially faster convergence. section 8.1.2
  • This advantage applies mainly when inputs are centered around zero, as after standardization. section 8.1.2
  • Without a nonlinear activation, stacking linear layers would still produce only a single linear transformation. section 11.1

tanh in LeNet

LeNet places a tanh activation layer after every feature map in its convolutional layers. These activations let the network model nonlinear combinations of image inputs; the original architecture used tanh, although ReLU and sigmoid are alternatives. section 11.1

Figure 8.4 Graph of a 1D tanh function.

Inspect the graph to connect tanh's centered output range with its activation-curve shape. section 8.1.2

Figure 8.5 Graph of the derivatives of 1D sigmoid and tanh functions

Compare the tanh and sigmoid derivative graphs to visualize their different gradient strengths near zero. section 8.1.2

How Math and Architectures of Deep Learning covers it

How deep it goes
Defines the output range and explains gradient behavior near zero, but stops short of implementation details or a derivative formula.
Examples
Uses derivative comparison graphs and LeNet's tanh layers after convolutional feature maps.
What you can do after
Evaluate/understand how centered outputs and stronger near-zero gradients make tanh useful as a neural-network activation.
How it connects
Connects tanh with sigmoid, ReLU, standardization, convolutional layers, feature maps, pooling, and softmax classification.

Also explained in

Compare how 4 books explain tanh →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math and Architectures of Deep Learning. The section links point to the parts of the book it draws on.