OneHot

OneHot - 11

版本

  • 名称: OneHot (GitHub)

  • : main

  • 起始版本: 11

  • 函数: False

  • 支持级别: SupportType.COMMON

  • 形状推断: True

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

摘要

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

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

当 axis = -1 时:对于所有 i, j, k,output[i, j, k, input[i, j, k]] = 1,否则为 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。输出张量元素的D数据类型与输入“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 起可用。

摘要

根据输入生成一个独热(one-hot)张量。输出张量中,由“indices”输入张量中的索引值表示的位置将为“on_value”,其他位置将为“off_value”。其中,“on_value”和“off_value”作为必需输入参数“values”的一部分指定,“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。输出张量元素的D数据类型与输入“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) )

    限制为任何张量类型。