SparseCategoricalCrossentropy¶
- class dragon.vm.tensorflow.keras.losses.SparseCategoricalCrossentropy(
 axis=- 1,
 ignore_index=None,
 reduction='valid',
 name=None
 )[source]¶
- A criterion to compute the categorical cross entropy with sparse labels. - The CrossEntropy function is defined as: \[\text{CrossEntropy}(p_{t}) = -\log(p_{t}) \]- Examples: - criterion = tf.keras.cost.SparseCategoricalCrossentropy() y_true = tf.constant([1, 0], 'int64') y_pred = tf.constant([[0.5, 0.5], [0.3, 0.7]]) print(criterion(y_true, y_pred)) # 0.8030813 
__init__¶
- SparseCategoricalCrossentropy.- __init__(
 axis=- 1,
 ignore_index=None,
 reduction='valid',
 name=None
 )[source]¶
- Create a - SparseCategoricalCrossentropycriterion.- Parameters:
- 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.
- name (str, optional) – The operation name.
 
 
Methods¶
__call__¶
- Loss.- __call__(
 y_true,
 y_pred
 )[source]
- Compute the defined loss function. - Parameters:
- y_true (dragon.Tensor) – The ground-truth tensor.
- y_pred (dragon.Tensor) – The logits tensor.
 
 - Returns:
- dragon.Tensor – The loss. 
 
