Keras and TensorFlow Interview Questions
1. What is the difference between TensorFlow and Keras?
TensorFlow is a low-level library for numerical computing, automatic differentiation and deployment. Keras is a high-level API for building and training neural networks. Keras 3 can run on TensorFlow, JAX or PyTorch as its backend.
2. What is a tensor?
A multi-dimensional array of numbers with a shape and a data type. Scalars, vectors, matrices and batches of images are all tensors.
3. Difference between tf.constant and tf.Variable?
A constant cannot be changed after creation. A Variable can be updated, which is how model weights are stored and trained.
4. Explain the Sequential API versus the Functional API.
Sequential is a plain stack of layers with one input and one output. The Functional API builds a graph of layers and supports multiple inputs and outputs, branches, shared layers and skip connections. Subclassing gives the most flexibility.
5. What do compile, fit, evaluate and predict do?
compile sets the optimizer, loss and metrics. fit trains the model. evaluate returns the loss and metrics on given data. predict returns model outputs for new inputs.
6. How do you choose the last layer and loss function?
Regression: Dense(1) with no activation and MSE. Binary: Dense(1, sigmoid) with binary crossentropy. Multi-class: Dense(n, softmax) with (sparse) categorical crossentropy. Multi-label: Dense(n, sigmoid) with binary crossentropy.
7. What is the difference between categorical and sparse categorical crossentropy?
Only the label format. Sparse categorical crossentropy expects integer class labels, categorical expects one-hot vectors.
8. What are callbacks? Name some useful ones.
Objects that run actions during training. Examples: EarlyStopping, ModelCheckpoint, ReduceLROnPlateau, TensorBoard and CSVLogger.
9. How do you save and load a model in Keras 3?
Use model.save('name.keras') and keras.models.load_model('name.keras'). Use save_weights with a .weights.h5 file for weights only and model.export() for the SavedModel format used in serving.
10. Why use tf.data?
It creates efficient input pipelines with shuffle, batch, map, cache and prefetch, so the GPU is not left waiting for data. It also handles datasets larger than memory.
11. What does GradientTape do?
It records operations during the forward pass so TensorFlow can compute gradients automatically. It is used in custom training loops.
12. What is transfer learning and how do you do it in Keras?
Reusing a model pretrained on a large dataset. Load a base from keras.applications with include_top=False, freeze it, add a new classifier head, train, and optionally fine-tune the top layers with a low learning rate.
13. What is the difference between trainable parameters and non-trainable parameters?
Trainable parameters are updated by the optimizer. Non-trainable ones are frozen layers or fixed statistics, such as the moving averages in batch normalization.
14. How can you make training faster?
Use a GPU, a tf.data pipeline with prefetch, a larger batch size, mixed precision, transfer learning, smaller inputs and multi-GPU strategies.
15. What is new in Keras 3?
Multi-backend support (TensorFlow, JAX, PyTorch), the keras.ops API for portable math, the .keras saving format and support for several data pipeline types. TensorFlow 2.16 and newer ship with Keras 3 by default.
16. How do you deploy a Keras model?
Options include a Flask or FastAPI service, TensorFlow Serving with a SavedModel from model.export, TensorFlow Lite for mobile and edge devices, and cloud model hosting.
Conclusion
These questions test practical framework knowledge. Be ready to explain choices, not only syntax.

