ReLU — find the dead neurons
Background
A ReLU unit outputs . If a neuron's pre-activation is for every input it ever sees, its output is always and its gradient is always — it can never learn. This is the dead neuron problem.
Given a batch of pre-activations (one row per example, one column per neuron), a neuron is dead when its whole column is .
Problem statement
Implement dead_neurons(Z) returning a boolean mask flagging which neurons (columns) are dead across the batch.
Input
Z— array-like of shape(batch, units): pre-activations before ReLU.
Output
Returns a boolean np.ndarray of length units: True where that neuron's pre-activation is for all rows.
Examples
Example 1
Input: Z = [[-1, 2, -3], [-4, 5, -6]]
Output: [ True False True]
Explanation: column 0 is (all → dead), column 1 has a positive value (alive), column 2 is all negative (dead).
Example 2 — a zero column is dead
Input: Z = [[0, 1], [0, 2]]
Output: [ True False]
Explanation: ReLU(0) = 0 with zero gradient, so an all-zero column counts as dead.
Constraints
- A neuron is dead iff the maximum of its column is .
- Return a boolean
np.ndarrayof lengthunits.
Notes
- Dead neurons motivate Leaky ReLU / GELU, which keep a small gradient for so units can recover.
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Mixed columns example
- •Zero column reference
- •One tiny positive keeps a neuron alive (sample)