OneHot - Maple Help

DeepLearning

 OneHot
 construct a one-hot Tensor

 Calling Sequence OneHot(indices,depth,opts)

Parameters

 indices - list of integers depth - integer opts - (optional) options as specified below

Options

 • axis = integer
 The axis to fill (default: -1, a new inner-most axis).
 • datatype = one of string,truefalse,integer[4],integer[8],float[4],float[8],complex[4], or complex[8]
 The value of option datatype specifies the type of data this Tensor will hold. By default, the datatype is inferred from on_value or off_value.
 • off_value = scalar
 The value to fill in output when indices[j] <> i (default: 0). If a datatype was specified, this value must be compatible with that type.
 • on_value = scalar
 The value to fill in output when indices[j] = i (default: 1). If a datatype was specified, this value must be compatible with that type.
 • name = string
 The value of option name specifies an optional name for this Tensor, to be displayed in output and when visualizing the dataflow graph.

Description

 • The OneHot(indices,depth,opts) command creates a one-hot Tensor in the active dataflow graph. The term "one-hot" comes from digital circuits and refers to a configuration where every bit in a collection is turned off, except one.
 • In the Tensor returned, the locations represented by indices take value on_value, while all other locations take value off_value.
 • If the input indices is rank n, the output will have rank n+1. The new axis is created at the dimension specified by axis. By default, the new axis is appended at the end.
 • These functions are part of the DeepLearning package, so they can can be used in the short form OneHot(..) only after executing the command with(DeepLearning). However,  can always be accessed through the long form of the command by using DeepLearning[OneHot](..).

Details

 • The implementation of EinsteinSummation uses the tf.one_hot command from the TensorFlow Python API. Consult the TensorFlow Python API documentation for tf.one_hot for more information.

Examples

 > $\mathrm{with}\left(\mathrm{DeepLearning}\right):$
 > $t≔\mathrm{OneHot}\left(\left[0,1,2\right],3,\mathrm{on_value}=3.0,\mathrm{off_value}=0.\right)$
 ${t}{≔}\left[\begin{array}{c}{\mathrm{DeepLearning Tensor}}\\ {\mathrm{Name: none}}\\ {\mathrm{Shape: undefined}}\\ {\mathrm{Data Type: float\left[4\right]}}\end{array}\right]$ (1)
 > $\mathrm{Shape}\left(t\right)$
 ${\mathrm{undefined}}$ (2)

Compatibility

 • The DeepLearning[OneHot] command was introduced in Maple 2018.