You want to build a neural network in TensorFlow to classify images into 5 different categories. Which output layer configuration is correct for this multi-class classification task?
For multi-class classification, the output layer should have one neuron per class with a softmax activation.
Softmax activation outputs probabilities for each class summing to 1, which is needed for multi-class classification. Sigmoid is for binary or multi-label tasks.
Which loss function should you use in TensorFlow when training a multi-class classification model with one-hot encoded labels?
One-hot encoded labels require a loss function that compares probability distributions.
CategoricalCrossentropy is used with one-hot labels. SparseCategoricalCrossentropy is for integer labels. BinaryCrossentropy is for binary tasks.
Given the following TensorFlow model for 4-class classification, what is the shape of the output predictions for a batch of 10 samples?
import tensorflow as tf model = tf.keras.Sequential([ tf.keras.layers.Dense(16, activation='relu', input_shape=(8,)), tf.keras.layers.Dense(4, activation='softmax') ]) import numpy as np sample_input = np.random.random((10, 8)) predictions = model(sample_input) predictions_shape = predictions.shape
The output shape matches the batch size and number of classes.
For 10 samples and 4 classes, the output shape is (10, 4), each row is a probability distribution over classes.
In training a multi-class classification model, what is a common effect of increasing the batch size too much?
Think about how batch size affects gradient noise and generalization.
Larger batch sizes reduce gradient noise, which can lead to convergence to sharp minima and worse generalization.
You trained a multi-class classification model with 3 classes using one-hot encoded labels. The model's accuracy stays around 33% (random guess). Which of the following is the most likely cause?
Check if the loss function matches the label format.
SparseCategoricalCrossentropy expects integer labels, not one-hot. Using it with one-hot labels causes poor training and accuracy.