0
0
TensorFlowml~10 mins

Sequential model API in TensorFlow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a simple sequential model with one dense layer.

TensorFlow
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'
ASequential
B32
C10
D'relu'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the activation function name instead of number of units.
Passing the input shape as the first argument instead of units.
2fill in blank
medium

Complete the code to compile the model with mean squared error loss.

TensorFlow
model.compile(optimizer='adam', loss='[1]', metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
Amean_squared_error
Bcategorical_crossentropy
Caccuracy
Dadam
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'accuracy' as loss instead of a loss function.
Using 'adam' as loss instead of optimizer.
3fill in blank
hard

Fix the error in the code to add a dropout layer after the first dense layer.

TensorFlow
from tensorflow.keras.layers import Dropout

model = Sequential()
model.add(Dense(64, input_shape=(20,), activation='relu'))
model.add([1](0.5))
Drag options to blanks, or click blank then click option'
ADropout
BDense
CActivation
DFlatten
Attempts:
3 left
💡 Hint
Common Mistakes
Using Dense instead of Dropout for dropout layer.
Forgetting to import Dropout layer.
4fill in blank
hard

Fill both blanks to create a sequential model with two dense layers and compile it with Adam optimizer and categorical crossentropy loss.

TensorFlow
model = Sequential()
model.add(Dense([1], activation='relu', input_shape=(15,)))
model.add(Dense([2], activation='softmax'))
model.compile(optimizer='[3]', loss='categorical_crossentropy')
Drag options to blanks, or click blank then click option'
A64
B10
C32
Dadam
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong number of units in output layer.
Using wrong optimizer name.
5fill in blank
hard

Fill all three blanks to create a sequential model with input shape, two dense layers, and compile it with RMSprop optimizer and binary crossentropy loss.

TensorFlow
model = Sequential()
model.add(Dense([1], activation='relu', input_shape=([2],)))
model.add(Dense([3], activation='sigmoid'))
model.compile(optimizer='rmsprop', loss='binary_crossentropy')
Drag options to blanks, or click blank then click option'
A128
B20
C1
D64
Attempts:
3 left
💡 Hint
Common Mistakes
Using more than 1 unit in output layer for binary classification.
Wrong input shape format.