0
0
TensorFlowml~20 mins

Multi-input and multi-output models in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Multi-Input Multi-Output Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output shape of a multi-input model
Consider a TensorFlow model with two inputs: one of shape (None, 10) and another of shape (None, 5). Both inputs are concatenated and passed through a Dense layer with 8 units. What is the shape of the model's output?
TensorFlow
import tensorflow as tf

input1 = tf.keras.Input(shape=(10,))
input2 = tf.keras.Input(shape=(5,))

concat = tf.keras.layers.Concatenate()([input1, input2])
output = tf.keras.layers.Dense(8)(concat)

model = tf.keras.Model(inputs=[input1, input2], outputs=output)

print(model.output_shape)
A(None, 8)
B(None, 10)
C(None, 15)
D(None, 5)
Attempts:
2 left
💡 Hint
The Dense layer outputs a tensor with shape (batch_size, units).
Model Choice
intermediate
2:00remaining
Choosing the correct multi-output model architecture
You want to build a TensorFlow model that takes one input of shape (20,) and produces two outputs: one for regression (a single continuous value) and one for classification (3 classes). Which model architecture below correctly implements this?
AOne input layer, two Dense layers with 3 units each and relu activation for outputs.
BTwo input layers, one output layer with 4 units and softmax activation.
COne input layer, one Dense layer with 4 units and sigmoid activation for both outputs.
DOne input layer, shared Dense layers, then two separate Dense layers: one with 1 unit (no activation) for regression, one with 3 units and softmax for classification.
Attempts:
2 left
💡 Hint
Regression output usually has 1 unit without activation; classification output uses softmax for multiple classes.
Hyperparameter
advanced
2:00remaining
Choosing loss functions for multi-output models
You have a multi-output model with two outputs: a regression output and a 4-class classification output. Which combination of loss functions is appropriate to compile this model?
A{'regression_output': 'mse', 'classification_output': 'categorical_crossentropy'}
B{'regression_output': 'binary_crossentropy', 'classification_output': 'mse'}
C{'regression_output': 'categorical_crossentropy', 'classification_output': 'mse'}
D{'regression_output': 'mse', 'classification_output': 'binary_crossentropy'}
Attempts:
2 left
💡 Hint
Regression uses mean squared error; multi-class classification uses categorical crossentropy.
🔧 Debug
advanced
2:00remaining
Debugging multi-input model input mismatch error
You defined a TensorFlow model with two inputs: input1 shape (None, 8) and input2 shape (None, 4). When training, you get a ValueError about input shapes not matching. Which of the following is the most likely cause?
AYou used different batch sizes for input1 and input2 arrays.
BYou passed a single numpy array instead of a list or tuple of two arrays as input data.
CYou forgot to compile the model before training.
DYou used a Dense layer instead of Conv2D in the model.
Attempts:
2 left
💡 Hint
Multi-input models expect inputs as a list or tuple matching the input layers.
🧠 Conceptual
expert
2:00remaining
Understanding training metrics in multi-output models
A multi-output model has two outputs: output A (regression) and output B (classification). You compile the model with metrics={'output_A': ['mae'], 'output_B': ['accuracy']}. During training, what will the reported 'accuracy' metric represent?
AThe overall accuracy combining regression and classification outputs.
BThe average accuracy of both outputs A and B.
CThe classification accuracy of output B only.
DThe mean absolute error of output A converted to accuracy.
Attempts:
2 left
💡 Hint
Metrics are reported per output when specified as a dictionary.