Deep Learning Interview Questions and Answers
Deep learning interviews probe whether you can make training work and recognise when it fails. Six questions are answered by training a small PyTorch network on 13,611 real bean measurements, then breaking it on purpose: unscaled inputs, bad learning rates, overfitting, dropout left on, and gradients never cleared.
GloryTecks Team
Training & Placement Faculty
Last updated: 9 October 2026
Deep learning interview questions often sound theoretical, about vanishing gradients, dropout and learning rates, but the interviewer usually wants to know one practical thing: can you get a network to train, and can you tell what went wrong when it does not? The answers below come from training a small network on real data and then breaking it on purpose, so each failure has a number attached.
The data is the UCI Dry Bean set: 13,611 beans of seven varieties, each described by 16 shape measurements taken from images (UCI: Dry Bean). The model is a two-layer PyTorch network. It runs on a single CPU thread with fixed seeds so that the numbers repeat; PyTorch itself warns that results can still differ across versions and hardware (PyTorch: reproducibility).
import numpy as np
import pandas as pd
import torch
from sklearn.ensemble import HistGradientBoostingClassifier
from sklearn.model_selection import train_test_split
from torch import nn
torch.set_num_threads(1) # single-threaded CPU, so every run repeats exactly
lines = [l for l in open("Dry_Bean_Dataset.arff") if l.strip() and l[0] not in "@%" and "," in l]
beans = pd.DataFrame([l.strip().split(",") for l in lines]) # UCI Dry Bean: 16 shape features, 7 varieties
X_raw, y_raw = beans.iloc[:, :-1].astype(float).to_numpy(), beans.iloc[:, -1].to_numpy()
classes = sorted(set(y_raw))
y = np.array([classes.index(c) for c in y_raw])
X_tr, X_te, y_tr, y_te = train_test_split(X_raw, y, test_size=0.3, stratify=y, random_state=0)
mu, sd = X_tr.mean(0), X_tr.std(0)
scale = lambda a: (a - mu) / sd # statistics from the training split only
print(f"{len(y):,} beans, {X_raw.shape[1]} features, {len(classes)} varieties; feature ranges from {X_raw.min():.4f} to {X_raw.max():,.0f}")
def train(X, y, lr=1e-2, epochs=60, hidden=64, dropout=0.0, weight_decay=0.0, zero_grad=True, seed=0):
torch.manual_seed(seed)
net = nn.Sequential(nn.Linear(X.shape[1], hidden), nn.ReLU(), nn.Dropout(dropout),
nn.Linear(hidden, hidden), nn.ReLU(), nn.Dropout(dropout), nn.Linear(hidden, len(classes)))
opt = torch.optim.Adam(net.parameters(), lr=lr, weight_decay=weight_decay)
Xt, yt = torch.tensor(X, dtype=torch.float32), torch.tensor(y)
loss_fn = nn.CrossEntropyLoss() # expects raw scores (logits)
for _ in range(epochs):
for idx in torch.randperm(len(yt)).split(256):
if zero_grad:
opt.zero_grad()
out = net(Xt[idx])
loss = loss_fn(out, yt[idx])
loss.backward()
opt.step()
return net
def acc(net, X, y, mode="eval"):
net.train() if mode == "train" else net.eval()
with torch.no_grad():
return (net(torch.tensor(X, dtype=torch.float32)).argmax(1).numpy() == y).mean()
gbm = HistGradientBoostingClassifier(random_state=0).fit(X_tr, y_tr)
base = train(scale(X_tr), y_tr)
print(f"\nD1 baseline first: gradient boosting {gbm.score(X_te, y_te):.3f} | neural net, scaled inputs {acc(base, scale(X_te), y_te):.3f}")
print(f"D2 the same net on unscaled inputs: {acc(train(X_tr, y_tr), X_te, y_te):.3f}")
print("D3 learning rate:", {lr: round(float(acc(train(scale(X_tr), y_tr, lr=lr, epochs=20), scale(X_te), y_te)), 3) for lr in (1e-5, 1e-3, 1e-2, 1.0)})
small_X, small_y = scale(X_tr[:300]), y_tr[:300]
for name, kw in (("no regularisation", {}), ("dropout 0.3 + weight decay", {"dropout": 0.3, "weight_decay": 1e-3})):
net = train(small_X, small_y, epochs=300, hidden=256, **kw)
print(f"D4 300 training beans, {name}: train {acc(net, small_X, small_y):.3f} | test {acc(net, scale(X_te), y_te):.3f}")
drop = train(scale(X_tr), y_tr, dropout=0.3)
runs = [acc(drop, scale(X_te), y_te, mode="train") for _ in range(3)]
print(f"D5 dropout net, eval() mode: {acc(drop, scale(X_te), y_te):.3f} twice -> {acc(drop, scale(X_te), y_te):.3f} | "
f"left in train() mode: {[round(float(r), 3) for r in runs]}")
print(f"D6 forgetting optimizer.zero_grad(): {acc(train(scale(X_tr), y_tr, zero_grad=False), scale(X_te), y_te):.3f} "
f"| share of the most common variety: {np.bincount(y_te).max() / len(y_te):.3f}")13,611 beans, 16 features, 7 varieties; feature ranges from 0.0006 to 263,261
D1 baseline first: gradient boosting 0.926 | neural net, scaled inputs 0.929
D2 the same net on unscaled inputs: 0.261
D3 learning rate: {1e-05: 0.42, 0.001: 0.931, 0.01: 0.926, 1.0: 0.149}
D4 300 training beans, no regularisation: train 1.000 | test 0.895
D4 300 training beans, dropout 0.3 + weight decay: train 0.973 | test 0.905
D5 dropout net, eval() mode: 0.930 twice -> 0.930 | left in train() mode: [0.923, 0.925, 0.925]
D6 forgetting optimizer.zero_grad(): 0.261 | share of the most common variety: 0.261D1. Do you need deep learning for this problem?
Start with a baseline. Gradient boosting reached 92.6% accuracy with default settings; the neural network reached 92.9%. On tabular data like this, the two are often close, and boosting needs no scaling, fewer settings and less tuning. Saying "I would try boosting first, then a network if it adds something" is a strong opening, not a weak one. Deep learning earns its place on images, audio and text, where it learns the features itself, and on very large datasets where its extra capacity pays off.
D2. Why does input scaling matter for neural networks?
Because gradient descent struggles when inputs differ wildly in scale. These features range from 0.0006 to 263,261. Trained on raw values, the same network reached 26.1% accuracy: exactly the share of the most common variety, so it had learned to predict one class. Standardising each feature with the training split's mean and standard deviation fixed it. Note "the training split's": computing the statistics on all data leaks the test set into training.
D3. What happens if the learning rate is wrong?
Too small and training crawls: after 20 epochs, a rate of 0.00001 reached only 42.0%. Too large and it diverges: a rate of 1.0 ended at 14.9%, worse than always guessing the most common class. Rates of 0.001 and 0.01 both worked, at 93.1% and 92.6%. In an interview, describe the symptoms: a loss that barely moves means too small; a loss that jumps or becomes NaN means too large. A learning-rate range test or a scheduler is the practical fix.
D4. How do you recognise and reduce overfitting?
Compare training and test performance. With only 300 training beans and a wide network, training accuracy reached 100% while test accuracy was 89.5%: the network memorised. Adding dropout and weight decay lowered training accuracy to 97.3% and raised test accuracy to 90.5%. The gap narrowed, but the bigger fix is usually more data. All 9,527 training beans gave 92.9% with no regularisation at all.
D5. What does model.eval() do?
It switches layers such as dropout and batch normalisation to inference behaviour (PyTorch: Module.eval). During training, dropout zeroes random units on every forward pass (PyTorch: Dropout). In eval mode, the dropout network gave 93.0% on two identical passes. Left in training mode, three passes over the same test data gave 92.3%, 92.5% and 92.5%: lower, and different every time. Forgetting eval() is a common cause of predictions that change between calls.
D6. Why must you call optimizer.zero_grad()?
Because PyTorch adds new gradients to the old ones instead of replacing them (PyTorch: zeroing gradients). Without zero_grad(), each step used the sum of every gradient so far, the updates grew without control, and the network again collapsed to 26.1%, the share of the most common class. Accumulation is occasionally deliberate, to simulate a larger batch, but then you zero the gradients every few steps on purpose.
Two more questions to expect
- Why softmax outputs, but logits for the loss?
CrossEntropyLossexpects raw scores and applies the softmax internally (PyTorch: CrossEntropyLoss); apply softmax yourself only when you need probabilities at inference. - What are vanishing gradients? In deep networks with saturating activations such as sigmoid, gradients shrink layer by layer and early layers stop learning. ReLU activations, careful initialisation, normalisation and residual connections all help.
How to answer deep learning questions
- Name the symptom, then the cause: collapse to one class, divergence, a large train-test gap.
- Compare with a simple baseline before defending a network.
- Debug on a tiny batch first: a correct network should drive the loss on a few dozen examples close to zero. If it cannot, the bug is in the code, not the data or the settings.
- Know the training loop by heart: zero gradients, forward, loss, backward, step, and
eval()before predicting.
Image-specific questions are in computer vision interview questions and text in NLP interview questions. Hardware and efficiency are covered in GPU vs CPU for ML and model compression; the full round is in data science interview questions and answers.
What are common deep learning interview questions?
Why did my neural network predict only one class?
How do I prevent overfitting in a neural network?
Is deep learning better than gradient boosting for tabular data?
Deep learning is part of the Data Science course.
Sources
- Dry Bean dataset (UCI Machine Learning Repository) — UCI Machine Learning Repository
- CrossEntropyLoss (PyTorch 2.14 documentation) — PyTorch
- Dropout (PyTorch 2.14 documentation) — PyTorch
- Module.eval (PyTorch 2.14 documentation) — PyTorch
- Zeroing out gradients in PyTorch (PyTorch tutorials) — PyTorch
- Reproducibility (PyTorch 2.14 documentation) — PyTorch
GloryTecks Team
Training & Placement Faculty
The GloryTecks faculty team mentors learners across Data Science, AI and Data Engineering, with a focus on real-time projects and placement readiness in Hyderabad.
Want to master Interview Questions?
Join GloryTecks’ expert-led Data Science training in Hyderabad with real-time projects and 100% placement support.
Related articles
SQL Interview Questions: Top 50 with Answers
Fifty SQL interview questions with answers checked on PostgreSQL, DuckDB and SQLite against one small practice schema: evaluation order, NULL logic, joins and fan-out, window functions, dates, and performance, including where the three engines disagree.
Python Interview Questions for Data Roles
The plain-Python coding tasks data-analyst and data-engineer interviews use, without pandas: counting, deduplicating, grouping, streaming large files, flattening JSON, joining, and the bugs interviewers plant. Each has a worked solution and the follow-up questions to expect.
Data Science Interview Questions and Answers 2026
A data science interview is several interviews in one: statistics, machine learning, coding, product sense and a take-home. This guide maps each round with model answers, then works a churn take-home on real telecom data, including the checks that separate a strong submission from a high score.