View source on GitHub
|
Computes the categorical hinge loss between y_true & y_pred.
tf.keras.losses.categorical_hinge(
y_true, y_pred
)
loss = maximum(neg - pos + 1, 0)
where neg=maximum((1-y_true)*y_pred) and pos=sum(y_true*y_pred)
y_true
y_true values are expected to be
either {-1, +1} or {0, 1} (i.e. a one-hot-encoded tensor) with
shape = [batch_size, d0, .. dN].
y_pred
[batch_size, d0, .. dN].
[batch_size, d0, .. dN-1].
y_true = np.random.randint(0, 3, size=(2,))y_true = np.eye(np.max(y_true) + 1)[y_true]y_pred = np.random.random(size=(2, 3))loss = keras.losses.categorical_hinge(y_true, y_pred)
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.