All problems
SiLU (Swish)
Problem
Apply the SiLU (swish) activation element-wise: f(x) = x * sigmoid(x).
The signature is silu(x). Use a numerically stable sigmoid and return a list of the same length.
Hint
Multiply each value by its sigmoid; for large negatives the product vanishes.
Test cases
case 1
in: [[0]]
expected: [0]
case 2
in: [[1,-1]]
expected: [0.7310585786,-0.2689414214]
case 3
in: [[2,-2,0.5]]
expected: [1.761594156,-0.238405844,0.3112296656]
case 4
in: [[100,-100]]
expected: [100,0]
Starter codePython
import math
def silu(x):
# Your code here
pass4 test cases · run your code against them in the editor