View source on GitHub |
Encodes integer labels as multi-hot vectors.
tf.keras.ops.multi_hot(
inputs, num_classes=None, axis=-1, dtype=None, sparse=False, **kwargs
)
This function encodes integer labels as multi-hot vectors, where each label is mapped to a binary value in the resulting vector.
Returns | |
---|---|
Tensor
|
The multi-hot encoded tensor. |
Example:
data = keras.ops.convert_to_tensor([0, 4])
keras.ops.multi_hot(data, num_classes=5)
array([1.0, 0.0, 0.0, 0.0, 1.0], dtype=float32)