Browse and solve 1,200+ machine learning coding challenges on Deep-ML. Filter by difficulty (beginner, intermediate, advanced) and category (linear algebra, machine learning, deep learning, NLP, computer vision). Write Python solutions in the browser and get instant feedback against test cases.
Deep-ML | Backward Pass of Tanh Using Cached OutputBackward Pass of Tanh Using Cached Output
Backward Pass of Tanh Using Cached Output
EasyDeep Learning
Example:
Input:
h = np.array([0.0, 0.5, -0.5])
dh = np.array([1.0, 1.0, 1.0])
Output:
[1.0, 0.75, 0.75]
Reasoning:
The derivative of tanh(z) with respect to z is 1 - tanh(z)^2 = 1 - h^2. For h = 0.0: 1 - 0 = 1.0. For h = 0.5: 1 - 0.25 = 0.75. For h = -0.5: 1 - 0.25 = 0.75. Multiplying elementwise by dh = [1,1,1] gives [1.0, 0.75, 0.75].