Skip to content

softmax

Module: strata.utils • Kind: function
Source: strata/utils/math.mojo

def softmax[dtype: DType = DType.float64](
x: List[Scalar[dtype]],
) -> List[Scalar[dtype]]
from strata.utils import softmax

Compute numerically stable softmax probability distribution.

Softmax(x)i=exi−max⁡(x)∑jexj−max⁡(x)\text{Softmax}(x)_i = \frac{e^{x_i - \max(x)}}{\sum_j e^{x_j - \max(x)}}

Returns: List[Scalar[dtype]] — List[Scalar[dtype]]: Normalized probability distribution vector summing to 1.0.