Skip to main content

ClikaRT::ops::log_softmax

function

log_softmax()

Tensor log_softmax(
    Tensor x,
    int64_t dim = -1,
    DataType dtype = DataType::Undefined
)

Logarithm of the softmax along dim, computed stably (never log(softmax(x)) in two passes).

log_softmax(x)i=ximaxjxjlog ⁣jexjmaxkxkalong dim\mathrm{log\_softmax}(x)_i = x_i - \max_j x_j - \log\!\sum_j e^{\,x_j - \max_k x_k} \quad \text{along } \mathit{dim}

Parameters

  • x: the input tensor.
  • dim: the reduction dimension. Negative counts from the end. Default -1.
  • dtype: output dtype; DataType::Undefined (default) keeps x's.

Throws

  • ClikaRT::Error: when dim is out of range, or when the dtype pair is not served (code_name() carries the reason).

Returns: same shape as x; dtype = dtype when set, else x's.

auto lp = ClikaRT::ops::log_softmax(logits, -1);

Declared in ClikaRT/compute/ops.h, line 918