All jobs / Data science / ML / AI

Deep Learning interview questions

Deep Learning questions a Data science / ML / AI can be asked, from first job to senior. Open one to see the strongest answer and why it works.

  1. Why does a neural network need a non-linear activation between its layers?

    The strongest answer: Without one, stacking linear layers collapses to a single linear map — it can only draw straight boundaries; the non-linearity (ReLU, sigmoid, GELU) is what lets depth compose curved, complex functions

    Why it works: Exactly — two linear layers are one linear layer; non-linearity is what buys expressiveness from depth.

    • Linear stacked on linear is linear.
    • Non-linearity buys curved boundaries.
    • Depth composes functions through it.
    • ReLU, sigmoid, GELU are the usual choices.
  2. What does backpropagation actually compute, and what does the optimiser do with it?

    The strongest answer: The gradient of the loss with respect to every parameter, by applying the chain rule backwards through the layers and reusing intermediate results; the optimiser then updates each parameter against its gradient

    Why it works: Right — backprop is efficient chain-rule differentiation; the update step is the optimiser’s job (SGD, Adam), a separate thing.

    • Backprop: gradients via the chain rule.
    • Backward through the layers.
    • Optimiser applies the update.
    • Two steps, two names.
  3. Your PyTorch model scores noticeably worse and slower during validation than you expect, and the validation numbers wobble between identical runs. What did you probably forget?

    The strongest answer: model.eval() and torch.no_grad(): eval switches dropout and batch-norm to inference behaviour, no_grad stops building the autograd graph — without them dropout is still active and every batch stores gradients

    Why it works: Exactly — eval mode fixes the behaviour, no_grad fixes the memory and speed. The same applies to TensorFlow’s training flag.

    • Inference: eval mode plus no_grad.
    • eval: dropout and batch-norm off.
    • no_grad: no graph, less memory.
    • Same idea in every framework.
  4. Why use convolutional layers for images instead of flattening the pixels into a fully connected network?

    The strongest answer: A convolution slides a small shared filter over the image, so it learns local patterns once and finds them anywhere — far fewer parameters, translation-robust, and stacked layers build edges into parts into objects

    Why it works: Right — weight sharing and locality are the inductive biases; that is why a CNN learns from far fewer images than a dense net.

    • Shared filter slides over the input.
    • Locality and weight sharing.
    • Same pattern found anywhere.
    • Layers compose edges into objects.
  5. What does self-attention do in a transformer, and why did it displace recurrent networks for language?

    The strongest answer: Each token weights every other token and takes a weighted mix of them, so any two positions connect in one step and the sequence trains in parallel; the cost is quadratic in length, and position must be added explicitly

    Why it works: Exactly — direct long-range paths and parallelism are the wins; the quadratic cost is why context length is still engineered around.

    • Weighted mix over all tokens.
    • Any two positions in one step.
    • Parallel training, no recurrence.
    • Quadratic cost; positions added explicitly.
  6. One head ranks, another classifies toxicity, and they fight on the same backbone. What do you do?

    The strongest answer: Name which decision is allowed to win on a conflict, or split the models — a blended loss with no owner is how both jobs get worse

    Why it works: Exactly. Multi-task is a product negotiation. Unowned blends hide the loser.

    • Give conflict an owner or split models.
    • Do not blend losses without a decision.
    • Do not let Slack pick the weight.
    • Do not hide the losing task.