sparse_categorical_crossentropy

dragon.vm.tensorflow.keras.losses.sparse_categorical_crossentropy(
  y_true,
  y_pred,
  axis=- 1,
  ignore_index=None,
  reduction='valid'
)[source]

Compute the categorical cross entropy with sparse labels.

The CrossEntropy function is defined as:

\[\text{CrossEntropy}(p_{t}) = -\log(p_{t}) \]

Examples:

y_true = tf.constant([1, 0], 'int64')
y_pred = tf.constant([[0.5, 0.5], [0.3, 0.7]])
print(tf.keras.cost.sparse_categorical_crossentropy(y_true, y_pred))  # 0.8030813
Parameters:
  • y_true (dragon.Tensor) The ground truth tensor.
  • y_pred (dragon.Tensor) The logits tensor.
  • axis (int, optional, default=-1) The reduction axis.
  • ignore_index (int, optional) The ignored value of target.
  • reduction ({'none', 'sum', 'mean', 'valid'}, optional) The reduction method.
Returns:

dragon.Tensor The loss.