<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/ops/nn.py#L2270-L2313) |

Encodes integer labels as multi-hot vectors.

#### View aliases


**Main aliases**

[`tf.keras.ops.nn.multi_hot`](https://www.tensorflow.org/api_docs/python/tf/keras/ops/multi_hot)

<br />

    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.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `inputs` | Tensor of integer labels to be converted to multi-hot vectors. |
| `num_classes` | Integer, the total number of unique classes. |
| `axis` | (optional) Axis along which the multi-hot encoding should be added. Defaults to `-1`, which corresponds to the last dimension. |
| `dtype` | (optional) The data type of the resulting tensor. Default is backend's float type. |
| `sparse` | Whether to return a sparse tensor; for backends that support sparse tensors. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| `Tensor` | The multi-hot encoded tensor. |

<br />

#### 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)