beetlebug▾
/

ztcl::tensor logsoftmax

Gives the log of the softmax of each row of a matrix.

ztcl::tensor logsoftmax TENSOR

Description

Gives x - max - log(sum(exp(x - max))) for each row of a float matrix. The shift by the maximum keeps it finite for large values.

Returns

A tensor.

Examples

Each example of this page runs after package require ztcl::tensor.

% ztcl::tensor logsoftmax [ztcl::tensor of {{1 2}} -dtype f64]
tensor f64 {1 2} {-1.3132616875182228 -0.31326168751822286}

Errors

% ztcl::tensor logsoftmax [ztcl::tensor ones {2 2} i32]
tensor logsoftmax: the operation needs a float dtype
-errorcode ZTCL TENSOR

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.4
Compute cost
A cost for each element operation by its kind (a copy, an add, a division, a math function, a multiply-add of a matmul), set so that one compute unit takes about the time of one unit of plain Tcl. docs/modules/tensor.md has the table.