Complete the code to import the categorical cross-entropy loss function from TensorFlow.
from tensorflow.keras.losses import [1]
The categorical_crossentropy function is used for multi-class classification problems where labels are one-hot encoded.
Complete the code to compile a Keras model using categorical cross-entropy loss.
model.compile(optimizer='adam', loss=[1], metrics=['accuracy'])
When compiling a model for multi-class classification with one-hot labels, use 'categorical_crossentropy' as the loss.
Fix the error in the code to compute categorical cross-entropy loss manually using TensorFlow.
loss = tf.keras.losses.categorical_crossentropy(y_true, [1])The function requires the true labels and the predicted probabilities as inputs. The predicted probabilities are usually stored in y_pred.
Fill both blanks to create a dictionary comprehension that maps class names to their predicted probabilities.
class_probs = {cls: [1][i] for i, cls in enumerate([2])}The dictionary comprehension pairs each class name with its predicted probability from y_pred. The class names are stored in class_names.
Fill all three blanks to compute the average categorical cross-entropy loss over a batch.
losses = tf.keras.losses.categorical_crossentropy([1], [2]) avg_loss = tf.reduce_mean([3])
First, compute the loss for each sample using true labels y_true and predictions y_pred. Then, calculate the average loss with tf.reduce_mean over the losses.