← LinkedIn Interview Insights

LinkedIn·Data Scientist·Technical Phone Screen·Senior

SeniorPrefer not to say
May 2026

Summary

LinkedIn Data Scientist whiteboard round, heavy on math. Four parts back to back: logistic regression from scratch, backprop derivations, mini-batch pseudocode, and Adam internals. Not a conceptual chat at all, they wanted chain-rule steps on the board.

Questions Asked (8)

Q1

Walk through logistic regression for binary classification: write the model, the sigmoid, and the binary cross-entropy loss for a single example and for a batch, then derive the gradient with respect to the weights and bias from first principles.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The derivation itself isn't hard but I kept second-guessing whether to show the sigmoid derivative cancellation explicitly or just state it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clearly stating the logistic regression model for binary classification, including the linear combination and sigmoid function. Then write the binary cross-entropy loss for a single example and extend it to a batch. Finally, derive the gradients with respect to weights and bias step-by-step, showing the chain rule and simplifying using the sigmoid derivative.

Pro tip: Emphasize the probabilistic interpretation: the sigmoid outputs P(y=1|x), and minimizing binary cross-entropy is equivalent to maximizing the likelihood. This shows depth beyond just memorizing formulas.

1. Define the model and sigmoid

Write the linear combination z = w^T x + b and the sigmoid activation σ(z) = 1/(1+e^{-z}). State that the predicted probability is ŷ = σ(z).

2. Write the loss for a single example

For a single example (x, y) with y ∈ {0,1}, the binary cross-entropy loss is L = -[y log(ŷ) + (1-y) log(1-ŷ)].

3. Extend to batch loss

For a batch of N examples, the total loss is the average (or sum) of individual losses: J = -(1/N) Σ_{i=1}^N [y_i log(ŷ_i) + (1-y_i) log(1-ŷ_i)].

4. Derive gradients for a single example

Compute ∂L/∂z = ŷ - y using the chain rule and the fact that σ'(z) = σ(z)(1-σ(z)). Then ∂L/∂w = (ŷ - y) x and ∂L/∂b = ŷ - y.

5. Extend gradients to batch

For a batch, the gradient of the average loss is the average of the per-example gradients: ∂J/∂w = (1/N) Σ (ŷ_i - y_i) x_i and ∂J/∂b = (1/N) Σ (ŷ_i - y_i).

Key Points to Mention

  • Sigmoid function and its derivative: σ'(z) = σ(z)(1-σ(z))
  • Binary cross-entropy loss formula for single example and batch
  • Chain rule application to derive gradient with respect to z
  • Gradient with respect to weights: (ŷ - y) x
  • Gradient with respect to bias: ŷ - y
  • Batch gradient as average of per-example gradients

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Show that logistic regression is a special case of a neural network, then write the full forward pass and backpropagation equations for an L-layer feedforward network, including how gradients flow through each layer.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

I said the L=1 thing confidently and that landed well.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by showing that logistic regression is equivalent to a single-layer neural network with a sigmoid activation and binary cross-entropy loss. Then, systematically derive the forward pass and backpropagation equations for a general L-layer feedforward network, emphasizing the chain rule and gradient flow. Use clear notation and explain each step to demonstrate deep understanding.

Pro tip: Use consistent notation (e.g., a^[l] for activations, z^[l] for pre-activations) and explicitly state the shapes of all matrices and vectors. This shows attention to detail and helps avoid confusion during the derivation.

1. Logistic Regression as a Neural Network

Show that logistic regression is a single-layer neural network with one output unit and sigmoid activation. Write the forward pass and loss function, and note that the gradient descent update matches that of logistic regression.

2. Define Network Architecture and Notation

Introduce the L-layer feedforward network: input layer (layer 0), hidden layers 1 to L-1, and output layer L. Define weights W^[l], biases b^[l], pre-activations z^[l], and activations a^[l] for each layer.

3. Forward Propagation Equations

Write the forward pass equations for each layer: z^[l] = W^[l] a^[l-1] + b^[l], a^[l] = g^[l](z^[l]), where g^[l] is the activation function. Specify the output layer activation and loss function (e.g., sigmoid + binary cross-entropy or softmax + categorical cross-entropy).

4. Backpropagation and Gradient Flow

Derive the backpropagation equations: compute the error term δ^[L] at the output layer, then propagate backwards using δ^[l] = (W^[l+1]^T δ^[l+1]) ⊙ g^[l]'(z^[l]). Compute gradients for weights and biases: ∂L/∂W^[l] = δ^[l] (a^[l-1])^T, ∂L/∂b^[l] = δ^[l].

5. Summarize and Discuss Trade-offs

Summarize the full set of equations, discuss computational complexity, and mention practical considerations like vanishing/exploding gradients and the role of activation functions.

Key Points to Mention

  • Logistic regression as a single neuron with sigmoid activation and binary cross-entropy loss.
  • General L-layer network notation: W^[l], b^[l], z^[l], a^[l], and activation functions g^[l].
  • Forward propagation: z^[l] = W^[l] a^[l-1] + b^[l], a^[l] = g^[l](z^[l]).
  • Backpropagation: δ^[L] = ∇_a L ⊙ g^[L]'(z^[L]), δ^[l] = (W^[l+1]^T δ^[l+1]) ⊙ g^[l]'(z^[l]).
  • Gradients: ∂L/∂W^[l] = δ^[l] (a^[l-1])^T, ∂L/∂b^[l] = δ^[l].
  • Gradient flow and potential issues like vanishing/exploding gradients.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Write pseudocode for mini-batch gradient descent training and explain why mini-batches are used instead of full-batch gradient descent or single-example updates.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Easiest part of the interview.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by writing clear pseudocode for mini-batch gradient descent, covering initialization, epoch loop, batch splitting, and parameter updates. Then explain the trade-offs between full-batch, stochastic, and mini-batch gradient descent, emphasizing computational efficiency, convergence behavior, and hardware utilization.

Pro tip: Mention that mini-batch size is a hyperparameter that balances the variance of updates and computational efficiency, and that it often enables better generalization due to noise. Also, note that modern hardware (GPUs) is optimized for parallel processing of batches.

1. Write pseudocode

Outline the algorithm: initialize parameters, loop over epochs, shuffle data, split into mini-batches, compute gradients, and update parameters.

2. Explain full-batch gradient descent

Describe that it computes gradients over the entire dataset, leading to stable but slow updates and high memory usage.

3. Explain stochastic gradient descent (SGD)

Describe that it updates parameters per example, leading to noisy updates, faster iterations, but poor hardware utilization.

4. Compare and contrast

Highlight that mini-batch combines the benefits: efficient hardware use, moderate noise for escaping local minima, and faster convergence.

5. Discuss practical considerations

Mention hyperparameter tuning (batch size), learning rate adjustments, and trade-offs in convergence and generalization.

Key Points to Mention

  • Computational efficiency: mini-batches allow parallel processing and better GPU utilization.
  • Convergence: mini-batch gradient descent often converges faster than full-batch due to more frequent updates.
  • Memory constraints: full-batch may not fit in memory for large datasets.
  • Noise in updates: mini-batch introduces noise that can help escape local minima and improve generalization.
  • Hyperparameter: batch size is a critical hyperparameter affecting training dynamics.
  • Learning rate: can often be larger with mini-batches compared to full-batch, but may need scheduling.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

Describe Adam's update rule, write out all four components including bias correction, and give a real argument for why the second moment estimate appears under a square root in the denominator.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The bias correction explanation tripped me up more than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by writing the Adam update rule with all four components: first moment estimate, second moment estimate, bias-corrected versions, and the parameter update. Then explain the intuition behind the second moment estimate under the square root, focusing on scale invariance and adaptive per-parameter learning rates.

Pro tip: Mention that the square root makes the update scale-invariant to gradient magnitude, which is crucial for handling sparse gradients and varying scales across parameters—a key reason Adam works well in practice.

1. Define the components

Clearly state the first moment (m_t) and second moment (v_t) estimates, and their bias-corrected versions (m_hat_t, v_hat_t).

2. Write the update rule

Present the full parameter update: θ_t = θ_{t-1} - α * m_hat_t / (sqrt(v_hat_t) + ε).

3. Explain bias correction

Describe why bias correction is needed (initialization at zero) and how it adjusts the estimates to be unbiased.

4. Justify the square root

Argue that the square root normalizes the gradient by its RMS, making the update scale-invariant and adaptive to gradient magnitude.

5. Connect to practical benefits

Tie the square root to benefits like handling sparse gradients, different parameter scales, and improved convergence.

Key Points to Mention

  • First moment estimate: m_t = β1 * m_{t-1} + (1 - β1) * g_t
  • Second moment estimate: v_t = β2 * v_{t-1} + (1 - β2) * g_t^2
  • Bias correction: m_hat_t = m_t / (1 - β1^t), v_hat_t = v_t / (1 - β2^t)
  • Update rule: θ_t = θ_{t-1} - α * m_hat_t / (sqrt(v_hat_t) + ε)
  • Square root provides scale invariance: update magnitude is proportional to gradient divided by its RMS
  • Adaptive per-parameter learning rates: parameters with larger gradients get smaller effective steps

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q5

Why is binary cross-entropy preferred over mean squared error for classification with a sigmoid output? What goes wrong with the optimization landscape if you use MSE instead?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

Follow-up question, came right after the gradient derivation.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Explain that binary cross-entropy (BCE) is the proper loss for binary classification because it directly models the Bernoulli likelihood and yields well-behaved gradients when combined with a sigmoid output. Contrast this with MSE, which assumes a Gaussian likelihood and produces a non-convex, poorly conditioned optimization landscape with vanishing gradients when the sigmoid saturates. Emphasize the practical consequences: slower convergence, potential local minima, and worse calibration.

Pro tip: Mention that BCE is equivalent to minimizing the Kullback-Leibler divergence between the predicted and true distributions, and that using MSE with sigmoid can be seen as a mismatched loss that violates the probabilistic assumptions of the output layer.

1. Define the problem and losses

Clarify that binary classification with a sigmoid output predicts a probability, and compare BCE and MSE as loss functions for this setting.

2. Explain the probabilistic foundation

State that BCE arises from maximum likelihood estimation under a Bernoulli distribution, while MSE corresponds to a Gaussian assumption, which is inappropriate for binary targets.

3. Analyze the optimization landscape

Describe how BCE with sigmoid yields a convex loss (in logits) with gradients proportional to the error, whereas MSE with sigmoid produces a non-convex loss with gradients that vanish when the sigmoid saturates.

4. Discuss practical implications

Highlight that MSE leads to slower convergence, can get stuck in plateaus, and may result in poor probability calibration compared to BCE.

5. Summarize and conclude

Reiterate that BCE is preferred because it aligns with the probabilistic nature of the output and provides better gradient behavior for efficient optimization.

Key Points to Mention

  • BCE is derived from maximum likelihood estimation for Bernoulli-distributed targets.
  • MSE assumes Gaussian noise, which is invalid for binary labels.
  • With sigmoid, BCE gradient is (prediction - target), which is well-behaved even when predictions are wrong.
  • MSE gradient includes the sigmoid derivative, which vanishes when the sigmoid saturates (e.g., for very wrong predictions).
  • The MSE loss surface with sigmoid is non-convex and can have flat regions, leading to slow convergence.
  • BCE provides better calibrated probabilities and is the standard choice for binary classification.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q6

What is the vanishing gradient problem in networks with sigmoid or tanh activations, and what approaches address it?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Short follow-up.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the vanishing gradient problem in the context of sigmoid and tanh activations, explaining how their derivatives are bounded and cause gradients to shrink exponentially during backpropagation. Then, discuss the consequences for deep networks and outline practical solutions such as ReLU activations, batch normalization, residual connections, and appropriate weight initialization. Finally, connect these solutions to real-world applications, especially in large-scale systems like LinkedIn's, to show practical awareness.

Pro tip: Mention that while ReLU mitigates vanishing gradients, it introduces the dying ReLU problem, and techniques like Leaky ReLU or ELU can help. Also, note that proper initialization (e.g., He initialization) is crucial for ReLU networks, while Xavier initialization suits sigmoid/tanh.

1. Define the problem

Explain that sigmoid and tanh activations have derivatives with maximum values of 0.25 and 1, respectively, causing gradients to diminish exponentially as they propagate back through many layers.

2. Explain the impact

Describe how vanishing gradients lead to slow or stalled training in deep networks, as early layers receive tiny updates, hindering learning of hierarchical features.

3. List activation-based solutions

Discuss using ReLU and its variants (Leaky ReLU, ELU) which have non-saturating gradients for positive inputs, thus alleviating the vanishing gradient issue.

4. Cover architectural and training solutions

Mention batch normalization, residual connections (skip connections), and appropriate weight initialization (Xavier/He) as effective strategies to maintain gradient flow.

5. Relate to practice

Connect these solutions to real-world scenarios, such as training deep neural networks for recommendation or ranking at LinkedIn, emphasizing trade-offs and practical considerations.

Key Points to Mention

  • Sigmoid and tanh derivatives are bounded (≤0.25 and ≤1), causing gradients to shrink exponentially with depth.
  • Vanishing gradients lead to slow convergence and difficulty in training deep networks.
  • ReLU and its variants (Leaky ReLU, ELU) mitigate the problem by avoiding saturation for positive inputs.
  • Batch normalization reduces internal covariate shift and helps maintain gradient magnitude.
  • Residual connections (skip connections) provide shortcut paths for gradients to flow directly.
  • Proper weight initialization (Xavier for sigmoid/tanh, He for ReLU) prevents gradients from vanishing or exploding at the start of training.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q7

How does Adam compare to RMSProp and to SGD with momentum, and are there situations where plain SGD with a learning rate schedule generalizes better?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

This one surprised me a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by briefly defining each optimizer (SGD with momentum, RMSProp, Adam) and their core mechanisms, then compare their strengths and weaknesses in terms of convergence speed, stability, and generalization. Finally, discuss scenarios where plain SGD with a learning rate schedule might generalize better, referencing empirical evidence and theoretical insights.

Pro tip: Mention that while adaptive methods like Adam often converge faster, they can sometimes lead to poorer generalization compared to SGD with momentum, especially in computer vision tasks; however, recent variants like AdamW and learning rate warmup can mitigate this.

1. Define the optimizers

Briefly explain SGD with momentum, RMSProp, and Adam, highlighting their update rules and key hyperparameters.

2. Compare convergence and stability

Discuss how Adam and RMSProp adapt learning rates per parameter, leading to faster convergence, while SGD with momentum uses a global learning rate and momentum term.

3. Discuss generalization

Explain that adaptive methods can sometimes overfit or converge to sharper minima, whereas SGD with momentum and a learning rate schedule often finds flatter minima that generalize better.

4. Provide practical scenarios

Give examples where SGD with a schedule is preferred, such as training deep convolutional networks on large datasets (e.g., ImageNet) or when generalization is critical.

5. Conclude with trade-offs

Summarize that the choice depends on the task, data, and computational budget, and mention recent advances like AdamW that combine benefits.

Key Points to Mention

  • Adam combines momentum and RMSProp-like adaptive learning rates, with bias correction.
  • RMSProp uses a moving average of squared gradients to scale learning rates, without momentum.
  • SGD with momentum accumulates velocity to accelerate convergence and dampen oscillations.
  • Adaptive methods can lead to sharper minima and worse generalization in some tasks.
  • Learning rate schedules (e.g., step decay, cosine annealing) help SGD generalize better by annealing to flat minima.
  • Empirical studies (e.g., Wilson et al. 2017) show SGD with momentum often outperforms adaptive methods on vision tasks.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q8

What is weight decay, and why is decoupled weight decay (as in AdamW) different from just adding an L2 penalty to the loss when training with Adam?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

Blanked for a second.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining weight decay as a regularization technique that shrinks weights to prevent overfitting, then explain that in SGD, L2 penalty and weight decay are equivalent, but in Adam, they are not due to adaptive learning rates. Finally, describe how AdamW decouples weight decay from the gradient update, applying it directly to the weights, which improves generalization and aligns with the original intent of weight decay.

Pro tip: Mention that AdamW is now the default optimizer in many deep learning libraries and has been shown to improve performance on tasks like image classification and language modeling, demonstrating awareness of current best practices.

1. Define weight decay and L2 regularization

Explain that weight decay adds a penalty proportional to the weight magnitude to the loss, discouraging large weights. In SGD, this is equivalent to L2 regularization because the gradient of the penalty is added to the gradient of the loss.

2. Explain Adam's adaptive learning rates

Describe how Adam computes per-parameter learning rates by scaling gradients with running averages of first and second moments. This adaptivity means that adding an L2 penalty to the loss results in a different effective regularization strength for each parameter.

3. Contrast L2 penalty in Adam vs. decoupled weight decay

Clarify that with L2 penalty in Adam, the penalty term is added to the loss and its gradient is scaled by the adaptive learning rate, so parameters with large gradients get less regularization. In contrast, decoupled weight decay (AdamW) applies a direct multiplicative decay to the weights, independent of the gradient-based update.

4. Discuss implications and benefits of AdamW

Highlight that decoupling weight decay from the adaptive learning rate restores the intended regularization effect, leading to better generalization and more stable training. Mention that AdamW often outperforms Adam with L2 on tasks like image classification and NLP.

Key Points to Mention

  • Weight decay as a regularization technique to prevent overfitting by penalizing large weights.
  • In SGD, L2 regularization and weight decay are mathematically equivalent.
  • Adam's adaptive learning rates cause L2 penalty to be scaled differently per parameter, altering regularization strength.
  • Decoupled weight decay in AdamW applies decay directly to weights, separate from gradient updates.
  • AdamW improves generalization and is widely adopted in practice (e.g., transformers, ResNets).
  • The distinction matters for hyperparameter tuning: weight decay in AdamW is more interpretable and effective.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.