tf.keras.ops.multi_hot
Stay organized with collections
Save and categorize content based on your preferences.
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.
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.
|
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)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-07 UTC."],[],[]]