LogSoftmax#
Domain:
ai.onnxSince version: 13
The operator computes the log of softmax values for the given input:
LogSoftmax(input, axis) = Log(Softmax(input, axis=axis))
The “axis” attribute indicates the dimension along which LogSoftmax will be performed. The output tensor has the same shape as the input tensor.
Inputs
input (T): The input tensor of rank >= axis.
Outputs
output (T): The output values with the same shape as the input tensor.
Attributes
axis (int): Describes the dimension Softmax will be performed on. Negative value means counting dimensions from the back.
Type Constraints
T: Constrain input and output types to float tensors. Allowed types: tensor(bfloat16), tensor(double), tensor(float), tensor(float16).
Examples#
test_cc_logsoftmax_axis_0
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = 0
Inputs:
input: shape=(2, 3), dtype=float32
[[ 1., 2., 3.],
[ 4., 1., -1.]]
Outputs:
output: shape=(2, 3), dtype=float32
[[-3.0485873 , -0.3132617 , -0.01814993],
[-0.04858735, -1.3132617 , -4.01815 ]]
test_cc_logsoftmax_axis_1
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = 1
Inputs:
input: shape=(2, 3), dtype=float32
[[ 1., 2., 3.],
[ 4., 1., -1.]]
Outputs:
output: shape=(2, 3), dtype=float32
[[-2.407606 , -1.4076059 , -0.40760595],
[-0.05498523, -3.0549853 , -5.054985 ]]
test_cc_logsoftmax_axis_2
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = 2
Inputs:
input: shape=(2, 2, 3), dtype=float32
[[[ 1. , 2. , 3. ],
[ 4. , 1. , -1. ]],
[[ 0.5, -0.5, 2. ],
[-2. , 1.5, 0. ]]]
Outputs:
output: shape=(2, 2, 3), dtype=float32
[[[-2.407606 , -1.4076059 , -0.40760595],
[-0.05498523, -3.0549853 , -5.054985 ]],
[[-1.7663679 , -2.766368 , -0.2663679 ],
[-3.725802 , -0.22580205, -1.7258021 ]]]
test_cc_logsoftmax_default_axis
Node:
LogSoftmax(input) -> (output)
Inputs:
input: shape=(2, 3), dtype=float32
[[ 1., 2., 3.],
[ 4., 1., -1.]]
Outputs:
output: shape=(2, 3), dtype=float32
[[-2.407606 , -1.4076059 , -0.40760595],
[-0.05498523, -3.0549853 , -5.054985 ]]
test_cc_logsoftmax_example_1
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = 1
Inputs:
input: shape=(2, 3), dtype=float32
[[1., 2., 3.],
[1., 2., 3.]]
Outputs:
output: shape=(2, 3), dtype=float32
[[-2.407606 , -1.4076059 , -0.40760595],
[-2.407606 , -1.4076059 , -0.40760595]]
test_cc_logsoftmax_large_number
Node:
LogSoftmax(input) -> (output)
Inputs:
input: shape=(2, 3), dtype=float32
[[1000., 1001., 1002.],
[1002., 1001., 1000.]]
Outputs:
output: shape=(2, 3), dtype=float32
[[-2.407606 , -1.4076059 , -0.40760595],
[-0.40760595, -1.4076059 , -2.407606 ]]
test_cc_logsoftmax_many_classes_bfloat16
Node:
LogSoftmax(input) -> (output)
Inputs:
input: shape=(1, 65536), dtype=bfloat16
[[0, 0, 0, ..., 0, 0, 0]]
Outputs:
output: shape=(1, 65536), dtype=bfloat16
[[-11.0625, -11.0625, -11.0625, ..., -11.0625, -11.0625, -11.0625]]
test_cc_logsoftmax_many_classes_float16
Node:
LogSoftmax(input) -> (output)
Inputs:
input: shape=(1, 65536), dtype=float16
[[0., 0., 0., ..., 0., 0., 0.]]
Outputs:
output: shape=(1, 65536), dtype=float16
[[-11.09, -11.09, -11.09, ..., -11.09, -11.09, -11.09]]
test_cc_logsoftmax_negative_axis
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = -1
Inputs:
input: shape=(2, 3), dtype=float32
[[ 1., 2., 3.],
[ 4., 1., -1.]]
Outputs:
output: shape=(2, 3), dtype=float32
[[-2.407606 , -1.4076059 , -0.40760595],
[-0.05498523, -3.0549853 , -5.054985 ]]
test_cc_reference_logsoftmax_empty_input
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = 1
Inputs:
input: shape=(0, 3), dtype=float32
[]
Outputs:
output: shape=(0, 3), dtype=float32
[]
test_cc_reference_logsoftmax_nonfinite
Node:
LogSoftmax(input) -> (output)
Inputs:
input: shape=(3, 2), dtype=float64
[[ inf, 0.],
[-inf, -inf],
[ nan, 0.]]
Outputs:
output: shape=(3, 2), dtype=float64
[[nan, nan],
[nan, nan],
[nan, nan]]
test_cc_reference_logsoftmax_single_class
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = 1
Inputs:
input: shape=(2, 1, 3), dtype=float32
[[[ 1., -2., 3.]],
[[ 4., 5., -6.]]]
Outputs:
output: shape=(2, 1, 3), dtype=float32
[[[0., 0., 0.]],
[[0., 0., 0.]]]
test_cc_reference_logsoftmax_small_log_probability_bfloat16_axis_-1
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = -1
Inputs:
input: shape=(2, 3, 3), dtype=bfloat16
[[[0, -18, -18],
[-18, 0, -18],
[-18, -18, 0]],
[[0, -18, -18],
[-18, 0, -18],
[-18, -18, 0]]]
Outputs:
output: shape=(2, 3, 3), dtype=bfloat16
[[[-3.05008e-08, -18, -18],
[-18, -3.05008e-08, -18],
[-18, -18, -3.05008e-08]],
[[-3.05008e-08, -18, -18],
[-18, -3.05008e-08, -18],
[-18, -18, -3.05008e-08]]]
test_cc_reference_logsoftmax_small_log_probability_bfloat16_axis_0
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = 0
Inputs:
input: shape=(3, 2, 3), dtype=bfloat16
[[[0, -18, -18],
[0, -18, -18]],
[[-18, 0, -18],
[-18, 0, -18]],
[[-18, -18, 0],
[-18, -18, 0]]]
Outputs:
output: shape=(3, 2, 3), dtype=bfloat16
[[[-3.05008e-08, -18, -18],
[-3.05008e-08, -18, -18]],
[[-18, -3.05008e-08, -18],
[-18, -3.05008e-08, -18]],
[[-18, -18, -3.05008e-08],
[-18, -18, -3.05008e-08]]]
test_cc_reference_logsoftmax_small_log_probability_bfloat16_axis_1
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = 1
Inputs:
input: shape=(2, 3, 3), dtype=bfloat16
[[[0, -18, -18],
[-18, 0, -18],
[-18, -18, 0]],
[[0, -18, -18],
[-18, 0, -18],
[-18, -18, 0]]]
Outputs:
output: shape=(2, 3, 3), dtype=bfloat16
[[[-3.05008e-08, -18, -18],
[-18, -3.05008e-08, -18],
[-18, -18, -3.05008e-08]],
[[-3.05008e-08, -18, -18],
[-18, -3.05008e-08, -18],
[-18, -18, -3.05008e-08]]]
test_cc_reference_logsoftmax_small_log_probability_float16_axis_-1
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = -1
Inputs:
input: shape=(2, 3, 3), dtype=float16
[[[ 0., -10., -10.],
[-10., 0., -10.],
[-10., -10., 0.]],
[[ 0., -10., -10.],
[-10., 0., -10.],
[-10., -10., 0.]]]
Outputs:
output: shape=(2, 3, 3), dtype=float16
[[[-9.08e-05, -1.00e+01, -1.00e+01],
[-1.00e+01, -9.08e-05, -1.00e+01],
[-1.00e+01, -1.00e+01, -9.08e-05]],
[[-9.08e-05, -1.00e+01, -1.00e+01],
[-1.00e+01, -9.08e-05, -1.00e+01],
[-1.00e+01, -1.00e+01, -9.08e-05]]]
test_cc_reference_logsoftmax_small_log_probability_float16_axis_0
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = 0
Inputs:
input: shape=(3, 2, 3), dtype=float16
[[[ 0., -10., -10.],
[ 0., -10., -10.]],
[[-10., 0., -10.],
[-10., 0., -10.]],
[[-10., -10., 0.],
[-10., -10., 0.]]]
Outputs:
output: shape=(3, 2, 3), dtype=float16
[[[-9.08e-05, -1.00e+01, -1.00e+01],
[-9.08e-05, -1.00e+01, -1.00e+01]],
[[-1.00e+01, -9.08e-05, -1.00e+01],
[-1.00e+01, -9.08e-05, -1.00e+01]],
[[-1.00e+01, -1.00e+01, -9.08e-05],
[-1.00e+01, -1.00e+01, -9.08e-05]]]
test_cc_reference_logsoftmax_small_log_probability_float16_axis_1
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = 1
Inputs:
input: shape=(2, 3, 3), dtype=float16
[[[ 0., -10., -10.],
[-10., 0., -10.],
[-10., -10., 0.]],
[[ 0., -10., -10.],
[-10., 0., -10.],
[-10., -10., 0.]]]
Outputs:
output: shape=(2, 3, 3), dtype=float16
[[[-9.08e-05, -1.00e+01, -1.00e+01],
[-1.00e+01, -9.08e-05, -1.00e+01],
[-1.00e+01, -1.00e+01, -9.08e-05]],
[[-9.08e-05, -1.00e+01, -1.00e+01],
[-1.00e+01, -9.08e-05, -1.00e+01],
[-1.00e+01, -1.00e+01, -9.08e-05]]]
test_cc_reference_logsoftmax_small_log_probability_float32_axis_-1
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = -1
Inputs:
input: shape=(2, 3, 3), dtype=float32
[[[ 0., -18., -18.],
[-18., 0., -18.],
[-18., -18., 0.]],
[[ 0., -18., -18.],
[-18., 0., -18.],
[-18., -18., 0.]]]
Outputs:
output: shape=(2, 3, 3), dtype=float32
[[[-3.0459958e-08, -1.8000000e+01, -1.8000000e+01],
[-1.8000000e+01, -3.0459958e-08, -1.8000000e+01],
[-1.8000000e+01, -1.8000000e+01, -3.0459958e-08]],
[[-3.0459958e-08, -1.8000000e+01, -1.8000000e+01],
[-1.8000000e+01, -3.0459958e-08, -1.8000000e+01],
[-1.8000000e+01, -1.8000000e+01, -3.0459958e-08]]]
test_cc_reference_logsoftmax_small_log_probability_float32_axis_0
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = 0
Inputs:
input: shape=(3, 2, 3), dtype=float32
[[[ 0., -18., -18.],
[ 0., -18., -18.]],
[[-18., 0., -18.],
[-18., 0., -18.]],
[[-18., -18., 0.],
[-18., -18., 0.]]]
Outputs:
output: shape=(3, 2, 3), dtype=float32
[[[-3.0459958e-08, -1.8000000e+01, -1.8000000e+01],
[-3.0459958e-08, -1.8000000e+01, -1.8000000e+01]],
[[-1.8000000e+01, -3.0459958e-08, -1.8000000e+01],
[-1.8000000e+01, -3.0459958e-08, -1.8000000e+01]],
[[-1.8000000e+01, -1.8000000e+01, -3.0459958e-08],
[-1.8000000e+01, -1.8000000e+01, -3.0459958e-08]]]
test_cc_reference_logsoftmax_small_log_probability_float32_axis_1
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = 1
Inputs:
input: shape=(2, 3, 3), dtype=float32
[[[ 0., -18., -18.],
[-18., 0., -18.],
[-18., -18., 0.]],
[[ 0., -18., -18.],
[-18., 0., -18.],
[-18., -18., 0.]]]
Outputs:
output: shape=(2, 3, 3), dtype=float32
[[[-3.0459958e-08, -1.8000000e+01, -1.8000000e+01],
[-1.8000000e+01, -3.0459958e-08, -1.8000000e+01],
[-1.8000000e+01, -1.8000000e+01, -3.0459958e-08]],
[[-3.0459958e-08, -1.8000000e+01, -1.8000000e+01],
[-1.8000000e+01, -3.0459958e-08, -1.8000000e+01],
[-1.8000000e+01, -1.8000000e+01, -3.0459958e-08]]]
test_cc_reference_logsoftmax_small_log_probability_float64_axis_-1
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = -1
Inputs:
input: shape=(2, 3, 3), dtype=float64
[[[ 0., -40., -40.],
[-40., 0., -40.],
[-40., -40., 0.]],
[[ 0., -40., -40.],
[-40., 0., -40.],
[-40., -40., 0.]]]
Outputs:
output: shape=(2, 3, 3), dtype=float64
[[[-8.49670851e-18, -4.00000000e+01, -4.00000000e+01],
[-4.00000000e+01, -8.49670851e-18, -4.00000000e+01],
[-4.00000000e+01, -4.00000000e+01, -8.49670851e-18]],
[[-8.49670851e-18, -4.00000000e+01, -4.00000000e+01],
[-4.00000000e+01, -8.49670851e-18, -4.00000000e+01],
[-4.00000000e+01, -4.00000000e+01, -8.49670851e-18]]]
test_cc_reference_logsoftmax_small_log_probability_float64_axis_0
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = 0
Inputs:
input: shape=(3, 2, 3), dtype=float64
[[[ 0., -40., -40.],
[ 0., -40., -40.]],
[[-40., 0., -40.],
[-40., 0., -40.]],
[[-40., -40., 0.],
[-40., -40., 0.]]]
Outputs:
output: shape=(3, 2, 3), dtype=float64
[[[-8.49670851e-18, -4.00000000e+01, -4.00000000e+01],
[-8.49670851e-18, -4.00000000e+01, -4.00000000e+01]],
[[-4.00000000e+01, -8.49670851e-18, -4.00000000e+01],
[-4.00000000e+01, -8.49670851e-18, -4.00000000e+01]],
[[-4.00000000e+01, -4.00000000e+01, -8.49670851e-18],
[-4.00000000e+01, -4.00000000e+01, -8.49670851e-18]]]
test_cc_reference_logsoftmax_small_log_probability_float64_axis_1
Node:
LogSoftmax(input) -> (output)
Attributes:
axis = 1
Inputs:
input: shape=(2, 3, 3), dtype=float64
[[[ 0., -40., -40.],
[-40., 0., -40.],
[-40., -40., 0.]],
[[ 0., -40., -40.],
[-40., 0., -40.],
[-40., -40., 0.]]]
Outputs:
output: shape=(2, 3, 3), dtype=float64
[[[-8.49670851e-18, -4.00000000e+01, -4.00000000e+01],
[-4.00000000e+01, -8.49670851e-18, -4.00000000e+01],
[-4.00000000e+01, -4.00000000e+01, -8.49670851e-18]],
[[-8.49670851e-18, -4.00000000e+01, -4.00000000e+01],
[-4.00000000e+01, -8.49670851e-18, -4.00000000e+01],
[-4.00000000e+01, -4.00000000e+01, -8.49670851e-18]]]
test_cc_reference_logsoftmax_tied_maxima
Node:
LogSoftmax(input) -> (output)
Inputs:
input: shape=(3, 3), dtype=float64
[[ 0., 0., -200.],
[ 4., 4., 4.],
[ 0., -inf, -inf]]
Outputs:
output: shape=(3, 3), dtype=float64
[[ -0.69314718, -0.69314718, -200.69314718],
[ -1.09861229, -1.09861229, -1.09861229],
[ 0. , -inf, -inf]]
Differences with previous version (11)#
SchemaDiff: LogSoftmax (domain 'ai.onnx')
old version: 11
new version: 13
breaking: yes
Breaking reasons:
attribute ‘axis’ (changed): default value changed 1 -> -1
Attributes:
[BREAKING] changed ‘axis’: default value changed 1 -> -1
Type constraints:
changed ‘T’: added types: [‘tensor(bfloat16)’]
Documentation:
line similarity: 0.18 (+6/-3 lines)
--- LogSoftmax v11
+++ LogSoftmax v13
@@ -1,4 +1,7 @@
-The operator computes the logsoftmax (log of softmax) values for the given input.
-The "axis" attribute indicates the dimension along which LogSoftmax is
-performed. The output tensor has the same shape as the input tensor.
+The operator computes the log of softmax values for the given input:
+
+ LogSoftmax(input, axis) = Log(Softmax(input, axis=axis))
+
+The "axis" attribute indicates the dimension along which LogSoftmax
+will be performed. The output tensor has the same shape as the input tensor.