one_hot

dragon.vm.tensorflow.one_hot(
  indices,
  depth,
  on_value=1,
  off_value=0,
  name=None
)[source]

Return the one-hot representation from indices.

\[y[i][j] = \begin{cases} \text{Val}_{off}, & \text{ if } \text{indices}[i] \neq j \\ \text{Val}_{on}, & \text{ otherwise } \end{cases} \]

The max value of indices, i.e., the depth should be specified:

indices = tf.constant([0, 1, 2, 3], tf.int64)
print(tf.one_hot(indices, depth=5))  # depth >= 4 will be ok

You can also set the on_value or off_value:

print(tf.one_hot(indices, depth=4, on_value=2, off_value=3))
Parameters:
  • indices (dragon.Tensor) – The tensor indices.
  • depth (int) – The depth of representation.
  • on_value (int, optional, default=1) – The value for equal branch.
  • off_value (int, optional, default=0) – The value for not-equal branch.
  • name (str, optional) – A optional name for the operation.
Returns:

dragon.Tensor – The output tensor.