TensorFlow Keras Model Building 1 — Questions and Answers
Question 1: Which Keras class is used to build a model layer-by-layer?
- tf.keras.Sequential (Correct answer)
- tf.keras.Parallel
- tf.keras.Linear
- tf.keras.Stack
Correct answer: tf.keras.Sequential
tf.keras.Sequential groups a linear stack of layers where each layer has exactly one input and one output tensor.
Question 2: What does model.compile() configure in Keras?
- Optimizer, loss function, and metrics (Correct answer)
- Layer weights and biases
- Input and output shapes
- Batch size and epochs
Correct answer: Optimizer, loss function, and metrics
model.compile() sets the training configuration including the optimizer, loss function, and evaluation metrics.
Question 3: Which Keras layer applies the ReLU activation function?
- tf.keras.layers.ReLU() (Correct answer)
- tf.keras.layers.Rectify()
- tf.keras.layers.Activate('relu')
- tf.keras.layers.MaxOut()
Correct answer: tf.keras.layers.ReLU()
tf.keras.layers.ReLU() is a dedicated layer that applies the Rectified Linear Unit activation.
Question 4: What is the purpose of the Dropout layer in Keras?
- Randomly sets input units to 0 during training to prevent overfitting (Correct answer)
- Removes unused layers
- Reduces model size
- Skips layers during inference
Correct answer: Randomly sets input units to 0 during training to prevent overfitting
Dropout randomly zeroes out a fraction of neurons during each training step as a regularization technique.
Question 5: Which Keras API allows building models with multiple inputs and outputs?
- Functional API (Correct answer)
- Sequential API
- Subclassing API
- Pipeline API
Correct answer: Functional API
The Keras Functional API enables creation of DAG-style models with multiple inputs, outputs, and shared layers.
Question 6: What does model.summary() display in Keras?
- Layer names, output shapes, and parameter counts (Correct answer)
- Training accuracy history
- Loss function details
- Dataset statistics
Correct answer: Layer names, output shapes, and parameter counts
model.summary() prints a table showing each layer, its output shape, and the number of trainable parameters.
Which Keras class is used to build a model layer-by-layer?