TensorFlow & Keras MCQ · test your framework knowledge
From Sequential models to custom training loops – 15 questions covering layers, compile/fit, callbacks, and best practices.
TensorFlow & Keras: the industry standard for deep learning
TensorFlow 2.x integrates Keras as its high-level API, making model building intuitive. This MCQ covers essential classes like tf.keras.Sequential, the Functional API for complex topologies, callbacks (EarlyStopping, ModelCheckpoint), and core concepts like eager execution and AutoGraph.
Why tf.keras?
It combines the flexibility of TensorFlow with the simplicity of Keras: you can go from quick prototyping (Sequential) to fully custom training loops while staying in the same ecosystem.
TensorFlow/Keras glossary – key concepts
Sequential model
Linear stack of layers. Ideal for most feedforward networks. tf.keras.Sequential([Dense(64, activation='relu'), Dense(10)])
Functional API
Build non‑linear topologies: multi‑input, multi‑output, residual connections. Uses layer call syntax.
Callbacks
Utilities like EarlyStopping, ModelCheckpoint, TensorBoard that hook into training.
compile & fit
model.compile(optimizer='adam', loss='mse') – configures learning process. fit() trains the model.
Eager execution
Default in TF2.x: operations run immediately, intuitive debugging. Can still build graphs via @tf.function.
tf.data.Dataset
Efficient input pipelines: batching, shuffling, prefetch. Integrates seamlessly with Keras.
Custom training loop
Use tf.GradientTape for fine‑grained control. Essential for research.
# Typical Keras pipeline
model = tf.keras.Sequential([
layers.Dense(128, activation='relu'),
layers.Dropout(0.2),
layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['acc'])
model.fit(train_ds, validation_data=val_ds, epochs=10, callbacks=[EarlyStopping()])
model.fit() vs custom loops, and how callbacks work. This MCQ covers these core distinctions.
Common TensorFlow interview questions
- What is the difference between TensorFlow 1.x and 2.x regarding execution?
- How do you create a multi‑input model in Keras?
- Explain the role of
@tf.functionand AutoGraph. - What is the purpose of the
validation_splitparameter infit()? - How can you implement early stopping without a callback?
- Describe how
tf.GradientTapeworks.