Practice 45 Keras interview questions on Keras 3, Sequential, Functional API, subclassing, layers, compile, fit, callbacks, saving, and transfer learning.
45 questions with answersKey Takeaways
Keras is a high-level API for deep learning models. It gives candidates a clean way to define layers, connect inputs and outputs, train with compile and fit, track metrics, save models, and reuse pretrained networks. In interviews, Keras questions test model API choice, tensor shapes, callbacks, training control, serialization, and whether you can keep model code readable without hiding important decisions.
Watch: Keras 3: Deep Learning made easy
Video: Keras 3: Deep Learning made easy (Keras contributor talk, YouTube)
Test yourself and earn a certificate
6 quick questions. Score 70%+ to download your Keras certificate.
Start here. These are the definitions and first-principle checks that open most rounds.
Keras 3 is a multi-backend version of Keras that can run on TensorFlow, JAX, and PyTorch backends.
The interview point is API portability, not that every backend detail becomes identical.
Keras 3 changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Watch a deeper explanation
Video: Keras 3: Deep Learning made easy (Keras contributor talk, YouTube)
Use Sequential when the model is a simple stack with one input and one output.
It is readable but limited for branches, shared layers, or multiple outputs.
Sequential model changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
model = keras.Sequential([
layers.Input(shape=(20,)),
layers.Dense(64, activation='relu'),
layers.Dense(1, activation='sigmoid')
])The Functional API connects inputs and outputs as a graph, so it fits multi-input, multi-output, and shared-layer models.
It is the best default for non-linear model topologies.
Functional API changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Subclassing is useful when the forward pass or layer behavior needs Python control that graph-style APIs do not express well.
It gives control but can make saving and inspection harder.
Subclassed model changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
| Answer part | What to say | Evidence to mention |
|---|---|---|
| Definition | Subclassed model in one direct sentence. | Official docs or course material |
| Use case | The work where it changes a decision. | Dataset, model, query, dashboard, or pipeline |
| Risk | What breaks when it is misunderstood. | Metric, log, test result, or review note |
A layer transforms input tensors into output tensors, often with trainable weights.
Dense, Conv2D, Dropout, BatchNormalization, and Embedding are common layers.
Layer changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Watch a deeper explanation
Video: TensorFlow beginner tutorial: build a neural net (TensorFlow, YouTube)
compile sets the optimizer, loss, metrics, and training behavior used by fit.
These choices must match target type and output activation.
Model compile changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
fit trains a compiled model over batches of data for one or more epochs.
It can accept arrays, datasets, generators, validation data, and callbacks.
model.fit changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Choose the loss by task: binary cross-entropy for binary classification, categorical variants for multiclass, and MAE or MSE for regression.
Output activation and label encoding must agree.
Loss function changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
An optimizer updates trainable weights using gradients from the loss.
Adam is common, but optimizer choice and learning rate still need validation.
Optimizer changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
A callback runs logic during training, such as saving checkpoints, stopping early, logging metrics, or changing learning rate.
Callbacks keep training control out of the model architecture.
Callback changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
ModelCheckpoint saves model weights or full artifacts during training, often only when validation metrics improve.
It protects long training runs and keeps the best version.
ModelCheckpoint changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
EarlyStopping stops training when a monitored metric stops improving for a set patience.
It helps reduce overfitting and wasted training time.
EarlyStopping changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Transfer learning starts from a pretrained model and adapts it to a new task.
Usually you train a new head first, then fine-tune selected base layers.
Transfer learning changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Watch a deeper explanation
Video: TensorFlow 2.0 complete course (freeCodeCamp.org, YouTube)
Keras can save full models, weights, and configuration so they can be loaded for training or inference.
Custom layers or losses need proper serialization support.
Saving and loading changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Write a custom layer when repeated model logic has trainable weights or special tensor operations not covered by built-in layers.
Implement build, call, and serialization methods when needed.
Custom layer changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
These questions test whether you can apply the topic to real data, real code, and messy constraints.
Define input shape, add hidden layers, use a sigmoid output, compile with binary cross-entropy, track a relevant metric, and fit with validation data.
If classes are imbalanced, mention precision, recall, PR AUC, class weights, or threshold tuning.
Use the Functional API, create two Input tensors, process each branch, concatenate features, and connect the output.
Sequential is the wrong API for this shape.
functional model changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Use ModelCheckpoint, EarlyStopping, TensorBoard, and learning-rate scheduling when the run needs those controls.
Do not add callbacks by habit. The job each one does.
train with callbacks changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check model.summary, input shape, batch dimension, layer output shapes, flattening, and label shape.
The expected shape at every boundary.
debug shape mismatch changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Use validation curves, dropout, regularization, augmentation, early stopping, smaller model size, or more data.
Pick changes based on evidence, not a checklist.
fix overfitting changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Use class weights, sampling, threshold tuning, and metrics such as precision, recall, F1, or PR AUC.
Accuracy alone can look good while the model misses rare positives.
handle class imbalance changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Freeze the base, train the new head, unfreeze selected layers, lower the learning rate, and monitor validation metrics.
Unfreezing too much too early can destroy useful pretrained features.
fine-tune pretrained model changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Register or serialize custom objects, save the model artifact, and test loading it in a clean process.
A model is not saved safely until reload works.
save custom model changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Write a custom metric when built-in metrics do not match the business error or evaluation rule.
Keep training loss and reporting metric separate when needed.
custom metric changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Skip fit when the training step has unusual losses, multiple optimizers, special updates, or research logic.
The trade-off is more control and more code to test.
custom training loop changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Watch a deeper explanation
Video: Build a neural network with TensorFlow, Keras, and Python (TensorFlow tutorial, YouTube)
a reasonable default, watch loss curves, try schedules, and reduce when validation stops improving comes first.
Too high can cause NaN or unstable loss. Too low can stall learning.
learning rate issue changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Use Keras preprocessing layers or a versioned input pipeline so training and inference apply the same transformations.
Mismatched preprocessing causes serving bugs.
input preprocessing changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Use the Functional API, name outputs, assign losses and loss weights, and track metrics per output.
Loss weighting decides what the model optimizes.
multi-output model changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Use model.summary, layer names, output shapes, trainable parameter counts, history metrics, and saved artifacts.
Inspection catches many design mistakes before training.
model inspection changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Explain which backend the team uses, what libraries it needs, and whether portability matters for the project.
Do not promise backend switching without testing custom code.
backend choice changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Advanced rounds test trade-offs, failure modes, and whether the decision can hold up under production pressure.
The dataset is likely imbalanced, so accuracy is the wrong primary metric.
Use precision, recall, PR AUC, cost-based metrics, and threshold analysis.
metric looks good changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check Keras version, backend, custom objects, serialization methods, input signature, and artifact path.
Always test reload outside the notebook.
model will not load changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check labels, loss, output activation, learning rate, data scaling, trainable layers, and optimizer setup.
A frozen model head or wrong label encoding is common.
training stuck changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check learning rate, input values, labels, normalization, invalid operations, and exploding gradients.
Run one tiny batch and inspect tensors.
NaN loss changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
They may be hiding simple graph structure and making serialization harder.
Subclassing is useful, but it should have a reason.
subclassing overuse changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
The base may have been unfrozen too aggressively or trained with too high a learning rate.
Train the head first, then fine-tune carefully.
bad transfer learning changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Tune patience, monitored metric, min_delta, validation quality, and learning-rate schedule.
The callback should fit the metric noise.
callback stops too soon changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
For single-label multiclass classification, softmax usually fits better.
Sigmoid fits independent multi-label outputs.
wrong output activation changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
The model may overfit, train slowly, and cost more to serve.
Dense layers after flattening image features often cause this.
huge parameter count changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check preprocessing, feature order, model version, input dtype, label mapping, and training-serving mismatch.
The model may be right and the serving path wrong.
serving skew changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Serialization or config handling may be incomplete.
Custom layers need reload tests.
custom layer bug changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Data leakage, duplicate samples, bad split logic, or preprocessing fitted on all data.
Audit the split and data pipeline.
validation leakage changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check backend-supported ops, custom layers, random behavior, metrics, saving path, and numeric differences.
Portability is practical only after tests pass.
backend portability changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
The input pipeline may be slow due to decoding, augmentation, batching, or storage reads.
Profile data loading before changing the model.
slow input pipeline changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Ask about API choice, shapes, labels, loss, metrics, callbacks, validation split, saving, reload tests, and serving contract.
Those questions catch most production failures.
senior review changes Keras decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Most Keras interviews ask which model API you would choose. The best technical choice uses the simplest API that still fits the model shape and training need.
| API | Use when | Strength | Watch out |
|---|---|---|---|
| Sequential | A straight stack of layers | Fast to read and write | Not enough for branched graphs |
| Functional API | Multiple inputs, outputs, or shared layers | Clear graph structure | Needs careful shape tracking |
| Subclassing | Custom forward pass or unusual behavior | Full control | Harder to inspect and serialize |
| Custom training loop | Custom loss or update logic | Fine control | More code to test |
Keras answer signals
Good answers choose the right level of control.
Prepare by building a small classifier with all three Keras APIs, then explain why you would choose one for a real project.
Keras interview prep flow
Most rounds reward clear reasoning more than memorized phrasing.
A strong Keras answer starts with the model shape and training goal. Say why Sequential, Functional API, or subclassing fits the problem, which loss and metric match the target, how callbacks protect training, and how the model will be saved. production-ready answers mention custom layers, backend portability in Keras 3, input pipelines, model signatures, and training-serving consistency.
A plain stack does not need subclassing. Over-custom code makes interviews harder to score.
Accuracy can hide class imbalance. Strong technical coverage picks metrics based on the business error.
Custom layers, losses, and metrics need serialization planning.
EarlyStopping, ModelCheckpoint, TensorBoard, and learning-rate callbacks solve different training problems.
6 questions, about 4 minutes. Score 70% or higher to earn a shareable certificate.
Use this Keras bank for model-building answers, then practice Python and model debugging tasks with Hyring's AI Coding Interviewer.
See Hyring AI Coding Interviewer