Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a saved TensorFlow model.
TensorFlow
model = tf.keras.models.load_model([1])Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the file name in quotes.
Using the model variable name instead of the file path.
✗ Incorrect
The load_model function requires the file path as a string to load the saved model.
2fill in blank
mediumComplete the code to make predictions with the loaded model.
TensorFlow
predictions = model.[1](input_data)Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fit' which trains the model instead of predicting.
Using 'evaluate' which returns loss and metrics, not predictions.
✗ Incorrect
The predict method is used to get model predictions on new input data.
3fill in blank
hardFix the error in the code to deploy the model for inference.
TensorFlow
def serve_model(request): data = request.get_json() input_data = tf.convert_to_tensor(data['input']) predictions = model.[1](input_data) return {'predictions': predictions.numpy().tolist()}
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fit' or 'train' which are for training, not inference.
Using 'compile' which prepares the model but does not predict.
✗ Incorrect
For inference in deployment, use model.predict to get predictions from input data.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps input features to predictions only if prediction is above threshold.
TensorFlow
result = {feature: pred for feature, pred in zip(features, predictions) if pred [1] threshold and feature [2] 'valid'}Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' for feature filtering.
Using '<' instead of '>' for prediction threshold.
✗ Incorrect
We want predictions greater than threshold and features not equal to 'valid' to filter results.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that stores uppercase feature names as keys, prediction scores as values, only if score is above 0.5.
TensorFlow
filtered_results = { [1]: [2] for [3], score in zip(features, predictions) if score > 0.5 }Attempts:
3 left
💡 Hint
Common Mistakes
Using 'predictions' instead of 'score' as value.
Using 'feature' instead of 'feature.upper()' for keys.
✗ Incorrect
Keys are uppercase feature names, values are scores, iterating over feature and score pairs.
