0
0
TensorFlowml~20 mins

Sequential model API in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sequential Model Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple Sequential model prediction
What is the output shape of the prediction from this Sequential model when given input shape (None, 10)?
TensorFlow
import tensorflow as tf
model = tf.keras.Sequential([
    tf.keras.layers.Dense(5, activation='relu', input_shape=(10,)),
    tf.keras.layers.Dense(3, activation='softmax')
])
import numpy as np
sample_input = np.random.random((1, 10))
prediction = model(sample_input)
prediction_shape = prediction.shape
print(prediction_shape)
A(1, 3)
B(10, 3)
C(1, 5)
D(3,)
Attempts:
2 left
💡 Hint
Remember the output shape depends on the last layer's units and batch size.
Model Choice
intermediate
2:00remaining
Choosing the correct Sequential model for binary classification
Which Sequential model architecture is best suited for a binary classification problem with input features of size 20?
ASequential([Dense(1, activation='relu', input_shape=(20,)), Dense(1, activation='sigmoid')])
BSequential([Dense(10, activation='relu', input_shape=(20,)), Dense(3, activation='softmax')])
CSequential([Dense(10, activation='relu', input_shape=(20,)), Dense(1, activation='sigmoid')])
DSequential([Dense(20, activation='relu'), Dense(1, activation='softmax')])
Attempts:
2 left
💡 Hint
Binary classification needs one output neuron with sigmoid activation.
Hyperparameter
advanced
2:00remaining
Effect of changing batch size in Sequential model training
What is the most likely effect of increasing the batch size from 16 to 256 during training of a Sequential model?
ATraining will use less memory and always converge slower.
BTraining will use less memory and produce more accurate models.
CTraining will use more memory and always overfit the data.
DTraining will use more memory and may converge faster but with less noisy gradient updates.
Attempts:
2 left
💡 Hint
Think about how batch size affects memory and gradient noise.
Metrics
advanced
2:00remaining
Correct metric for multi-class classification with Sequential model
Which metric should be used to evaluate a Sequential model trained for 4-class classification?
Amean_absolute_error
Baccuracy
Cmean_squared_error
Dbinary_crossentropy
Attempts:
2 left
💡 Hint
Think about the type of problem and metric suitability.
🔧 Debug
expert
2:00remaining
Identify the error in this Sequential model code
What error will this code raise when run?
TensorFlow
import tensorflow as tf
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(10, activation='relu'))
model.add(tf.keras.layers.Dense(1, activation='sigmoid'))
model.compile(optimizer='adam', loss='binary_crossentropy')
import numpy as np
x = np.random.random((5, 20))
y = np.random.randint(0, 2, size=(5, 1))
model.fit(x, y, epochs=1)
ANo error, code runs successfully
BTypeError: optimizer argument must be a string
CRuntimeError: model.fit requires validation data
DValueError: Input shape is not defined for the first layer
Attempts:
2 left
💡 Hint
Keras Sequential models can infer input shape from training data.