Challenge - 5 Problems
Dense Layer Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output shape of a Dense layer
Given the following TensorFlow code, what is the shape of the output tensor after the Dense layer?
TensorFlow
import tensorflow as tf input_tensor = tf.random.uniform((5, 10)) # batch size 5, input features 10 layer = tf.keras.layers.Dense(8) output = layer(input_tensor) output_shape = output.shape print(output_shape)
Attempts:
2 left
💡 Hint
Remember the Dense layer changes the last dimension to the number of units.
✗ Incorrect
The Dense layer transforms each input vector of size 10 into a vector of size 8. Since the batch size is 5, the output shape is (5, 8).
❓ Model Choice
intermediate2:00remaining
Choosing the correct Dense layer for classification
You want to build a neural network to classify images into 10 categories. Which Dense layer configuration is most appropriate for the final layer?
Attempts:
2 left
💡 Hint
For multi-class classification, the output layer should have one unit per class with softmax activation.
✗ Incorrect
For 10 classes, the output layer should have 10 units with softmax activation to output probabilities for each class.
❓ Hyperparameter
advanced2:00remaining
Effect of changing units in Dense layer
What is the effect of increasing the number of units in a Dense layer from 32 to 128 in a neural network?
Attempts:
2 left
💡 Hint
More units mean more parameters to learn.
✗ Incorrect
Increasing units increases the number of parameters, allowing the model to learn more complex patterns but also increasing overfitting risk.
🔧 Debug
advanced2:00remaining
Identifying error in Dense layer usage
What error will this code raise when run?
TensorFlow
import tensorflow as tf input_tensor = tf.random.uniform((5, 10)) layer = tf.keras.layers.Dense(-5) output = layer(input_tensor)
Attempts:
2 left
💡 Hint
Check the units argument for Dense layer.
✗ Incorrect
Dense layer units must be a positive integer. Negative units cause a ValueError.
🧠 Conceptual
expert2:00remaining
Why use bias in Dense layers?
What is the main purpose of including a bias term in a Dense (fully connected) layer?
Attempts:
2 left
💡 Hint
Think about shifting the activation function.
✗ Incorrect
Bias allows the activation function to shift, enabling the model to fit data that does not pass through zero.