ReLU With the Corner Sanded Off

Activation FunctionsMedium+20 XP+20

ReLU With the Corner Sanded Off

ReLU has a sharp corner at 000, where its slope jumps straight from 000 to 111 with nothing in between. Softplus is a smooth stand-in that looks like ReLU from a distance but rounds the corner off:

softplus(x)=ln⁡(1+ex)\text{softplus}(x) = \ln\left(1 + e^{x}\right)softplus(x)=ln(1+ex)

Far to the left it hugs 000. Far to the right it hugs the line y=xy = xy=x. Near 000 it bends smoothly, so its slope changes gradually instead of jumping.

Task: write softplus_with_slope(values). For each pre-activation xxx in the list values, produce the pair [softplus(x), slope], where slope is the derivative of softplus at xxx. Round both numbers to 4 decimal places and return the pairs as a list, in the same order as the input. An empty list gives an empty list.

The layer this runs in sees pre-activations as large as ±1000\pm 1000±1000. Your function must return correct, finite numbers for them, and must not crash.

Examples

values = [0.0, 1.0, -2.0]
returns [[0.6931, 0.5], [1.3133, 0.7311], [0.1269, 0.1192]]
values = [3.5, -0.5, 10.0]
returns [[3.5298, 0.9707], [0.4741, 0.3775], [10.0, 1.0]]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run