.. _op_ai_onnx_ml_CategoryMapper: CategoryMapper ============== - **Domain**: ``ai.onnx.ml`` - **Since version**: 1 Converts strings to integers and vice versa. Two sequences of equal length are used to map between integers and strings, with strings and integers at the same index detailing the mapping. 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. 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. **Inputs** - **X** (*T1*): Input data **Outputs** - **Y** (*T2*): Output data. If strings are input, the output values are integers, and vice versa. **Type Constraints** - **T1**: The input must be a tensor of strings or integers, either [N,C] or [C]. Allowed types: tensor(int64), tensor(string). - **T2**: The output is a tensor of strings or integers. Its shape will be the same as the input shape. Allowed types: tensor(int64), tensor(string). Examples -------- **test_cc_category_mapper_int_to_string** .. code-block:: text Node: ai.onnx.ml.CategoryMapper(x) -> (y) Attributes: cats_strings = ['hello', 'world', 'good morning'] cats_int64s = [1, 2, 3] default_string = "_Unused" .. code-block:: text Inputs: x: shape=(4,), dtype=int64 [1, 2, 4, 3] Outputs: y: shape=(4,), dtype=object ['hello', 'world', '_Unused', 'good morning'] **test_cc_category_mapper_string_to_int** .. code-block:: text Node: ai.onnx.ml.CategoryMapper(x) -> (y) Attributes: cats_strings = ['hello', 'world', 'good morning'] cats_int64s = [1, 2, 3] default_int64 = -1 .. code-block:: text Inputs: x: shape=(4,), dtype=object ['hello', 'world', '?', 'good morning'] Outputs: y: shape=(4,), dtype=int64 [ 1, 2, -1, 3]