Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Module

keras.activations

keras.activations provides built-in nonlinear and linear functions for transforming tensors. Use them directly, pass them to layer activation arguments, or select built-ins by string name.

How it works

The module provides callable activation functions for transforming tensor values. Use a function directly, pass it to a layer's activation argument, or refer to a built-in function by its string identifier; most functions preserve the input shape and dtype.

Syntax

keras.activations.<name>(x, ...)

Parameters

NameTypeDescription
xTensorInput tensor or tensor-like value to transform.
negative_slopefloatNegative slope used by ReLU for values below its threshold.
max_valuefloat or NoneOptional upper bound for ReLU outputs.
thresholdfloatThreshold used by ReLU.
axisintAxis along which softmax is computed.

Returns

Each activation returns a tensor containing the transformed values; the documentation specifies that an activation callable should return a tensor of the same shape and dtype as its input.

Key points

  • Use an activation either as a standalone Activation layer or through a forward layer's activation argument.
  • Built-in functions can be selected by names such as "relu" instead of passing the callable.
  • ReLU accepts controls for negative slope, an optional maximum output, and a threshold.
  • Softmax normalizes along a configurable axis, defaulting to the final axis.
  • Sigmoid maps inputs using the standard logistic formula.
  • GLU splits its input conceptually into two parts and gates one part with the sigmoid of the other.

Example: Apply ReLU directly

import keras
from keras import activations

x = keras.ops.array([-2.0, 0.0, 3.0])
y = activations.relu(x)
print(y)

Applies the built-in ReLU function directly to a tensor-like value.

When to use it

Direct tensor transformation

Add nonlinear behavior inside a model while retaining explicit control over the function.

Layer activation argument

Configure a Dense or other forward layer concisely.

Softmax output transformation

Normalize class scores into values that form a distribution along a chosen dimension.

Custom activation integration

Define custom model logic using the same callable activation interface as built-ins.

Interview questions

QHow are Keras activation functions used?

Keras activations are callable functions such as relu, sigmoid, and softmax. They can be called directly or supplied to a layer through its activation argument.

Follow-up: How can a built-in activation be configured without passing the function object? Use its string identifier, such as "relu".

QWhat controls the behavior of keras.activations.relu?

ReLU uses configurable negative_slope, max_value, and threshold arguments. With defaults, it behaves as the element-wise maximum of zero and the input.

Follow-up: What does changing threshold do? It changes the point at which the rectifying behavior is applied, while the other parameters can control negative slope and output capping.

QWhat does softmax do, and what is its key parameter?

Softmax converts values into a probability distribution along the selected axis. Its axis argument defaults to the last axis, so multidimensional inputs can choose which dimension is normalized.

Follow-up: When would another activation be preferable? Use an activation whose output behavior matches the task, such as sigmoid for scalar bounded outputs or a linear function when no nonlinear transformation is wanted.

  • keras.layers.Activation
  • keras.layers.Dense
  • keras.activations.celu
  • keras.activations.elu
  • keras.activations.gelu
  • keras.activations.glu
  • keras.activations.relu
  • keras.activations.selu

Source: Layer activation functions - Keras. Checked 2026-10-15.