0
0
TensorFlowml~10 mins

Functional API basics 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 an input layer with shape (28, 28).

TensorFlow
inputs = tf.keras.Input(shape=[1])
Drag options to blanks, or click blank then click option'
A(28, 28)
B28
C[28, 28]
D(784,)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a tuple for shape.
Specifying the total number of pixels instead of the shape tuple.
2fill in blank
medium

Complete the code to add a Dense layer with 64 units and ReLU activation.

TensorFlow
x = tf.keras.layers.Dense([1], activation='relu')(inputs)
Drag options to blanks, or click blank then click option'
A128
B64
C32
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing the wrong number of units.
Confusing activation function with units.
3fill in blank
hard

Fix the error in the code to create the model using the Functional API.

TensorFlow
model = tf.keras.Model(inputs=[1], outputs=x)
Drag options to blanks, or click blank then click option'
Aoutputs
Bx
Cmodel
Dinputs
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the output tensor as inputs.
Passing the model variable itself.
4fill in blank
hard

Fill both blanks to flatten the input and add a Dense layer with 10 units.

TensorFlow
x = tf.keras.layers.[1]()(inputs)
x = tf.keras.layers.Dense([2])(x)
Drag options to blanks, or click blank then click option'
AFlatten
B10
CDense
D64
Attempts:
3 left
💡 Hint
Common Mistakes
Using Dense instead of Flatten for the first layer.
Choosing wrong number of units for the Dense layer.
5fill in blank
hard

Fill all three blanks to compile the model with Adam optimizer, sparse categorical crossentropy loss, and accuracy metric.

TensorFlow
model.compile(optimizer='[1]', loss='[2]', metrics=['[3]'])
Drag options to blanks, or click blank then click option'
Aadam
Bsparse_categorical_crossentropy
Caccuracy
Dsgd
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong optimizer like 'sgd' when 'adam' is expected.
Using categorical_crossentropy instead of sparse_categorical_crossentropy.
Forgetting to include accuracy metric.