ML / Deep Learning Interview Guide
CNN, RNN, Transformers, metrics, training pitfalls, and the Q&A senior ML interviews expect.
Interview tip For architecture questions: input shape → layers → output shape → loss → why this beats baseline.
① ML fundamentals — must know cold
| Concept | One-liner | Follow-up they ask |
|---|---|---|
| Bias-variance | Underfit = high bias; overfit = high variance | How detect on learning curves? |
| Regularization | Penalize complexity — L1 sparsity, L2 weight decay, dropout | L1 vs L2 when? |
| Gradient descent | SGD, mini-batch, Adam — update weights via loss gradient | Why Adam over SGD? |
| Cross-validation | k-fold estimates generalization | Leakage if preprocess on full data? |
| Imbalanced data | SMOTE, class weights, threshold tuning | Why accuracy misleading? |
Learning curves: train loss ↓ but val loss ↑ = overfitting → more data, regularization, simpler model. Both high = underfitting → bigger model, more features, train longer.
② CNN — convolutional neural networks
Conv layer — learn local filters (edges, textures, parts)
Pooling — reduce spatial size (max/avg pool)
Stack depth — VGG, ResNet skip connections solve vanishing gradient
Output — flatten + FC layers or global average pool
Use cases — image classification, detection, segmentation
| Layer | Typical effect | Param intuition |
|---|---|---|
| Conv 3×3 | Local feature detection | C_out × C_in × 3 × 3 weights |
| MaxPool 2×2 | Translation invariance, downsampling | No learnable params |
| BatchNorm | Stabilize training, allow higher LR | Per-channel scale/shift |
| ResNet block | Skip connection — gradient flows directly | Enables very deep nets |
Interview: "Why CNN for images?" — local connectivity, parameter sharing, translation equivariance.
③ RNN / LSTM — sequential models
RNN: hidden state carries information across time steps. Problem: vanishing/exploding gradients on long sequences.
LSTM/GRU: gating mechanisms (forget, input, output) preserve long-range dependencies. Still sequential — hard to parallelize on GPU.
LSTM/GRU: gating mechanisms (forget, input, output) preserve long-range dependencies. Still sequential — hard to parallelize on GPU.
RNN unrolled
x₁→h₁→x₂→h₂→y
| Architecture | Best for | Limitation |
|---|---|---|
| RNN/LSTM | Short sequences, small data, time-series | Slow training, long-range still hard |
| Transformer | Long context, parallel training, NLP/SOTA | Quadratic memory in sequence length |
| 1D CNN | Fixed-length sequences, audio | Limited receptive field without dilated conv |
④ Transformers & attention
Self-attention: each token attends to all tokens — computes Query, Key, Value; attention weights = softmax(QKᵀ/√d); output = weighted sum of Values. Parallelizable; captures long-range deps.
Transformer block
Multi-head attention→Add & Norm→Feed-forward→Add & Norm
| Component | Purpose |
|---|---|
| Positional encoding | Inject order — sin/cos or learned |
| Multi-head attention | Multiple representation subspaces |
| Layer norm | Stabilize activations |
| Encoder-decoder | T5, original Transformer — seq2seq |
| Decoder-only | GPT — autoregressive generation |
| Encoder-only | BERT — classification, embeddings |
⑤ Evaluation metrics
| Metric | Formula / meaning | Use when |
|---|---|---|
| Accuracy | Correct / total | Balanced classes only |
| Precision | TP / (TP+FP) | Cost of false positives high (spam filter) |
| Recall | TP / (TP+FN) | Cost of false negatives high (cancer screening) |
| F1 | Harmonic mean P & R | Balance both |
| ROC-AUC | Area under TPR vs FPR curve | Threshold-independent ranking |
| RMSE / MAE | Regression error | MAE robust to outliers |
Confusion matrix is your friend — draw it in interviews. Calibration: predicted probabilities match true frequencies — important for threshold tuning.
⑥ Training — optimization & pitfalls
| Technique | What it does | When |
|---|---|---|
| Learning rate schedule | Warmup, cosine decay, step decay | Transformers need warmup |
| Batch normalization | Normalize activations per batch | CNNs; less common in LLMs (LayerNorm) |
| Dropout | Randomly zero neurons — regularization | FC layers; 0.1–0.5 typical |
| Early stopping | Stop when val loss stops improving | Default regularization |
| Data augmentation | Flip, crop, noise — synthetic diversity | Images, text paraphrase |
| Gradient clipping | Cap gradient norm | RNNs, unstable training |
Debugging: loss NaN → LR too high, bad initialization, label errors. Val train gap → overfit. Both flat → underfit or bug in pipeline.
⑦ Model serving (system design angle)
Model serving at scale
Clients
API Gateway + batching
Model servers (GPU pool)
Feature store / embedding cache
- Batch requests for GPU efficiency (dynamic batching)
- Quantization (INT8) and distillation for latency
- Cache frequent queries / embeddings
- A/B test model versions with shadow traffic
- Monitor: latency p99, throughput, prediction drift
⑧ Interview Q&A — rapid fire
| Question | Strong answer sketch |
|---|---|
| Explain backprop | Chain rule applied layer-by-layer; compute gradients via computational graph |
| Batch vs layer norm | BatchNorm across batch dim; LayerNorm across features — LLMs use LayerNorm |
| Why transformers beat RNNs? | Parallel training, long-range attention, scaled pretraining |
| Transfer learning? | Pretrain on large dataset, fine-tune head on small target task |
| Overfitting fixes? | More data, regularization, dropout, simpler model, early stopping |
| Attention complexity? | O(n²) in sequence length — sparse/local attention variants |
⑨ Whiteboard problem — fraud detection metrics
Scenario: fraud is 0.1% of transactions. False negative = lost money. False positive = customer friction.
Answer structure: Don't use accuracy (99.9% by predicting all legit). Optimize recall at acceptable precision, or cost-sensitive metric:
Answer structure: Don't use accuracy (99.9% by predicting all legit). Optimize recall at acceptable precision, or cost-sensitive metric:
Cost = 10×FN + 1×FP. Use PR curve not ROC when imbalanced. Threshold tune on validation set with business cost matrix.⑩ Revision checklist
- Explained bias-variance with learning curve interpretation
- Compared CNN, RNN, Transformer with use cases
- Drew confusion matrix and picked metrics for imbalanced problem
- Named 3 overfitting fixes and 3 training debug steps
- Described attention mechanism without hand-waving
- Outlined model serving architecture for latency SLA