Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a simple neural network layer using Keras.
ML Python
from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense model = Sequential() model.add(Dense([1], input_shape=(10,), activation='relu'))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the activation function name instead of the number of neurons.
Using the input shape as the number of neurons.
✗ Incorrect
The first Dense layer needs the number of neurons as the first argument, here 32 neurons.
2fill in blank
mediumComplete the code to compile the model with the correct loss function for classification.
ML Python
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 mean squared error loss for classification.
Using hinge loss which is for SVMs.
✗ Incorrect
For multi-class classification, 'categorical_crossentropy' is the correct loss function.
3fill in blank
hardFix the error in the code to add a dropout layer with 0.5 dropout rate.
ML Python
from tensorflow.keras.layers import Dropout model.add(Dropout([1]))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 50 instead of 0.5 for dropout rate.
Using values greater than 1.
✗ Incorrect
Dropout rate should be a float between 0 and 1, so 0.5 means 50% dropout.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps layer names to their output shapes for layers with output shape length greater than 2.
ML Python
layer_shapes = {layer.name: layer.output_shape for layer in model.layers if len(layer.output_shape) [1] [2] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the condition.
Using 1 instead of 2 as the threshold.
✗ Incorrect
We want layers where the output shape length is greater than 2, so use '>' and 2.
5fill in blank
hardFill all three blanks to create a dictionary that maps layer names in uppercase to their output shapes, but only for layers with output shape length greater than 1.
ML Python
layer_info = {layer.name[1]: layer.output_shape for layer in model.layers if len(layer.output_shape) [2] [3] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using .upper() to convert names.
Using '<' instead of '>' in the condition.
Using 2 instead of 1 as the threshold.
✗ Incorrect
We convert layer names to uppercase with .upper(), and filter layers with output shape length greater than 1.