Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a softmax output layer with 3 classes.
TensorFlow
model.add(tf.keras.layers.Dense(3, activation=[1]))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'relu' or 'sigmoid' in the output layer for multi-class classification.
Forgetting to specify activation function.
✗ Incorrect
The softmax activation function is used in the output layer for multi-class classification to produce probabilities for each class.
2fill in blank
mediumComplete the code to compile the model with the correct loss function for softmax output.
TensorFlow
model.compile(optimizer='adam', loss=[1], metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'binary_crossentropy' for multi-class problems.
Using loss functions meant for regression.
✗ Incorrect
For multi-class classification with softmax output, 'categorical_crossentropy' is the appropriate loss function.
3fill in blank
hardFix the error in the code to correctly define a softmax output layer.
TensorFlow
output = tf.keras.layers.Dense(5, activation=[1])(previous_layer)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing activation without quotes.
Using uppercase letters in activation string.
✗ Incorrect
Activation functions must be passed as lowercase strings like 'softmax'. Passing without quotes or with wrong case causes errors.
4fill in blank
hardFill both blanks to create a softmax output layer and compile the model correctly.
TensorFlow
model.add(tf.keras.layers.Dense([1], activation=[2])) model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong number of units for output layer.
Using 'sigmoid' instead of 'softmax' for multi-class output.
✗ Incorrect
The output layer should have units equal to the number of classes (10 here) and use 'softmax' activation for multi-class classification.
5fill in blank
hardFill all three blanks to define a softmax output layer, compile the model, and fit it with data.
TensorFlow
model = tf.keras.Sequential() model.add(tf.keras.layers.Dense(64, activation='relu')) model.add(tf.keras.layers.Dense([1], activation=[2])) model.compile(optimizer=[3], loss='categorical_crossentropy', metrics=['accuracy']) model.fit(x_train, y_train, epochs=5)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong number of output units.
Using 'sigmoid' activation instead of 'softmax'.
Using an optimizer other than 'adam' without reason.
✗ Incorrect
The output layer units match the number of classes (3), activation is 'softmax', and optimizer is 'adam' for good training performance.