Skip to content
fn

log_softmax_op

→TensorImplPtr
int log_softmax_op(const int & a, int axis)

Python wrappers

Public Python APIs implemented by this engine symbols.

Numerically stable log-softmax y=x−logsumexp(x,axis)y = x - \mathrm{logsumexp}(x, \text{axis}).

See Also

softmax_op : Probability-domain variant. LogSoftmaxBackward : Autograd node implementing the gradient rule.

Parameters

aTensorImplPtr
Input logits.
axisint
Axis along which to normalise. Negative values count from the end.

Returns

TensorImplPtr

Log-softmax output with the same shape and dtype as a.

Notes

Prefer log_softmax_op followed by nll_loss over log(softmax_op(...)) followed by nll_loss — the former is numerically stable for very confident logits, the latter is not.