Skip to content
DeepForgeby svx

Problem

Apply the mish activation element-wise: f(x) = x * tanh(softplus(x)), where softplus is computed stably as max(x, 0) + log1p(exp(-|x|)).

The signature is mish(x).

Hint

Mish is x times the tanh of softplus, so it is smooth and non-monotonic near zero.

Test cases

case 1
in: [[0]]
expected: [0]
case 2
in: [[1,-1]]
expected: [0.8650983883,-0.3034014614]
case 3
in: [[2,-2,0.5]]
expected: [1.9439589595,-0.2525014827,0.3752452113]
case 4
in: [[100,-100]]
expected: [100,0]
Starter codePython
import math
def mish(x):
    # Your code here
    pass

4 test cases · run your code against them in the editor