Skip to content
class

SoftmaxTransform

extendsTransform
SoftmaxTransform()

Softmax transform mapping RK→ΔK−1\mathbb{R}^K \to \Delta^{K-1}.

Pushes an unconstrained vector x∈RK\mathbf{x} \in \mathbb{R}^K onto the open KK-simplex via y=softmax(x)\mathbf{y} = \mathrm{softmax}(\mathbf{x}). Operates on the last axis; event_dim = 1.

The transform is over-parameterised: any constant shift along the softmax axis (x→x+c1\mathbf{x} \to \mathbf{x} + c\mathbf{1}) yields the same y\mathbf{y}, so it is not a true bijection. The standard convention used here is to anchor the inverse at x=log⁡y\mathbf{x} = \log \mathbf{y} (un-normalised log-probabilities), which is one canonical preimage.

Notes

Forward:

yk=exk∑j=1Kexjy_k = \frac{e^{x_k}}{\sum_{j=1}^{K} e^{x_j}}

Inverse (canonical anchor):

xk=log⁡ykx_k = \log y_k

There is no log-determinant: the map is not injective, so it has no Jacobian determinant and log_abs_det_jacobian raises NotImplementedError, as in the reference. A density through SoftmaxTransform is therefore not defined; for a true bijection between RK−1\mathbb{R}^{K-1} and the simplex use StickBreakingTransform instead.

Examples

>>> import lucid
>>> from lucid.distributions.transforms import SoftmaxTransform
>>> T = SoftmaxTransform()
>>> T(lucid.tensor([0.0, 1.0, 2.0]))
tensor([0.09003, 0.2447, 0.6652])

Used by 2