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:
int
Inputs:
indices
: input tensor of rank N
with indices of any supported integer data type. Can be 0D. Required.depth
: scalar (0D tensor) of any supported integer type that specifies number of classes and the size of one-hot dimension.on_value
: scalar (0D tensor) of any type that is the value that the locations in output tensor represented by indices in input take.off_value
: scalar (0D tensor) of any type that is the value that the locations not represented by indices in input take.Outputs:
N+1
, where N
is a rank of input tensor indices
. A new axis of the size depth
is inserted at the dimension axis
.Examples