0
0
TensorFlowml~10 mins

Categorical cross-entropy loss in TensorFlow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the categorical cross-entropy loss function from TensorFlow.

TensorFlow
from tensorflow.keras.losses import [1]
Drag options to blanks, or click blank then click option'
Acategorical_crossentropy
Bmean_squared_error
Cbinary_crossentropy
Dhinge_loss
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing binary_crossentropy which is for two-class problems.
Using mean_squared_error which is for regression tasks.
2fill in blank
medium

Complete the code to compile a Keras model using categorical cross-entropy loss.

TensorFlow
model.compile(optimizer='adam', loss=[1], metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
A'binary_crossentropy'
B'hinge'
C'mean_squared_error'
D'categorical_crossentropy'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'binary_crossentropy' for multi-class problems.
Using 'mean_squared_error' which is for regression.
3fill in blank
hard

Fix the error in the code to compute categorical cross-entropy loss manually using TensorFlow.

TensorFlow
loss = tf.keras.losses.categorical_crossentropy(y_true, [1])
Drag options to blanks, or click blank then click option'
Ay_pred
Bpredictions
Cy_predicted
Dy_true
Attempts:
3 left
💡 Hint
Common Mistakes
Passing true labels twice instead of predictions.
Using a variable name that is not defined.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps class names to their predicted probabilities.

TensorFlow
class_probs = {cls: [1][i] for i, cls in enumerate([2])}
Drag options to blanks, or click blank then click option'
Ay_pred
By_true
Cclass_names
Dpredictions
Attempts:
3 left
💡 Hint
Common Mistakes
Using true labels instead of predicted probabilities.
Mixing up class names with predictions.
5fill in blank
hard

Fill all three blanks to compute the average categorical cross-entropy loss over a batch.

TensorFlow
losses = tf.keras.losses.categorical_crossentropy([1], [2])
avg_loss = tf.reduce_mean([3])
Drag options to blanks, or click blank then click option'
Ay_true
By_pred
Closses
Dpredictions
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping true labels and predictions.
Trying to reduce mean over wrong variable.