0
0
TensorFlowml~10 mins

First neural network 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 neural network model using TensorFlow Keras.

TensorFlow
import tensorflow as tf
model = tf.keras.Sequential([
    tf.keras.layers.Dense(10, activation=[1])
])
Drag options to blanks, or click blank then click option'
A"relu"
B"linear"
C"sigmoid"
D"softmax"
Attempts:
3 left
💡 Hint
Common Mistakes
Using activation functions like 'softmax' in the first hidden layer instead of output layer.
Forgetting to put activation function as a string.
2fill in blank
medium

Complete the code to compile the model with an optimizer.

TensorFlow
model.compile(optimizer=[1], loss='sparse_categorical_crossentropy', metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
A"adagrad"
B"rmsprop"
C"adam"
D"sgd"
Attempts:
3 left
💡 Hint
Common Mistakes
Using an invalid string for optimizer.
Forgetting to put the optimizer name in quotes.
3fill in blank
hard

Fix the error in the code to train the model on data.

TensorFlow
history = model.fit(x_train, y_train, epochs=[1])
Drag options to blanks, or click blank then click option'
A5
B"5"
C10.0
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Passing epochs as a string like "5" instead of integer 5.
Passing epochs as a float like 10.0.
4fill in blank
hard

Fill both blanks to create a dictionary of training accuracy and loss from the history object.

TensorFlow
metrics = { 'accuracy': history.history[[1]], 'loss': history.history[[2]] }
Drag options to blanks, or click blank then click option'
A"accuracy"
B"acc"
C"loss"
D"val_loss"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'acc' instead of 'accuracy' which may not be present depending on TensorFlow version.
Mixing validation loss key 'val_loss' with training loss.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each word to its length if length is greater than 3.

TensorFlow
lengths = { [1]: [2] for [3] in words if len([3]) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not using len() to get the length.