Classification probabilities
Use as the final transformation for single-label multi-class predictions.
Keras · Class
A Keras layer that converts logits into normalized softmax values along one or more selected axes. It supports an optional broadcastable mask for excluding positions.
Softmax normalizes logits along the configured axis. It subtracts the maximum value for numerical stability, exponentiates the shifted values, and divides each by their sum; an optional mask can exclude selected positions before normalization.
keras.layers.Softmax(axis=-1, **kwargs)| Name | Type | Description |
|---|---|---|
axis | int | list[int] | Integer or list of integers specifying the axis or axes used for softmax normalization. |
**kwargs | keyword arguments | Additional base-layer keyword arguments, including options such as name and dtype. |
inputs | tensor | Input logits to the layer. |
mask | boolean tensor | None | Optional boolean mask broadcastable to inputs; 1 keeps a position and 0 masks it. |
Softmaxed output with the same shape as inputs.
keras.layers.Softmax is a layer form of the softmax activation.axis setting determines the dimension or dimensions over which normalization occurs.import keras
import numpy as np
layer = keras.layers.Softmax(axis=-1)
logits = np.array([[1.0, 2.0, 1.0]])
print(layer(logits).numpy())
Creates a softmax layer and normalizes each row of the logits into class probabilities.
Use as the final transformation for single-label multi-class predictions.
Normalize scores across a selected feature, spatial, or sequence dimension.
Exclude padding or invalid positions before computing a distribution.
Softmax converts logits into normalized values by exponentiating values after subtracting the maximum, then dividing by their sum. The normalization is performed along the configured axis.
Follow-up: What does the layer return shape-wise? It returns a tensor with the same shape as its input.
The default axis is -1, so normalization is applied along the final dimension. The axis may also be an integer list when normalization must cover multiple dimensions.
Follow-up: How would you normalize channels rather than the final dimension? Pass the desired channel axis explicitly when constructing the layer.
The call accepts an optional boolean mask that is broadcastable to the inputs. A mask keeps positions marked with 1 and masks positions marked with 0.
Follow-up: What constraint must the mask satisfy? Each mask dimension must be 1 or match the corresponding input dimension, and cannot be larger.
keras.activations.softmaxkeras.layers.Activationkeras.layers.Dense