0
0
TensorFlowml~10 mins

Why neural networks excel at classification in TensorFlow - Test Your Understanding

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 layer using TensorFlow.

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 linear activation which does not help learn complex patterns.
Choosing softmax in hidden layers instead of output layer.
2fill in blank
medium

Complete the code to compile the model with an appropriate loss function for classification.

TensorFlow
model.compile(optimizer='adam', loss=[1], metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
A"mean_squared_error"
B"mean_absolute_error"
C"categorical_crossentropy"
D"hinge"
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean squared error which is better for regression.
Choosing hinge loss which is for SVMs.
3fill in blank
hard

Fix the error in the code to correctly predict classes from model output probabilities.

TensorFlow
predictions = model.predict(test_data)
predicted_classes = tf.argmax(predictions, axis=[1])
Drag options to blanks, or click blank then click option'
A2
B1
C-1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using axis 0 which selects the batch dimension.
Using axis -1 which may work but is less clear here.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

TensorFlow
word_lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword.startswith('a')
Dword.isalpha()
Attempts:
3 left
💡 Hint
Common Mistakes
Using the condition incorrectly or missing it.
Mapping to the word itself instead of its length.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their counts only if count is greater than 1.

TensorFlow
word_counts = [1]: [2] for word, count in counts.items() if [3]
Drag options to blanks, or click blank then click option'
Aword.upper()
Bcount
Ccount > 1
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase instead of uppercase for keys.
Not filtering counts properly.