0
0
TensorFlowml~20 mins

Softmax output layer in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Softmax Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
Output shape of a softmax layer
What is the shape of the output tensor after applying a softmax layer with 10 units to an input batch of shape (32, 100)?
TensorFlow
import tensorflow as tf
inputs = tf.random.uniform((32, 100))
softmax_layer = tf.keras.layers.Dense(10, activation='softmax')
outputs = softmax_layer(inputs)
output_shape = outputs.shape
print(output_shape)
A(10, 32)
B(32, 10)
C(32, 100)
D(100, 10)
Attempts:
2 left
💡 Hint
The softmax layer outputs one probability distribution per input example.
Model Choice
intermediate
1:30remaining
Choosing the correct output layer for multi-class classification
You want to build a neural network to classify images into 5 categories. Which output layer configuration is correct?
ADense(1, activation='sigmoid')
BDense(1, activation='softmax')
CDense(5, activation='sigmoid')
DDense(5, activation='softmax')
Attempts:
2 left
💡 Hint
Softmax is used for multi-class classification with mutually exclusive classes.
Hyperparameter
advanced
2:00remaining
Effect of temperature parameter on softmax output
In a softmax function, what is the effect of increasing the temperature parameter T > 1 on the output probabilities?
AThe output probabilities do not change.
BThe output probabilities become more peaked (more confident).
CThe output probabilities become more uniform (less confident).
DThe softmax function becomes equivalent to sigmoid.
Attempts:
2 left
💡 Hint
Temperature controls the sharpness of the softmax distribution.
Metrics
advanced
1:30remaining
Correct loss function for softmax output layer
Which loss function should you use when training a model with a softmax output layer for multi-class classification?
ASparseCategoricalCrossentropy
BBinaryCrossentropy
CMeanSquaredError
DHuberLoss
Attempts:
2 left
💡 Hint
The loss function must match the output activation and label format.
🔧 Debug
expert
2:00remaining
Identifying the error in softmax output layer usage
What error will occur when compiling this model? import tensorflow as tf model = tf.keras.Sequential([ tf.keras.layers.Dense(10), tf.keras.layers.Softmax() ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy')
TensorFlow
import tensorflow as tf
model = tf.keras.Sequential([
  tf.keras.layers.Dense(10),
  tf.keras.layers.Softmax()
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy')
ANo error, model compiles successfully.
BRuntimeError: Loss function incompatible with model output.
CTypeError: Softmax layer cannot be used as a separate layer after Dense.
DValueError: You must pass logits to SparseCategoricalCrossentropy when from_logits=True is False.
Attempts:
2 left
💡 Hint
Softmax can be a separate layer; loss expects probabilities by default.