Deep Learning Interviews
The 50 neural-network concepts that come up most in internship and job interviews, from the perceptron to diffusion: what to study, how to study it and how to answer. With short answers linked to the section of the class that teaches each one, a quiz, a checklist of your progress and references to go further.
The curve that rises at epoch 8
A scene that will happen to you.
Tuesday, 10 a.m. Second round of the interview for the computer-vision internship you wanted most. The interviewer shares the screen: two plots from an image classifier someone on the team trained. The training loss falls from start to finish. The validation loss falls until epoch 8, stops and starts to rise; by epoch 30 it is above where it began. He asks:
"What would you do?"
He does not want one word. He wants to see how you think.
There is a weak answer ("it's overfitting, add dropout") and a strong one, which starts with a question back: "was validation measured in model.eval()? How many images are in each set, and does the split keep them apart?". A validation curve that is wrong because dropout was on, or because the sets leak into each other, leads to a wrong diagnosis however right it sounds.
The difference between the two answers is not memorizing more layer names. It is knowing how to connect what you studied: the two curves, bias and variance, early stopping, the regularizers from cheapest to most expensive and the golden rule of the split. This page lays out that path. At the end we come back to epoch 8 with the full answer.
What a deep learning interview looks like
Three kinds of question, three skills and the same logic: reasoning out loud with shapes, curves and numbers.
"Why divide by βdk?"
Checks that you explain in your own words, give the intuition and know where the idea breaks. There is almost always a small calculation behind it: a variance, a shape, a parameter count.
"The loss went NaN"
Checks diagnosis and next steps. There is no single answer: there is a line of reasoning that rules out the cheap causes first and proposes one experiment per hypothesis.
"Write the training loop"
Checks that you write a PyTorch loop without the classic bugs: zero_grad, model.eval(), torch.no_grad(), a softmax applied twice, shapes that do not match.
For an entry-level role, hardly anyone expects you to know this week's architecture. What sinks candidates are the basic traps: not knowing the shape of the tensors, mixing up training and validation loss, evaluating with dropout on, choosing hyperparameters by looking at the test set and reporting accuracy on an imbalanced problem. Avoid those five and you are already ahead of most.
What the interviewer assesses
| Aspect | Conceptual | Case | Code |
|---|---|---|---|
| Right answer | An explanation, with the math behind it | Several valid answers | Code that runs and actually trains |
| Focus | Intuition and where it breaks | Diagnosis and trade-offs | Shapes and the forwardβbackwardβstep cycle |
| Typical length | 1β3 min per question | 10β20 min | 15β30 min |
| Most common mistake | Reciting the definition without the trap | Switching architectures before looking at the data and the curves | Forgetting zero_grad or model.eval() |
| Where to practise | Key concepts | Case question | The training loop |
How to answer: 8 principles
They apply to all three kinds and are what turns a correct answer into a good one.
CrossEntropyLoss is applied twice; a perfect validation score is almost always a leak. This is where the interviewer sees depth. Practical tip: make transitions explicit. When you move from diagnosis to solution, say it out loud: "so the problem looks like variance; I'll propose three ways to reduce it, from cheapest to most expensive". The interviewer follows your structure and you do not get lost.
The training loop from memory
The most common coding question is also the shortest: "write the training of a network in PyTorch". Know how to write this without looking anything up and say what every line does.
model = nn.Sequential(nn.Linear(d, 64), nn.ReLU(), nn.Linear(64, n_classes))
opt = torch.optim.AdamW(model.parameters(), lr=1e-3, weight_decay=1e-2)
loss_fn = nn.CrossEntropyLoss() # takes raw logits: no softmax in the model
for epoch in range(epochs):
model.train() # dropout and BatchNorm in training mode
for xb, yb in train_loader: # xb: (B, d) Β· yb: (B,) with class indices
opt.zero_grad() # without it the gradients accumulate
loss = loss_fn(model(xb), yb) # logits: (B, n_classes)
loss.backward()
opt.step()
model.eval() # dropout off, BatchNorm uses its running statistics
with torch.no_grad(): # no graph: faster and no extra memory
val_loss = sum(loss_fn(model(xb), yb).item() * len(yb)
for xb, yb in val_loader) / len(val_loader.dataset)
Five lines that win the job
Forgetting zero_grad (gradients add up across steps); evaluating without model.eval() (dropout on during validation); applying softmax before CrossEntropyLoss; using MSE on the class index; mixing up dimensions, such as passing (B, 1) where the loss expects (B,).
Write the shape of every tensor
An nn.Linear(d, 64) takes (B, d) and returns (B, 64) with a (64, d) weight matrix. An nn.Conv2d(3, 16, 3) takes (B, 3, 32, 32) to (B, 16, 30, 30). Attention takes (B, n, d) to scores of (B, h, n, n). Whoever knows the shapes solves half the bugs by looking.
A case question, step by step
"How would you train a network toβ¦": the most common open question. The answer is the flow of any project with neural networks.
Always ask: "do I really need a network, or a network trained from scratch?" On small tables, gradient boosting usually wins. On images and text, starting from a pretrained model almost always beats training from scratch. Saying so before drawing the architecture shows you think about the problem, not the tool.
Quick diagnosis
The symptoms that show up in case questions, what they usually point to and what to do.
In case questions the interviewer describes a symptom and expects a diagnosis with the next step. Before proposing another architecture, rule out the cheap causes: a bug in the data pipeline, the learning rate, the evaluation mode, a leak between the sets.
| Symptom | Likely diagnosis | Next step |
|---|---|---|
| Loss turns NaN or inf | Learning rate above the stability bound, exploding gradient, log(0) in the loss | Divide the rate by 10, gradient clipping, use the loss that takes logits |
| Loss flat from step 0 | Rate far too small, dead ReLUs, broken data or labels | Rate Γ10; check the network memorizes 10 examples; look at one batch by hand |
| Initial loss far from ln C | Wrong initialization or input scale, softmax applied twice | Check the input scale, the initialization and the loss |
| Train falls, validation rises | Overfitting (variance) | Early stopping, weight decay, dropout, augmentation, more data |
| Train and validation both high and close | Underfitting (bias) | More capacity, longer training, less regularization |
| Validation better than training | Dropout or augmentation only in training, or a leak between sets | Check model.eval() and how the split was built |
| Deep sigmoid network does not learn | Vanishing gradient: each layer multiplies by at most 0.25 | ReLU, He initialization, residual connections, normalization |
| Many units always at zero | ReLUs killed by a high rate or a negative bias | Lower rate, LeakyReLU or GELU, check the initialization |
| Loss jitters violently | Batch too small or rate too high | Larger batch, momentum, a learning-rate schedule |
| Fine at first, diverges at epoch k | Rate too high for the sharper region training reached | Learning-rate schedule and warmup |
| Perfect validation score | A leak. Almost always a leak | Audit the split and the features |
"The loss went NaN at epoch 3"
Ask: which optimizer and which rate? Is there a log or a division in the loss? Mixed precision?
Rule out the cheap: any NaN in the input data? Does the loss use BCEWithLogitsLoss, or a sigmoid and a log applied separately?
Diagnose: if the gradient norm shoots up before the NaN, the step is numerically unstable.
Propose, cheapest first: rate Γ·10; gradient clipping; warmup; check the initialization and the input scale.
What to use when
The two loss curves: bias, variance and the best epoch.
Memorizing a small batch: tells a bug from a lack of capacity.
Gradient norm per layer: vanishing or exploding gradients.
Activation histogram: dead or saturated units.
Learning-rate sweep over powers of 10: the hyperparameter search that always pays off.
The 50 key concepts
The 50 topics in eight themes. Try to answer out loud before opening each theme. The numbers identify each topic in the checklist; the link at the end of each answer goes to the section of the class that teaches it.
BCEWithLogitsLoss). Multi-class: one logit per class and softmax cross-entropy (CrossEntropyLoss). Trap: PyTorch's losses already include the sigmoid or softmax; applying them before is a silent bug. β MLPmodel.eval() leaves dropout on during evaluation. β Regularizationmodel.eval() is forgotten. β Regularizationpos_weight or focal loss) if negatives dominate the gradient, balanced batches if batches come up empty of positives and, whenever possible, more positives. Trap: resampling and weighting the loss decalibrate the probabilities. β ImbalanceConv2d(3, 16, 3) has 448. Trap: most CNN bugs are shape bugs, nearly always at the first Linear after the Flatten: print the shape instead of guessing. β CNNsQuiz
Twenty-four interview-style questions, three per theme. Filter by theme to review only what you need.
Study plan
How to study, and a plan for the two weeks before an interview.
Out loud, to someone
If you cannot explain backpropagation to a classmate who missed the class, you have not learned it yet. Studying in pairs, one interviewing the other with the case questions, is the best practice there is.
The loop and the shapes from memory
Write without looking anything up the training loop, an MLP, a small CNN and an attention head, noting the shape of every tensor. Run it, break it on purpose (no zero_grad, no eval) and see what changes.
A day, a week, a month
Reviewing spaced out in time sticks far better than studying everything the night before. The study cards do it for you: the ones you miss come back first.
The checklist is your thermometer
Tick an item only when you can explain it without looking at anything, trap included. A checklist full of items ticked out of optimism does not help in the interview.
| Days | What to do |
|---|---|
| 1β2 | Fundamentals: perceptron, MLP and backpropagation by hand on a 2-layer network; the shape of every tensor |
| 3β4 | Optimization and depth: learning rate, Adam, initialization and residuals; play with the playground until you see the gradient vanish and come back |
| 5β6 | Regularization and evaluation: the two curves, dropout, BatchNorm, splitting, leakage and the metrics by hand |
| 7β8 | CNNs and attention: the shape and parameter arithmetic; one attention head by hand |
| 9β10 | Transformers, transfer learning, LLMs and generative models: one sentence and one trap per concept |
| 11β12 | Case questions in pairs, timed, with the quick diagnosis; the training loop written from memory |
| 13β14 | The full quiz and one last pass over the whole checklist, out loud |
To review in the course's format: the study cards, with a challenge mode built on situations; the cheat sheet, with the formulas of every class; and the playground, to see in practice what the case questions describe.
Checklist
The 50 concepts and the interview habits. Your progress is saved in this browser.
Back to epoch 8
The full answer to "what would you do?"
model.eval()? Are there images of the same object or the same person in both training and validation?" A wrong curve leads to a wrong diagnosis. Principle 1, items [18], [24].Four steps, one minute and nine of the 50 concepts used in a single answer. That is what the interviewer wanted to see: not what you memorized, but how you connect it.
References
To go deeper, grouped by kind.
Free books
Free online resources
Dataset and DataLoader, saving and loading models: the vocabulary that shows up in coding questions.