OneHot

Versioned name: OneHot-1

Category: Sequence processing

Short description: OneHot sets the elements in the output tensor with specified indices to on_value and fills all other locations with off_value.

Detailed description

Taking a tensor with rank N as the first input indices, OneHot produces tensor with rank N+1 extending original tensor with a new dimension at axis position in shape. Output tensor is populated with two scalar values: on_value that comes from the 3rd input and off_value that comes from the 4nd input. Population is made in the following way:

output[:, ... ,:, i, :, ... ,:] = on_value if (indices[:, ..., :, :, ..., :] == i) else off_value

where i is at axis position in output shape and has values from range [0, ..., depth-1].

When index element from indices is greater or equal to depth, it is a well-formed operation. In this case the corresponding row output[..., i, ...] is populated with off_value only for all i values.

Types of input scalars on_value and off_value should match and can be any of the supported types. The type of output tensor is derived from on_value and off_value, they all have the same type.

Attributes:

Inputs:

Outputs:

Examples

<layer ... type="OneHot" ...>
<data axis="-1"/>
<input>
<port id="0">
<dim>3</dim>
</port>
<port id="1">
</port>
<port id="2">
</port>
<port id="3">
</port>
</input>
<output>
<port id="0">
<dim>3</dim>
<dim>2</dim>
</port>
</output>
</layer>