Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-067

GELU Exact (Erf)

Problem

Apply the exact GELU activation element-wise: f(x) = 0.5 * x * (1 + erf(x / sqrt(2))), using math.erf.

The signature is exact_gelu(x). Return a list.

Hint

The exact GELU uses the error function, not tanh; the CDF of a standard normal appears here.

Test cases

case 1
in: [[0]]
expected: [0]
case 2
in: [[1,-1]]
expected: [0.8413447461,-0.1586552539]
case 3
in: [[2,-2,0.5]]
expected: [1.9544997361,-0.0455002639,0.3457312306]
case 4
in: [[3,-3]]
expected: [2.9959503059,-0.0040496941]
Starter codePython
import math
def exact_gelu(x):
    # Your code here
    pass

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