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.31326175, -0.01814985],
[-0.04858732, -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.4076059 ],
[-0.05498505, -3.054985 , -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.4076059 ],
[-0.05498505, -3.054985 , -5.054985 ]],
[[-1.7663679 , -2.766368 , -0.2663679 ],
[-3.725802 , -0.22580206, -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.4076059 ],
[-0.05498505, -3.054985 , -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.4076059],
[-2.407606 , -1.4076059, -0.4076059]]
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.4075928 , -1.4075928 , -0.40759277],
[-0.40759277, -1.4075928 , -2.4075928 ]]
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.4076059 ],
[-0.05498505, -3.054985 , -5.054985 ]]
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.