DML_ACTIVATION_LOG_SOFTMAX1_OPERATOR_DESC 结构 (directml.h)

InputTensor 的每个元素执行自然 log-of-softmax 激活函数,将结果放入 OutputTensor 的相应元素中。

For 1-D InputTensor:
// Let x[i] to be the current element in the InputTensor, and j be the total number of elements in the InputTensor
f(x[i]) = ln(exp(x[i]) / sum(exp(x[0]), ..., exp(x[j-1])))

其中 exp(x) 是自然指数函数,ln(x) 是自然对数。

重要

此 API 作为 DirectML 独立可再发行组件包的一部分提供(请参阅 Microsoft.AI.DirectML 版本 1.9 及更高版本。 另请参阅 DirectML 版本历史记录

语法

struct DML_ACTIVATION_LOG_SOFTMAX1_OPERATOR_DESC
{
    const DML_TENSOR_DESC* InputTensor;
    const DML_TENSOR_DESC* OutputTensor;
    UINT AxisCount;
    _Field_size_(AxisCount) const UINT* Axes;
};

成员

InputTensor

类型:const DML_TENSOR_DESC*

要从中读取数据的输入张量。

OutputTensor

类型:const DML_TENSOR_DESC*

要向其写入结果的输出张量。

AxisCount

类型:UINT

要计算减少总和的轴数。 此字段确定 Axes 数组的大小。

Axes

类型:_Field_size_(AxisCount) const UINT*

要减少总和的轴。 值必须在 [0, InputTensor.DimensionCount - 1] 范围内。

示例

以下示例均使用相同的三维输入张量:

InputTensor: (Sizes:{2, 2, 2}, DataType:FLOAT32)
[
    [
        [  12, 0],
        [-101, 11],
    ],
    [
        [  3,  234],
        [  0, -101],
    ]
]

示例 1

AxisCount: 1
Axes: {1}
OutputTensor: (Sizes:{2, 2, 2}, DataType:FLOAT32)
[
    [               // max element in {12, -101} is 12 and in {0, 11} is 11
        [1, 0],
        [0, 1],
    ],
    [               // max element in {3, 0} is 3 and in {234, -101} is 234
        [1, 1],
        [0, 0],
    ]
]

示例 2

AxisCount: 1
Axes: {0}
OutputTensor: (Sizes:{2, 2, 2}, DataType:FLOAT32)
[
    [               // max element in {12, 3} is 12, in {0, 234} is 234, in {-101, 0} is 0 and in {11, -101} is 11
        [1, 0],
        [0, 1],
    ],
    [
        [0, 1],
        [1, 0],
    ]
]

示例 3

AxisCount: 2
Axes: {0, 2}
OutputTensor: (Sizes:{2, 2, 2}, DataType:FLOAT32)
[
    [               // max element in {12, 0, 3, 234} is 234 and in {-101, 11, 0, -101} is 11
        [0, 0],
        [0, 1],
    ],
    [
        [0, 1],
        [0, 0],
    ]
]

注解

AxisCount == 1 且 Axes == {DimensionCount - 1} 时,此运算符等效于 DML_ACTIVATION_LOG_SOFTMAX_OPERATOR_DESC

可用性

此运算符是在 DML_FEATURE_LEVEL_5_1 中引入的。

张量约束

InputTensorOutputTensor 必须具有相同的 DataTypeDimensionCountSizes

张量支持

张量 种类 支持的维度计数 支持的数据类型
InputTensor 输入 1 到 8 FLOAT32、FLOAT16
OutputTensor 输出 1 到 8 FLOAT32、FLOAT16

要求

   
页眉 directml.h

另请参阅