Sigmoid and Tanh with Their Derivatives

easy
Unit 1 · Activations0/3 to milestone

Implement the two classic squashing activations and their derivatives, written in terms of the outputs (that's how backprop reuses the forward pass):

  • sigmoid(x) and sigmoid_grad(s) where s = sigmoid(x): s(1−s)s(1-s)
  • tanh(x) and tanh_grad(t) where t = tanh(x): 1−t21 - t^2

sigmoid must not overflow for large negative inputs (no warnings for x = -1000).

#activations#backprop2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Sigmoid and Tanh with Their Derivatives · TechGradify