OneHot

OneHot - 11

版本

  • 名称: OneHot (GitHub)

  • : main

  • 起始版本: 11

  • 函数: False

  • 支持级别: SupportType.COMMON

  • 形状推断: True

此版本的运算符自 版本 11 起可用。

摘要

根据输入生成独热张量。在输出张量中,由“indices”输入张量中的索引值表示的位置将具有“on_value”,而其他位置将具有“off_value”。“on_value”和“off_value”作为必需输入参数“values”的一部分指定,该参数是一个两元素张量,格式为 [off_value, on_value]。输出张量的秩将比输入张量的秩大一。附加维度用于独热表示。附加维度将插入到“axis”指定的位置。如果未指定“axis”,则附加维度将作为最内层维度插入,即 axis=-1。附加维度的大小由必需的标量输入“depth”指定。输出张量的类型与“values”输入的类型相同。“indices”输入张量中值超出范围 [-depth, depth-1] 的任何条目都将导致输出张量中所有“off_value”值的独热表示。

当 axis = 0 时:output[input[i, j, k], i, j, k] = 1 对于所有 i, j, k,否则为 0。

当 axis = -1 时:output[i, j, k, input[i, j, k]] = 1 对于所有 i, j, k,否则为 0。

属性

  • 轴 - INT(默认值为 '-1'

    (可选) 独热表示添加的轴。默认值:axis=-1。axis=-1 表示附加维度将作为输出张量中最内层/最后一个维度插入。负值表示从后向前计算维度。接受的范围是 [-r-1, r],其中 r = rank(indices)。

输入

  • indices (异构) - T1

    包含索引的输入张量。在输出张量中,'indices'输入张量中值超出范围[-depth, depth-1]的任何条目都将导致所有'off_value'值的独热表示。如果'indices'是非整数类型,则在使用前会将其转换为int64。

  • depth (异构) - T2

    标量或秩为 1 的张量,仅包含一个元素,指定独热张量中的类别数量。这也是输出张量中添加的独热维度(由“axis”属性指定)的大小。“indices”输入张量中的值预期在范围 [-depth, depth-1] 内。如果“depth”是非整数类型,则在使用前会将其转换为 int64。

  • values (异构) - T3

    秩为 1 的张量,包含两个元素,格式为 [off_value, on_value],其中“on_value”用于填充“indices”输入张量中指定的位置,“off_value”用于填充“indices”输入张量中指定位置以外的位置。

输出

  • output (异构) - T3

    输出张量的秩比输入张量“indices”大一,即 rank(output) = rank(indices) + 1。输出张量元素的类型与输入“values”的类型相同。

类型约束

  • T1 在 ( tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) )

    将输入限制为仅数值类型。

  • T2 在 ( tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) )

    将输入限制为仅数值类型。

  • T3 在 ( tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) )

    限制为任何张量类型。

OneHot - 9

版本

  • 名称: OneHot (GitHub)

  • : main

  • 起始版本: 9

  • 函数: False

  • 支持级别: SupportType.COMMON

  • 形状推断: True

此版本的运算符自 版本 9 起可用。

摘要

根据输入生成独热张量。输出张量中,由“indices”输入张量中的索引值表示的位置将具有“on_value”,而其他位置将具有“off_value”,其中“on_value”和“off_value”作为必需输入参数“values”的一部分指定,该参数是一个两元素张量,格式为 [off_value, on_value]。输出张量的秩将比输入张量的秩大一。附加维度用于独热表示。附加维度将插入到“axis”指定的位置。如果未指定“axis”,则附加维度将作为最内层维度插入,即 axis=-1。附加维度的大小由必需的标量输入“depth”指定。输出张量的类型与“values”输入的类型相同。“indices”输入张量中值超出范围 [0, depth) 的任何条目都将导致输出张量中所有“off_value”值的独热表示。

属性

  • 轴 - INT(默认值为 '-1'

    (可选) 独热表示添加的轴。默认值:axis=-1。axis=-1 表示附加维度将作为输出张量中最内层/最后一个维度插入。

输入

  • indices (异构) - T1

    包含索引的输入张量。值必须是非负整数。在输出张量中,'indices'输入张量中值超出范围[0, depth)的任何条目都将导致所有'off_value'值的独热表示。如果'indices'是非整数类型,则在使用前会将其转换为int64。

  • depth (异构) - T2

    标量或秩为 1 的张量,仅包含一个元素,指定独热张量中的类别数量。这也是输出张量中添加的独热维度(由“axis”属性指定)的大小。“indices”输入张量中的值预期在范围 [0, depth) 内。如果“depth”是非整数类型,则在使用前会将其转换为 int64。

  • values (异构) - T3

    秩为 1 的张量,包含两个元素,格式为 [off_value, on_value],其中“on_value”用于填充“indices”输入张量中指定的位置,“off_value”用于填充“indices”输入张量中指定位置以外的位置。

输出

  • output (异构) - T3

    输出张量的秩比输入张量“indices”大一,即 rank(output) = rank(indices) + 1。输出张量元素的类型与输入“values”的类型相同。

类型约束

  • T1 在 ( tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) )

    将输入限制为仅数值类型。

  • T2 在 ( tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) )

    将输入限制为仅数值类型。

  • T3 在 ( tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) )

    限制为任何张量类型。