We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
← Activations step 3 of 9
Easy
Primitives
Implement Tanh
Implement the hyperbolic tangent (tanh) activation function.
$$\tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}}$$
Equivalently: $\tanh(x) = 2\sigma(2x) - 1$ where $\sigma$ is the sigmoid function.
Input: A tensor x of any shape
Output: A tensor of the same shape with values in $(-1, 1)$
Loading visualization…
Nothing accepted yet. When a submission passes, the code that passed shows up
here, one entry per mode.
Stuck?
PyTorch reference solution
Sign in to attempt this problem and reveal the reference solution.