AI

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

ConceptOne-linerFollow-up they ask
Bias-varianceUnderfit = high bias; overfit = high varianceHow detect on learning curves?
RegularizationPenalize complexity — L1 sparsity, L2 weight decay, dropoutL1 vs L2 when?
Gradient descentSGD, mini-batch, Adam — update weights via loss gradientWhy Adam over SGD?
Cross-validationk-fold estimates generalizationLeakage if preprocess on full data?
Imbalanced dataSMOTE, class weights, threshold tuningWhy 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
LayerTypical effectParam intuition
Conv 3×3Local feature detectionC_out × C_in × 3 × 3 weights
MaxPool 2×2Translation invariance, downsamplingNo learnable params
BatchNormStabilize training, allow higher LRPer-channel scale/shift
ResNet blockSkip connection — gradient flows directlyEnables 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.
RNN unrolled
x₁h₁x₂h₂y
ArchitectureBest forLimitation
RNN/LSTMShort sequences, small data, time-seriesSlow training, long-range still hard
TransformerLong context, parallel training, NLP/SOTAQuadratic memory in sequence length
1D CNNFixed-length sequences, audioLimited 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 attentionAdd & NormFeed-forwardAdd & Norm
ComponentPurpose
Positional encodingInject order — sin/cos or learned
Multi-head attentionMultiple representation subspaces
Layer normStabilize activations
Encoder-decoderT5, original Transformer — seq2seq
Decoder-onlyGPT — autoregressive generation
Encoder-onlyBERT — classification, embeddings

⑤ Evaluation metrics

MetricFormula / meaningUse when
AccuracyCorrect / totalBalanced classes only
PrecisionTP / (TP+FP)Cost of false positives high (spam filter)
RecallTP / (TP+FN)Cost of false negatives high (cancer screening)
F1Harmonic mean P & RBalance both
ROC-AUCArea under TPR vs FPR curveThreshold-independent ranking
RMSE / MAERegression errorMAE 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

TechniqueWhat it doesWhen
Learning rate scheduleWarmup, cosine decay, step decayTransformers need warmup
Batch normalizationNormalize activations per batchCNNs; less common in LLMs (LayerNorm)
DropoutRandomly zero neurons — regularizationFC layers; 0.1–0.5 typical
Early stoppingStop when val loss stops improvingDefault regularization
Data augmentationFlip, crop, noise — synthetic diversityImages, text paraphrase
Gradient clippingCap gradient normRNNs, 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

QuestionStrong answer sketch
Explain backpropChain rule applied layer-by-layer; compute gradients via computational graph
Batch vs layer normBatchNorm 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: 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
CNNRNNtransformermetricstraininginterview