TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

203. Backprop: Tanh

Easy

Hand-derive the gradient of L = sum(tanh(x)) w.r.t. x.

Forward: y = tanh(x). L = sum(y).

Implement:

  • tanh_forward(x) -> y
  • tanh_backward(x) -> dL/dx of the same shape

Use the identity dy/dx = 1 - y^2.

Math

tanh′(x)=1−tanh2(x)

Related problems

  • Backprop: Tanh (PyTorch)easyPyTorch

Asked at

NumPy

import numpy as np

 

def tanh_forward(...):

    pass

🔒

Premium problem

Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.

Upgrade to PremiumBack to problems

Already premium?