獨熱編碼 (OneHot)

獨熱編碼 (OneHot) - 11

版本 (Version)

  • 名稱: OneHot (GitHub)

  • 網域: main

  • 起始版本: 11

  • 函式: False

  • 支援層級: SupportType.COMMON

  • 形狀推斷: True

此運算子的版本自版本 11 起可用。

摘要 (Summary)

根據輸入產生獨熱張量。由 ‘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 時:對於所有 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。

屬性 (Attributes)

  • axis - INT (預設為 '-1')

    (可選) 沿其新增獨熱表示的軸。預設值:axis=-1。 axis=-1 表示附加維度將作為輸出張量中最內層/最後的維度插入。負值表示從後面的維度開始計數。可接受的範圍是 [-r-1, r],其中 r = rank(indices)。

輸入 (Inputs)

  • 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’ 輸入張量中指定位置以外的值。

輸出 (Outputs)

  • output (異質) - T3

    等級比輸入張量 ‘indices’ 大一的張量,即 rank(output) = rank(indices) + 1。輸出張量元素的資料類型與使用之輸入 ‘values’ 的類型相同。

類型約束 (Type Constraints)

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

    將輸入限制為僅限數值類型。

  • T2 in ( 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

  • since_version: 9

  • 函式: False

  • 支援層級: SupportType.COMMON

  • 形狀推斷: True

此運算符版本自版本 9 起可用。

摘要

根據輸入產生 one-hot 張量。由「indices」輸入張量中的索引值表示的位置將具有「on_value」,而其他位置在輸出張量中將具有「off_value」,其中「on_value」和「off_value」指定為必需輸入參數「values」的一部分,該參數是一個格式為 [off_value, on_value] 的雙元素張量。輸出張量的階數將比輸入張量的階數大一。額外維度用於 one-hot 表示。額外維度將插入由「axis」指定的位置。如果未指定「axis」,則額外維度將插入為最內維度,即 axis=-1。額外維度的大小由必需的標量輸入「depth」指定。輸出張量的類型與「values」輸入的類型相同。「indices」輸入張量中任何超出範圍 [0, depth) 的值將導致輸出張量中所有值為「off_value」的 one-hot 表示。

屬性

  • axis - INT (預設為 '-1')

    (可選) 沿其新增 one-hot 表示的軸。預設值:axis=-1。axis=-1 表示額外維度將插入為輸出張量中最內/最後的維度。

輸入

  • indices (異質) - T1

    包含索引的輸入張量。這些值必須是非負整數。「indices」輸入張量中任何超出範圍 [0, depth) 的值將導致輸出 張量 中所有值為「off_value」的 one-hot 表示。如果「indices」為非整數類型,則在使用前將這些值轉換為 int64。

  • depth (異質) - T2

    包含恰好一個元素的純量或 1 階張量,指定 one-hot 張量中的類別數量。這也是輸出張量中新增的 one-hot 維度(由「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 in ( tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) )

    將輸入限制為僅限數值類型。

  • T2 in ( 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) )

    限制為任何張量類型。