tf.keras.losses.categorical_hinge

Computes the categorical hinge loss between y_true & y_pred.

Formula:

loss = maximum(neg - pos + 1, 0)

where neg=maximum((1-y_true)*y_pred) and pos=sum(y_true*y_pred)

y_true The ground truth values. 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 The predicted values with shape = [batch_size, d0, .. dN].

Categorical hinge loss values with shape = [batch_size, d0, .. dN-1].

Example:

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)