0
0
Prompt Engineering / GenAIml~20 mins

Output format control in Prompt Engineering / GenAI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Output Format Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output format of model predictions in JSON
Given a model that predicts labels for images, what is the output format of the following code snippet?
Prompt Engineering / GenAI
predictions = model.predict(images)
output = [{"image_id": i, "label": label} for i, label in enumerate(predictions)]
print(output)
A[{'label': 'cat'}, {'label': 'dog'}]
B[{'0': 'cat'}, {'1': 'dog'}]
C[('image_id', 0, 'label', 'cat'), ('image_id', 1, 'label', 'dog')]
D[{'image_id': 0, 'label': 'cat'}, {'image_id': 1, 'label': 'dog'}]
Attempts:
2 left
💡 Hint
Look at how the list comprehension builds dictionaries with keys 'image_id' and 'label'.
Metrics
intermediate
2:00remaining
Interpreting accuracy output format
After training a classification model, the accuracy is printed as follows. What is the type and format of the accuracy output?
Prompt Engineering / GenAI
accuracy = model.evaluate(test_data)
print(f"Accuracy: {accuracy}")
AA dictionary with keys 'accuracy' and 'loss'
BA float number between 0 and 1 representing accuracy
CA list of accuracy values for each class
DA string describing accuracy percentage like '85%'
Attempts:
2 left
💡 Hint
Model evaluation usually returns numeric metrics as floats.
Model Choice
advanced
2:00remaining
Choosing output format for multi-label classification
You build a multi-label classifier that predicts multiple labels per input. Which output format best represents the model predictions?
AA string with comma-separated labels, e.g. ['cat,dog', 'bird']
BA single integer label per input, e.g. [0, 1]
CA list of label indices for each input, e.g. [[0,2], [1,3]]
DA dictionary with keys as labels and boolean values, e.g. [{'cat': True, 'dog': False}]
Attempts:
2 left
💡 Hint
Multi-label means multiple labels per input, so output must allow multiple labels.
🔧 Debug
advanced
2:00remaining
Identifying output format error in prediction code
What error occurs when running this code that formats model output incorrectly?
Prompt Engineering / GenAI
preds = model.predict(data)
formatted = {i: preds[i] for i in preds}
print(formatted)
AKeyError because preds has no keys
BNo error, prints correct dictionary
CTypeError because preds is a list and cannot be used as dict keys
DSyntaxError due to missing colon
Attempts:
2 left
💡 Hint
Check the type of preds and how it is used in the dict comprehension.
🧠 Conceptual
expert
2:00remaining
Best practice for output format in AI model serving
When serving an AI model via an API, which output format is best for easy parsing and extensibility?
AJSON with keys for predictions, confidence scores, and metadata
BPlain text with predictions separated by commas
CBinary format with raw model output tensors
DCSV string with predictions only
Attempts:
2 left
💡 Hint
Consider formats that are human-readable and easy to extend with new fields.