ReLU & GELU Activations

easy
Checkpoint challenge
Solve this to show you know the material and jump straight to Unit 2. Everything before it counts as cleared.

Activation functions add the non-linearity that lets neural networks learn complex patterns.

Implement three vectorised functions:

  • relu(x): max⁡(0,x)\max(0, x)
  • relu_grad(x): the derivative of ReLU, which is 1.0 where x>0x > 0 and 0.0 elsewhere
  • gelu(x): the tanh approximation used by GPT-2 and BERT:
GELU(x)≈0.5 x(1+tanh⁡[2/π (x+0.044715 x3)])\text{GELU}(x) \approx 0.5\,x\left(1 + \tanh\left[\sqrt{2/\pi}\,(x + 0.044715\,x^3)\right]\right)

All three take and return NumPy arrays of any shape.

#activations#numpy3 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
ReLU & GELU Activations · TechGradify