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
0 | Maps each element in the input tensor to another value. | ||
1 |
| ||
2 | The mapping is determined by the two parallel attributes, 'keys_*' and | ||
3 | 'values_*' attribute. The i-th value in the specified 'keys_*' attribute | ||
4 | would be mapped to the i-th value in the specified 'values_*' attribute. It | ||
5 | implies 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 | ||
7 | specified 'values_*' attribute. If an input element can not be found in the | ||
8 | specified 'keys_*' attribute, the 'default_*' that matches the specified | ||
9 | 'values_*' attribute may be used as its output value. | ||
10 |
| ||
11 | Let's consider an example which maps a string tensor to an integer tensor. | ||
12 | Assume and 'keys_strings' is ["Amy", "Sally"], 'values_int64s' is [5, 6], | ||
13 | and 'default_int64' is '-1'. The input ["Dori", "Amy", "Amy", "Sally", | ||
14 | "Sally"] would be mapped to [-1, 5, 5, 6, 6]. | ||
15 |
| ||
16 | Since this operator is an one-to-one mapping, its input and output shapes | ||
17 | are the same. Notice that only one of 'keys_*'/'values_*' can be set. | ||
18 |
| ||
19 | For key look-up, bit-wise comparison is used so even a float NaN can be | ||
20 | mapped to a value in 'values_*' attribute. | ||
21 |
| ||
0 | 22 | Converts strings to integers and vice versa. |
|
1 | 23 |
|
|
2 | 24 | If the string default value is set, it will convert integers to strings. |
|
3 | 25 | If the int default value is set, it will convert strings to integers. |
|
4 |
| ||
5 | 26 | Each operator converts either integers to strings or strings to integers, depending |
|
6 | 27 | on which default value attribute is provided. Only one default value attribute |
|
7 | should be defined. | ||
8 |
| ||
9 | 28 | When converting from integers to strings, the string is fetched from the |
|
10 | 'classes_strings' list, by simple indexing. | ||
11 |
| ||
12 | 29 | When converting from strings to integers, the string is looked up in the list |
|
13 | 30 | and the index at which it is found is used as the converted value. |
|
14 |
| ||
15 | **Attributes** | ||
16 |
| ||
17 | * **classes_strings**: | ||
18 | 31 | A list of labels. |
|
19 | 32 | * **default_int64**: |
|
20 | 33 | An integer to use when an input string value is not found in the |
|
21 | 34 | map.<br>One and only one of the 'default_*' attributes must be |
|
22 | 35 | defined. Default value is -1. |
|
23 | 36 | * **default_string**: |
|
24 | 37 | A string to use when an input integer value is not found in the |
|
25 | 38 | map.<br>One and only one of the 'default_*' attributes must be |
|
26 | 39 | defined. Default value is '_Unused'. |
|
40 | * **values_strings**: | ||
41 | A list of strings. One and only one of 'value_*'s should be set. | ||
27 | 42 |
|
|
28 | 43 | **Inputs** | **Inputs** |
29 | 44 |
|
|
30 | 45 | * **X** (heterogeneous) - **T1**: | * **X** (heterogeneous) - **T1**: |
31 | 46 | Input data. |
|
32 | 47 |
|
|
33 | 48 | **Outputs** | **Outputs** |
34 | 49 |
|
|
35 | 50 | * **Y** (heterogeneous) - **T2**: | * **Y** (heterogeneous) - **T2**: |
36 | 51 | Output data. If strings are input, the output values are integers, |
|
37 | and vice versa. | ||
38 | 52 |
|
|
39 | 53 | **Type Constraints** | **Type Constraints** |
40 | 54 |
|
|
41 | 55 | * **T1** in ( | * **T1** in ( |
56 | tensor(float), | ||
42 | 57 | tensor(int64), | tensor(int64), |
43 | 58 | tensor(string) | tensor(string) |
44 | 59 | ): | ): |
45 | 60 | The input type must be a tensor of integers or strings, of any |
|
46 | shape. | ||
47 | 61 | * **T2** in ( | * **T2** in ( |
48 | 62 | tensor(int64), |
|
49 | tensor(string) | ||
50 | ): | ||
51 | 63 | The output type will be a tensor of strings or integers, and will |
|
52 | 64 | have the same shape as the input. |
|
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.