5 hidden checks

The three functions at the heart of every classifier, written so they never produce nan or inf.

  • sigmoid(z): element-wise on an array. It must not overflow for large negative z (try np.exp(1000)). One approach: np.where(z >= 0, 1 / (1 + np.exp(-z)), np.exp(z) / (1 + np.exp(z))), but beware that np.where evaluates both branches; clipping z to [-500, 500] first is a simple fix.
  • bce(p, y): mean binary cross-entropy for probability array p and 0/1 labels y. Clip p to [1e-12, 1 - 1e-12].
  • softmax(Z): row-wise softmax of a 2-D array of logits. Subtract each row's max.
checks
  • sigmoid has the right valuesnot run
  • sigmoid survives extreme inputsnot run
  • bce matches the formula and stays finitenot run
  • softmax rows sum to 1 and match the formulanot run
  • softmax survives huge logitsnot run
python sleeps until you press run

Press Run & check. Your code runs first, then the hidden checks on the left.