0
0
TensorFlowml~10 mins

Softmax output layer 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 add a softmax output layer with 3 classes.

TensorFlow
model.add(tf.keras.layers.Dense(3, activation=[1]))
Drag options to blanks, or click blank then click option'
A"relu"
B"tanh"
C"softmax"
D"sigmoid"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'relu' or 'sigmoid' in the output layer for multi-class classification.
Forgetting to specify activation function.
2fill in blank
medium

Complete the code to compile the model with the correct loss function for softmax output.

TensorFlow
model.compile(optimizer='adam', loss=[1], metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
A"hinge"
B"binary_crossentropy"
C"mean_squared_error"
D"categorical_crossentropy"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'binary_crossentropy' for multi-class problems.
Using loss functions meant for regression.
3fill in blank
hard

Fix the error in the code to correctly define a softmax output layer.

TensorFlow
output = tf.keras.layers.Dense(5, activation=[1])(previous_layer)
Drag options to blanks, or click blank then click option'
A"softmax"
Bsoftmax
C"Softmax"
D"relu"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing activation without quotes.
Using uppercase letters in activation string.
4fill in blank
hard

Fill both blanks to create a softmax output layer and compile the model correctly.

TensorFlow
model.add(tf.keras.layers.Dense([1], activation=[2]))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
A10
B"softmax"
C5
D"sigmoid"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong number of units for output layer.
Using 'sigmoid' instead of 'softmax' for multi-class output.
5fill in blank
hard

Fill all three blanks to define a softmax output layer, compile the model, and fit it with data.

TensorFlow
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(64, activation='relu'))
model.add(tf.keras.layers.Dense([1], activation=[2]))
model.compile(optimizer=[3], loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)
Drag options to blanks, or click blank then click option'
A3
B"softmax"
C'adam'
D'sgd'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong number of output units.
Using 'sigmoid' activation instead of 'softmax'.
Using an optimizer other than 'adam' without reason.