TensorTonic
Problems
Implement GELU Activation (Gaussian Error Linear Unit)
Activation Functions
Medium

Compute the exact Gaussian Error Linear Unit for every input value:

GELU⁡(x)=x2(1+erf⁡(x2))\operatorname{GELU}(x) = \frac{x}{2}\left(1 + \operatorname{erf}\left(\frac{x}{\sqrt{2}}\right)\right)GELU(x)=2x​(1+erf(2​x​))

Here, xxx is an input value and erf⁡\operatorname{erf}erf is the Gaussian error function. Apply the formula elementwise and return a NumPy array with the same shape as the input.

Loading visualization...

Examples

Input: x = [-1.0, 0.0, 1.0]

Output: [-0.158655, 0.0, 0.841345]

Explanation: The exact GELU formula scales negative values toward zero while retaining most of a positive value.

Input: x = [[-2.0, -1.0], [0.0, 1.0]]

Output: [[-0.0455, -0.158655], [0.0, 0.841345]]

Hint 1

Use np.asarray(x, dtype=float) before applying the formula.

Hint 2

Use np.vectorize(math.erf) to apply the scalar error function elementwise.

Requirements

  • Apply the exact error-function formula elementwise
  • Preserve the input shape
  • Return a NumPy array of floating-point values

Constraints

  • x is a nonempty finite numeric list of any depth
  • x contains at most 10610^6106 values
  • Use NumPy and the Python standard library only
Try Similar Problems
Implement Numerically Stable SoftmaxMediumImplement Sigmoid in NumPyEasyImplement Tanh ActivationEasyImplement ReLU Activation in NumPyEasyImplement Swish Activation in NumPyEasyParameter-Matched SwiGLU BlockMediumImplement Leaky ReLU (with α)EasyELU ActivationEasyContinuity of Activation FunctionsMediumSigmoid Boundedness via Squeeze TheoremMediumSoftmax Numerical Stability & Log-Sum-ExpMediumActivation FunctionsEasy
Scratchpad

Accepts: array

You must run your code first.
Implement GELU Activation (Gaussian Error Linear Unit)

Implement GELU Activation (Gaussian Error Linear Unit)

Activation Functions
Medium

Compute the exact Gaussian Error Linear Unit for every input value:

GELU⁡(x)=x2(1+erf⁡(x2))\operatorname{GELU}(x) = \frac{x}{2}\left(1 + \operatorname{erf}\left(\frac{x}{\sqrt{2}}\right)\right)GELU(x)=2x​(1+erf(2​x​))

Here, xxx is an input value and erf⁡\operatorname{erf}erf is the Gaussian error function. Apply the formula elementwise and return a NumPy array with the same shape as the input.

Loading visualization...

Examples

Input: x = [-1.0, 0.0, 1.0]

Output: [-0.158655, 0.0, 0.841345]

Explanation: The exact GELU formula scales negative values toward zero while retaining most of a positive value.

Input: x = [[-2.0, -1.0], [0.0, 1.0]]

Output: [[-0.0455, -0.158655], [0.0, 0.841345]]

Hint 1

Use np.asarray(x, dtype=float) before applying the formula.

Hint 2

Use np.vectorize(math.erf) to apply the scalar error function elementwise.

Requirements

  • Apply the exact error-function formula elementwise
  • Preserve the input shape
  • Return a NumPy array of floating-point values

Constraints

  • x is a nonempty finite numeric list of any depth
  • x contains at most 10610^6106 values
  • Use NumPy and the Python standard library only
Try Similar Problems
Implement Numerically Stable SoftmaxMediumImplement Sigmoid in NumPyEasyImplement Tanh ActivationEasyImplement ReLU Activation in NumPyEasyImplement Swish Activation in NumPyEasyParameter-Matched SwiGLU BlockMediumImplement Leaky ReLU (with α)EasyELU ActivationEasyContinuity of Activation FunctionsMediumSigmoid Boundedness via Squeeze TheoremMediumSoftmax Numerical Stability & Log-Sum-ExpMediumActivation FunctionsEasy
Scratchpad

Accepts: array

You must run your code first.
Problems
Loading...
1 / 1