ai.onnx.ml - LabelEncoder#

LabelEncoder - 2 (ai.onnx.ml)#

Version

  • name: LabelEncoder (GitHub)

  • domain: ai.onnx.ml

  • since_version: 2

  • function: False

  • support_level: SupportType.COMMON

  • shape inference: True

This version of the operator has been available since version 2 of domain ai.onnx.ml.

Summary

Maps each element in the input tensor to another value.

The mapping is determined by the two parallel attributes, ‘keys_*’ and ‘values_*’ attribute. The i-th value in the specified ‘keys_*’ attribute would be mapped to the i-th value in the specified ‘values_*’ attribute. It implies that input’s element type and the element type of the specified ‘keys_*’ should be identical while the output type is identical to the specified ‘values_*’ attribute. If an input element can not be found in the specified ‘keys_*’ attribute, the ‘default_*’ that matches the specified ‘values_*’ attribute may be used as its output value.

Let’s consider an example which maps a string tensor to an integer tensor. Assume and ‘keys_strings’ is [“Amy”, “Sally”], ‘values_int64s’ is [5, 6], and ‘default_int64’ is ‘-1’. The input [“Dori”, “Amy”, “Amy”, “Sally”, “Sally”] would be mapped to [-1, 5, 5, 6, 6].

Since this operator is an one-to-one mapping, its input and output shapes are the same. Notice that only one of ‘keys_*’/’values_*’ can be set.

For key look-up, bit-wise comparison is used so even a float NaN can be mapped to a value in ‘values_*’ attribute.

Attributes

  • default_float: A float. Default value is -0.0.

  • default_int64: An integer. Default value is -1.

  • default_string: A string. Default value is '_Unused'.

  • keys_floats: A list of floats.

  • keys_int64s: A list of ints.

  • keys_strings: A list of strings. One and only one of ‘keys_*’s should be set.

  • values_floats: A list of floats.

  • values_int64s: A list of ints.

  • values_strings: A list of strings. One and only one of ‘value_*’s should be set.

Inputs

  • X (heterogeneous) - T1: Input data. It can be either tensor or scalar.

Outputs

  • Y (heterogeneous) - T2: Output data.

Type Constraints

  • T1 in ( tensor(float), tensor(int64), tensor(string) ): The input type is a tensor of any shape.

  • T2 in ( tensor(float), tensor(int64), tensor(string) ): Output type is determined by the specified ‘values_*’ attribute.

Examples

Differences

0Maps each element in the input tensor to another value.
1
2The mapping is determined by the two parallel attributes, 'keys_*' and
3'values_*' attribute. The i-th value in the specified 'keys_*' attribute
4would be mapped to the i-th value in the specified 'values_*' attribute. It
5implies that input's element type and the element type of the specified
6'keys_*' should be identical while the output type is identical to the
7specified 'values_*' attribute. If an input element can not be found in the
8specified 'keys_*' attribute, the 'default_*' that matches the specified
9'values_*' attribute may be used as its output value.
10
11Let's consider an example which maps a string tensor to an integer tensor.
12Assume and 'keys_strings' is ["Amy", "Sally"], 'values_int64s' is [5, 6],
13and 'default_int64' is '-1'. The input ["Dori", "Amy", "Amy", "Sally",
14"Sally"] would be mapped to [-1, 5, 5, 6, 6].
15
16Since this operator is an one-to-one mapping, its input and output shapes
17are the same. Notice that only one of 'keys_*'/'values_*' can be set.
18
19For key look-up, bit-wise comparison is used so even a float NaN can be
20mapped to a value in 'values_*' attribute.
21
022Converts strings to integers and vice versa.**Attributes**
123
224If the string default value is set, it will convert integers to strings.* **default_float**:
325If the int default value is set, it will convert strings to integers. A float. Default value is -0.0.
4
526Each operator converts either integers to strings or strings to integers, depending* **default_int64**:
627on which default value attribute is provided. Only one default value attribute An integer. Default value is -1.
7should be defined.
8
928When converting from integers to strings, the string is fetched from the* **default_string**:
10'classes_strings' list, by simple indexing.
11
1229When converting from strings to integers, the string is looked up in the list A string. Default value is '_Unused'.
1330and the index at which it is found is used as the converted value.* **keys_floats**:
14
15**Attributes**
16
17* **classes_strings**:
1831 A list of labels. A list of floats.
1932* **default_int64**:* **keys_int64s**:
2033 An integer to use when an input string value is not found in the A list of ints.
2134 map.<br>One and only one of the 'default_*' attributes must be* **keys_strings**:
2235 defined. Default value is -1. A list of strings. One and only one of 'keys_*'s should be set.
2336* **default_string**:* **values_floats**:
2437 A string to use when an input integer value is not found in the A list of floats.
2538 map.<br>One and only one of the 'default_*' attributes must be* **values_int64s**:
2639 defined. Default value is '_Unused'. A list of ints.
40* **values_strings**:
41 A list of strings. One and only one of 'value_*'s should be set.
2742
2843**Inputs****Inputs**
2944
3045* **X** (heterogeneous) - **T1**:* **X** (heterogeneous) - **T1**:
3146 Input data. Input data. It can be either tensor or scalar.
3247
3348**Outputs****Outputs**
3449
3550* **Y** (heterogeneous) - **T2**:* **Y** (heterogeneous) - **T2**:
3651 Output data. If strings are input, the output values are integers, Output data.
37 and vice versa.
3852
3953**Type Constraints****Type Constraints**
4054
4155* **T1** in (* **T1** in (
56 tensor(float),
4257 tensor(int64), tensor(int64),
4358 tensor(string) tensor(string)
4459 ): ):
4560 The input type must be a tensor of integers or strings, of any The input type is a tensor of any shape.
46 shape.
4761* **T2** in (* **T2** in (
4862 tensor(int64), tensor(float),
49 tensor(string)
50 ):
5163 The output type will be a tensor of strings or integers, and will tensor(int64),
5264 have the same shape as the input. tensor(string)
65 ):
66 Output type is determined by the specified 'values_*' attribute.

LabelEncoder - 1 (ai.onnx.ml)#

Version

  • name: LabelEncoder (GitHub)

  • domain: ai.onnx.ml

  • since_version: 1

  • function: False

  • support_level: SupportType.COMMON

  • shape inference: True

This version of the operator has been available since version 1 of domain ai.onnx.ml.

Summary

Converts strings to integers and vice versa.

If the string default value is set, it will convert integers to strings. If the int default value is set, it will convert strings to integers.

Each operator converts either integers to strings or strings to integers, depending on which default value attribute is provided. Only one default value attribute should be defined.

When converting from integers to strings, the string is fetched from the ‘classes_strings’ list, by simple indexing.

When converting from strings to integers, the string is looked up in the list and the index at which it is found is used as the converted value.

Attributes

  • classes_strings: A list of labels.

  • default_int64: An integer to use when an input string value is not found in the map.<br>One and only one of the ‘default_*’ attributes must be defined. Default value is -1.

  • default_string: A string to use when an input integer value is not found in the map.<br>One and only one of the ‘default_*’ attributes must be defined. Default value is '_Unused'.

Inputs

  • X (heterogeneous) - T1: Input data.

Outputs

  • Y (heterogeneous) - T2: Output data. If strings are input, the output values are integers, and vice versa.

Type Constraints

  • T1 in ( tensor(int64), tensor(string) ): The input type must be a tensor of integers or strings, of any shape.

  • T2 in ( tensor(int64), tensor(string) ): The output type will be a tensor of strings or integers, and will have the same shape as the input.