induwara.lk
induwara.lkAI · Machine learning

Activation Function Calculator

Compute ReLU, Leaky ReLU, GELU (exact or tanh), SiLU/Swish, Tanh and ELU for a single value or a whole vector — each with its formula, derivative, a plotted curve and step-by-step working. Verified against PyTorch, no signup, runs in your browser.

By Induwara AshinsanaUpdated Jul 13, 2026
Activation function calculator

A single number or a comma/space/newline-separated vector. Negatives and decimals are fine. Up to 256 values.

0 ≤ α ≤ 1. Default 0.01.

0 < α ≤ 10. Default 1.0.

Exact uses erf; tanh is the GPT/BERT form.

Examples
GELU(x₀)
1.954500
at x₀ = 2.0000
GELU′(x₀)
toggle 'Show derivative'
Values
1
single scalar
Cross-check gap
2.2e-16
tanh & SiLU identity self-test

GELU curve

-0.662.926.49-606x

Amber dots mark your input; points beyond the visible range sit on the nearest edge.

All functions at your input

FunctionFormulaf(x₀)
ReLUmax(0, x)
Leaky ReLUx if x>0, else 0.01·x
GELUx·Φ(x), Φ(x)=½(1+erf(x/√2))
SiLU / Swishx·σ(x), σ(x)=1/(1+e⁻ˣ)
Tanh(eˣ−e⁻ˣ)/(eˣ+e⁻ˣ)
ELUx if x>0, else 1·(eˣ−1)

GELU output

[1.954500]
Copy

GELU step-by-step (first value)

  1. 1. Input: x = 2.000000
  2. 2. Φ(x) = ½(1 + erf(x/√2)) = ½(1 + erf(1.414214)) = 0.977250
  3. 3. GELU(x) = x·Φ(x) = 2.000000 × 0.977250 = 1.954500

Method: each function uses its originating-paper definition — ReLU max(0,x), Leaky ReLU, GELU x·Φ(x) (erf via Abramowitz & Stegun 7.1.26, |err|≤1.5×10⁻⁷) or its tanh approximation, SiLU/Swish x·σ(x), Tanh, and ELU. Sigmoid uses the numerically-stable branch. Everything runs in your browser — no data leaves this page.

How it works

An activation functionis applied element-wise to a neuron's pre-activation (the weighted sum plus bias) to introduce the non-linearity a neural network needs to learn. This tool implements the six most common ones exactly as their originating papers define them, and reproduces the behaviour of PyTorch's torch.nn.functional.

  • ReLU max(0, x). Zeroes every negative input; derivative 1 for x > 0, else 0 (Nair & Hinton, 2010).
  • Leaky ReLU x if x>0 else α·x, default slope α = 0.01, so negatives leak a small gradient instead of dying (Maas et al., 2013).
  • GELU x·Φ(x)with Φ the standard-normal CDF, Φ(x) = ½(1 + erf(x/√2)). The tanh approximation ½x(1 + tanh(√(2/π)(x + 0.044715x³))) is the form used inside GPT and BERT (Hendrycks & Gimpel, 2016).
  • SiLU / Swish x·σ(x), sigmoid-gated and smooth; Swish with β = 1 is identical (Elfwing 2017; Ramachandran 2017).
  • Tanh (eˣ−e⁻ˣ)/(eˣ+e⁻ˣ), a zero-centred squashing function bounded in (−1, 1) with derivative 1 − tanh²(x).
  • ELU x if x>0 else α(eˣ−1), default α = 1, which saturates at −α for large negatives (Clevert et al., 2015).

The exact GELU needs the error function erf, computed here with the Abramowitz & Stegun 7.1.26 rational approximation (maximum error 1.5×10⁻⁷), which is comfortably tighter than the six decimals shown. The sigmoid inside SiLU uses the numerically-stable sign-aware branch — 1/(1+e⁻ˣ) when x ≥ 0 and eˣ/(1+eˣ) when x < 0 — so extreme inputs never overflow to Infinity or NaN; SiLU(1e9) returns 1e9 and ELU(−1000) returns −1 cleanly.

To prove the implementation is self-consistent, the module recomputes two of the functions by independent algebraic identities — tanh(x) = 2σ(2x) − 1 and SiLU(x) = x·½(1+tanh(x/2)) — and reports the largest disagreement, which is 0 (≈1e-16) for every input. All arithmetic is double-precision JavaScript; results are rounded only for display, never for chained computation, and nothing is sent to a server.

Worked examples

Positive pre-activation — x = 2.0 (defaults)

  1. ReLU(2) = max(0, 2) = 2.000000
  2. Leaky ReLU(2) = 2.000000 (x > 0, so unchanged)
  3. GELU exact = 2·Φ(2) = 2 × 0.977250 = 1.954500
  4. SiLU = 2·σ(2) = 2 × 0.880797 = 1.761594
  5. Tanh(2) = 0.964028 ELU(2) = 2.000000

Negative pre-activation — x = −1.5 (see how each treats it)

  1. ReLU(−1.5) = max(0, −1.5) = 0.000000
  2. Leaky ReLU = 0.01 × (−1.5) = −0.015000
  3. GELU exact = −1.5·Φ(−1.5) = −1.5 × 0.066807 = −0.100211
  4. SiLU = −1.5·σ(−1.5) = −1.5 × 0.182426 = −0.273639
  5. ELU (α=1) = 1·(e⁻¹·⁵ − 1) = 0.223130 − 1 = −0.776870

Saturation / stability edge case — x = −1000

  1. ReLU(−1000) = 0 Leaky ReLU = 0.01 × (−1000) = −10.000000
  2. Tanh(−1000) = −1.000000 (fully saturated)
  3. SiLU = −1000·σ(−1000) = −1000 × 0 = 0.000000
  4. ELU (α=1) = 1·(e⁻¹⁰⁰⁰ − 1) = 0 − 1 = −1.000000 (floors at −α)
  5. No overflow or NaN — the stable sigmoid branch keeps exponents ≤ 0.

Frequently asked questions

Sources & references

The formulas on this page were last cross-checked against these papers and PyTorch on 2026-07-13. Activation functions are stable mathematical definitions, so this tool needs no rate or schedule updates — only the worked examples are periodically re-reconciled.

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.