0
0
TensorFlowml~20 mins

Dense (fully connected) layers in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dense Layer Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A(10, 8)
B(5, 8)
C(5, 10)
D(8, 5)
Attempts:
2 left
💡 Hint
Remember the Dense layer changes the last dimension to the number of units.
Model Choice
intermediate
2: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?
ADense(10, activation='softmax')
BDense(1, activation='sigmoid')
CDense(10, activation='relu')
DDense(5, activation='softmax')
Attempts:
2 left
💡 Hint
For multi-class classification, the output layer should have one unit per class with softmax activation.
Hyperparameter
advanced
2: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?
AIncreases model capacity and may improve learning but risks overfitting
BDecreases model capacity and speeds up training
CHas no effect on model capacity or training time
DAlways guarantees better accuracy on test data
Attempts:
2 left
💡 Hint
More units mean more parameters to learn.
🔧 Debug
advanced
2: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)
ARuntimeError: layer not built
BTypeError: input_tensor shape invalid
CNo error, runs successfully
DValueError: units must be a positive integer
Attempts:
2 left
💡 Hint
Check the units argument for Dense layer.
🧠 Conceptual
expert
2:00remaining
Why use bias in Dense layers?
What is the main purpose of including a bias term in a Dense (fully connected) layer?
ATo reduce the number of parameters in the model
BTo normalize the input data automatically
CTo allow the model to fit data that does not pass through the origin
DTo prevent overfitting by adding regularization
Attempts:
2 left
💡 Hint
Think about shifting the activation function.