Page:
https://www.tensorflow.org/api_docs/python/tf/keras/losses/SparseCategoricalCrossentropy
The first example no longer functions.
y_true = [1, 2]
y_pred = [[0.05, 0.95, 0], [0.1, 0.8, 0.1]]
# Using 'auto'/'sum_over_batch_size' reduction type.
scce = keras.losses.SparseCategoricalCrossentropy()
scce(y_true, y_pred)
The error is:
ValueError: Structures don't have the same nested structure.
Fixed code:
y_true = tf.constant([1, 2])
y_pred = tf.constant([[0.05, 0.95, 0], [0.1, 0.8, 0.1]])
scce = keras.losses.SparseCategoricalCrossentropy()
loss = scce(y_true, y_pred)
print(loss.numpy())