Implementing kernel
C++ engine symbols that back this Python API.Apply the softmax function along a dimension.
Parameters
inputTensorInput tensor of any shape (the "logits").
dimint or NoneDimension along which softmax is computed.
_stacklevelintInternal stack level for the implicit-dimension warning.
dtypeDTypeLike or NoneTarget floating-point dtype to cast
input to before softmax.Returns
TensorSame-shape tensor whose entries along dim sum to 1.
Notes
The engine uses the log-sum-exp shift .
For loss computation, prefer log_softmax followed by nll_loss.
Examples
>>> import lucid
>>> from lucid.nn.functional import softmax
>>> logits = lucid.tensor([[1.0, 2.0, 3.0]])
>>> p = softmax(logits, dim=1)
>>> p
tensor([[0.09003, 0.2447, 0.6652]])
>>> p.sum(dim=1)
tensor([1.])