Module 13 Regularization
Module 13 Regularization
In machine learning, models with huge capacity (like a neural network with 1,000 parameters) trained on tiny datasets (like 100 samples) do exactly this. They connect
every tiny dot, memorizing the noise in the training data rather than the underlying trend. Regularization is a mathematical penalty we impose on the model to force it
to keep its conclusions simple and general, preventing it from overthinking.
Task Loss: How wrong your predictions are (e.g., Mean Squared Error or Cross-Entropy).
Penalty: A function of the model's weights (e.g., the sum of all weights).
λ (Lambda): The regularization strength dial.
Small λ: Trust the data completely. The model focuses almost entirely on minimizing the Task Loss (risk of high variance / overfitting).
Large λ: Distrust the data. The model prioritizes shrinking its weights over fitting the data (risk of high bias / underfitting). If λ is astronomically large, all
weights become zero, and your model predicts a flat, horizontal line.
Swiggy Relevance
Imagine Swiggy builds a DeFraudNet model to detect fake restaurants created to launder money. Fraud is rare, so the dataset is sparse. Without regularization, a
deep neural network will memorize individual harmless features—like "this restaurant is in Koramangala and sells exactly 3 types of idli"—rather than learning the true
fraud pattern (e.g., "high volume of orders at 3 AM from the exact same IP address"). Regularization forces the model to ignore the highly specific, noisy features and
focus on the universal signals of fraud.
Code Snippet
import torch
import [Link] as nn
# Forward pass
predictions = model(inputs)
task_loss = criterion(predictions, targets)
# ---------------------------------------------------------
# MANUAL REGULARIZATION IMPLEMENTATION (For intuition only)
# ---------------------------------------------------------
lambda_reg = 0.001
penalty = 0.0
Free Resources
Google Machine Learning Crash Course: Regularization ([Link]
regularization) - Excellent visual intuition.
Understanding the Bias-Variance Tradeoff ([Link] - Core foundation.
Because we take the absolute value, the penalty grows linearly. The pressure to shrink a weight from 0.1 to 0.0 is the exact same amount of pressure as shrinking it
from 100.1 to 100.0. This constant pressure pushes small, irrelevant weights all the way to absolute zero.
^ w2
|
/ \
--- / \ ---> w1
\ /
\ /
|
2. The optimal weights are found where the contour lines of the Task Loss intersect this constraint region.
3. Because the L1 constraint is a diamond with sharp, pointy corners on the axes, the elliptical loss contours are overwhelmingly likely to hit a corner.
4. At a corner, one of the weights (e.g., w1) is exactly zero. This creates sparsity.
5. The Subgradient Problem: The absolute value function |w| has a sharp point at w = 0 (it is not differentiable there). Standard gradient descent struggles
here. Optimizers handle this using subgradient methods or proximal gradient descent, which explicitly snaps the weight to exactly zero if the gradient step
crosses zero.
Swiggy Relevance
Imagine Swiggy is building a churn prediction model. They feed 100 user behavioral features into a logistic regression model: app_opens_per_week,
average_order_value, favorite_color, battery_percentage_when_ordering, etc. By applying L1 regularization, the model will automatically zero out 87
irrelevant features (like battery percentage), keeping only the 13 truly predictive features. This makes the model blazingly fast to execute in production.
import torch
import [Link] as nn
model = [Link](10, 1)
criterion = [Link]()
optimizer = [Link]([Link](), lr=0.01)
# Compute L1 Penalty manually (PyTorch optimizers don't have a direct 'l1_decay' parameter)
l1_lambda = 0.005
l1_penalty = sum([Link]().sum() for p in [Link]())
Free Resources
L1 vs L2 Regularization (Visualized) ([Link]
Proximal Gradient Descent for L1 ([Link]
Because it is squared, large weights are penalized exponentially harder than small weights. Shrinking a weight from 10.0 to 9.0 relieves a massive amount of penalty.
But shrinking a weight from 0.1 to 0.0 relieves almost nothing. Therefore, L2 shrinks weights toward zero, but almost never reaches exactly zero.
^ w2
|
/ \
--- | | ---> w1
\ /
|
2. Because the constraint boundary is curved, the loss contours will smoothly touch the edge of the circle somewhere in the middle, almost never directly on an
axis. Thus, weights shrink, but do not hit zero.
3. The Gradient: The derivative of the penalty λw² with respect to w is 2λw.
4. Weight Decay Update: During gradient descent, the weight update becomes: w_new = w_old - learning_rate * (Task_Gradient + 2λw_old)
Rewritten: w_new = w_old(1 - 2*learning_rate*λ) - learning_rate * Task_Gradient
5. Notice the term w_old(1 - small_constant). Every single step, the weight is multiplied by a fraction slightly less than 1 (e.g., 0.99). This is literally
decaying the weight step-by-step. This is why L2 regularization is interchangeably called Weight Decay.
Swiggy Relevance
L2 is the default regularization for virtually all deep learning models at Swiggy. Whether it's the MIMO (Multi-Input Multi-Output) architecture predicting delivery ETAs,
or the deep neural networks powering restaurant search ranking, L2 (Weight Decay) is running in the background to ensure the massive weight matrices stay small,
stable, and generalizable.
Code Snippet
import torch
model = [Link](10, 1)
# 2. Adam: weight_decay adds L2 to the loss, which gets DISTORTED by Adam's adaptive scaling
optimizer_adam = [Link]([Link](), lr=0.001, weight_decay=1e-4)
Free Resources
Decoupled Weight Decay Regularization (AdamW Paper) ([Link] - The foundational paper explaining why Adam + L2 is broken.
PyTorch AdamW Documentation ([Link]
13.4 Elastic Net (L1 + L2)
What Is It? (Plain English First)
If L1 is a strict minimalist who throws things away, and L2 is an organizer who shrinks everything to fit neatly, Elastic Net is a compromise between the two. It applies
both rules at the same time.
Elastic Net simply adds both the absolute value penalty (L1) and the squared penalty (L2) to the loss function.
Swiggy Relevance
Swiggy's marketing analytics team might run regression models to predict customer lifetime value (LTV) based on hundreds of overlapping, highly correlated metrics
(clicks_on_promo, time_spent_on_promo_page, promo_emails_opened). Elastic Net is the perfect algorithm here: it drops completely irrelevant features
(L1) but keeps the highly correlated promotional features grouped together (L2) for stable, interpretable coefficients.
Code Snippet
from sklearn.linear_model import ElasticNet
from [Link] import make_regression
elastic_net.fit(X, y)
# Print the number of features that were completely zeroed out by the L1 component
features_kept = sum(elastic_net.coef_ != 0)
print(f"Features kept: {features_kept} out of 100")
Free Resources
Elastic Net Regression Explained ([Link]
Scikit-Learn Elastic Net Docs ([Link]
Answer Framework:
It prevents overfitting.
Overfitting occurs when a model with high capacity memorizes the noise in the training data rather than the underlying signal.
Regularization enforces simplicity by adding a penalty term to the loss function based on the size of the weights.
Why This Is Asked: To verify you understand the core purpose of the technique before diving into math.
Answer Framework:
Bias is the error from erroneous assumptions (model is too simple, underfitting).
Variance is the error from sensitivity to small fluctuations in the training set (model is too complex, overfitting).
You cannot perfectly minimize both. Regularization intentionally increases bias slightly to massively reduce variance.
L1 (Lasso) adds a penalty equal to the absolute value of the magnitude of coefficients: \(\lambda \sum|w|\).
L2 (Ridge) adds a penalty equal to the square of the magnitude of coefficients: \(\lambda \sum w^2\).
Answer Framework:
L1 Regularization.
Because of its diamond-shaped geometric constraint, the loss optimization is highly likely to intersect exactly at an axis.
This drives the weights of less important features to exactly zero, removing them from the model.
Q5. What happens if you set the regularization hyperparameter (\(\lambda\)) to an extremely large value?
Answer Framework:
The penalty term will completely dominate the task loss (e.g., MSE).
The optimizer will focus entirely on shrinking the weights to zero to minimize the massive penalty.
The model will become a flat horizontal line, resulting in severe underfitting (high bias).
Answer Framework:
It is the mechanism by which the weights are reduced slightly during each update step of gradient descent.
In standard SGD, it is mathematically identical to the derivative of the L2 penalty, where the weight is multiplied by a factor slightly less than 1 (e.g., \((1
- 2\eta\lambda)\)).
Why This Is Asked: Terminology check. Many people use "L2" and "Weight Decay" interchangeably, which is fine for SGD but dangerous for Adam.
Q7. Swiggy uses deep neural networks for search ranking. Should they use L1 or L2 regularization?
Answer Framework:
A regularization technique that combines both L1 and L2 penalties in the loss function.
It uses a hyperparameter (often l1_ratio) to balance the strength of the absolute value penalty vs the squared penalty.
Answer Framework:
Why This Is Asked: Geometric intuition is critical for understanding why sparsity happens.
Answer Framework:
Q11. Swiggy's fraud detection model uses 200 features, but inference is too slow. How can regularization help?
Answer Framework:
Why This Is Asked: Applying L1 for its primary industrial use case: feature selection.
Answer Framework:
Answer Framework:
Q14. Swiggy has features like user_total_spend and user_avg_spend which are highly correlated. What happens if you use pure L1 regularization?
Answer Framework:
Q15. How does Elastic Net solve the correlated feature problem described above?
Answer Framework:
Why This Is Asked: Understanding the exact hybrid mechanism of Elastic Net.
Q16. During the fine-tuning of your TrOCR model for Malayalam, did you use Weight Decay?
Answer Framework:
Yes. The Hugging Face Trainer uses AdamW by default, which implements decoupled weight decay (L2).
Transformers are highly prone to overfitting on small fine-tuning datasets. Weight decay was essential to ensure the model didn't destroy its pre-trained
visual-language representations while adapting to the Malayalam script.
Why This Is Asked: Connecting optimizer defaults to Ashmi's specific project workflow.
Answer Framework:
Q18. If a model is severely underfitting, what should you do to the regularization parameter?
Answer Framework:
Decrease \(\lambda\).
Underfitting (high bias) means the penalty is dominating the task loss, preventing the model from learning the patterns in the data.
Reducing \(\lambda\) allows the weights to grow and better fit the training set.
Q19. Swiggy's MIMO model predicts 5 different outputs (ETA, cost, distance, etc.). Does regularization affect all outputs equally?
Answer Framework:
It affects all weights in the shared hidden layers equally, promoting generalized internal representations.
However, for the final output heads, the penalty applies to their specific weights. If one output requires much larger weights to scale its predictions
properly, L2 might over-penalize it unless inputs/outputs are properly normalized.
Answer Framework:
Bias terms do not interact with the input data directly; they just shift the activation function.
Large bias terms do not cause the model to become highly sensitive to variance in the input data (which is what causes overfitting).
Penalizing them can cause underfitting without providing any generalization benefit.
Why This Is Asked: A classic edge-case question that separates beginners from practitioners.
Q21. Explain exactly why Adam and L2 regularization don't mix well mathematically.
Answer Framework:
In standard Adam, L2 is implemented by adding \(\lambda w\) to the gradient before the adaptive learning rate step.
Adam divides the gradient by the square root of the moving average of squared gradients (\(\sqrt{v_t}\)).
This means the weight decay penalty is also divided by this adaptive factor. Parameters with large gradients get less weight decay; parameters with
small gradients get massive weight decay.
⚠ Common Wrong Answer: "Adam uses L1 instead of L2." No, Adam attempts to use L2, but its adaptive denominator distorts the penalty, rendering
it ineffective.
Why This Is Asked: This is the core reason AdamW was invented.
Q22. [CODE QUESTION] You are training a PyTorch model and need to apply L1 regularization. PyTorch optimizers don't have an l1_decay argument.
Write the code to apply it.
Answer Framework:
You must manually iterate through the parameters, sum their absolute values, and add it to the loss before backward().
⚠ Common Wrong Answer: Trying to pass weight_decay=0.01 to the optimizer, assuming it does L1. (It does L2/Weight decay).
Why This Is Asked: Tests PyTorch proficiency and understanding of autograd mechanics.
Answer Framework:
Q24. Swiggy wants to build a demand forecasting model using linear regression on 50 highly correlated weather and traffic variables. Which regularization
do you choose and why?
Answer Framework:
Elastic Net.
Pure L1 (Lasso) will arbitrarily drop correlated weather variables, making the model unstable day-to-day.
Pure L2 (Ridge) will keep all 50, providing no feature selection.
Elastic Net's grouping effect will keep the genuinely predictive correlated clusters together while zeroing out the absolute noise.
⚠ Common Wrong Answer: "Just use Lasso to get rid of the extra features."
Q25. In your REBOUND application, you track user poses via MediaPipe. If you trained a custom classifier on those joint coordinates, why would
standardizing/normalizing the coordinates be critical before applying L2 regularization?
Answer Framework:
Why This Is Asked: Cross-domain integration: understanding how data preprocessing interacts with loss functions.
Q26. [CODE QUESTION] In Scikit-Learn, how do you verify exactly how many features an ElasticNet model zeroed out?
Answer Framework:
⚠ Common Wrong Answer: Looking at model.feature_importances_ (that is for tree-based models, not linear regression).
Q27. Why do Transformers (like the one used in your Sarathī RAG system) require AdamW instead of Adam?
Answer Framework:
Transformers are notorious for overfitting due to their massive parameter count and lack of spatial inductive bias (unlike CNNs).
They require strict, consistent regularization to generalize.
Standard Adam's coupled L2 regularization applies unevenly to different attention heads based on their gradient histories. AdamW's decoupled
approach guarantees uniform regularization, which is empirically required for Transformer stability.
⚠ Common Wrong Answer: "AdamW is just faster."
Q28. A Swiggy engineer proposes removing all Weight Decay and instead just using Early Stopping to prevent overfitting on the ETA model. Is this
mathematically equivalent?
Answer Framework:
Geometrically, yes, they are closely related. Early stopping halts the weights before they have time to grow massive and reach the unregularized
minimum.
It acts as an implicit L2 regularizer.
However, explicit Weight Decay operates continuously on the loss manifold, often finding flatter, more generalizable minima than simply cutting the
training run short. Best practice is to use both.
⚠ Common Wrong Answer: "They have nothing to do with each other."
Why This Is Asked: Testing deep intuition linking different regularization techniques.
Q29. What is the difference between a penalty term and a hard constraint?
Answer Framework:
A penalty term adds \(\lambda \sum w^2\) to the loss. It acts as a "soft" pressure. The optimizer balances it against the task loss.
A hard constraint (like max-norm regularization) literally projects the weights back into a sphere if they exceed a certain radius (e.g., \(||w|| < C\)).
⚠ Common Wrong Answer: Assuming L2 prevents weights from ever crossing a specific numerical threshold.
Q30. You are using L1 regularization for a fraud detection model at Swiggy, but it keeps dropping a feature you know is important. How do you fix this?
Answer Framework:
The feature might be highly correlated with another feature that L1 arbitrarily kept. Switch to Elastic Net to induce the grouping effect.
Alternatively, apply different \(\lambda\) weights to different features (un-penalize the feature you want to force the model to use).
⚠ Common Wrong Answer: "Increase lambda so it pays more attention to it." (Increasing lambda forces more things to zero).
Q31. Derive the weight update rule for SGD with L2 regularization and prove why it is called "Weight Decay."
Answer Framework:
Loss function: \(J(w) = L(w) + \frac{\lambda}{2} w^2\) (Using \(\frac{\lambda}{2}\) makes the derivative cleaner).
Derivative: \(\nabla J(w) = \nabla L(w) + \lambda w\).
Update rule: \(w_{t+1} = w_t - \eta(\nabla L(w) + \lambda w_t)\).
Rearranging: \(w_{t+1} = w_t(1 - \eta\lambda) - \eta\nabla L(w)\).
Because \((1 - \eta\lambda)\) is a fraction \(< 1\), the weight is explicitly decayed by this factor before the gradient is subtracted.
⚠ Common Wrong Answer: Failing the algebra to factor out \(w_t\).
Q32. In your TrOCR fine-tuning, how does Weight Decay interact with the Learning Rate Scheduler?
Answer Framework:
In AdamW, the weight decay update is \(w_{t+1} = w_t - \eta \lambda w_t - \dots\)
Notice that \(\eta\) (learning rate) is multiplied by \(\lambda\).
If you use a scheduler (like Cosine Annealing) to drop \(\eta\) to near zero at the end of training, the effective weight decay also drops to near zero!
This allows the model to fine-tune its final weights freely in the local minimum without being artificially dragged to zero at the last minute.
⚠ Common Wrong Answer: "Weight decay is constant throughout training."
Answer Framework:
Regularization is equivalent to putting a prior probability distribution on the weights (MAP estimation).
L2 Regularization is mathematically equivalent to assuming the weights are drawn from a Gaussian (Normal) prior distribution centered at zero.
L1 Regularization is mathematically equivalent to assuming the weights are drawn from a Laplace prior distribution, which has a much sharper peak at
zero and fatter tails, explaining its tendency for exact zero coefficients.
⚠ Common Wrong Answer: Confusing the priors or not knowing the Bayesian link.
Q34. [CODE QUESTION] How would you implement Decoupled Weight Decay in a custom PyTorch SGD training loop without relying on the optimizer's
built-in parameter?
Answer Framework:
You compute the gradients from the task loss, step the optimizer, and then manually multiply the weights by the decay factor within a
torch.no_grad() block.
[Link]()
[Link]() # standard update
with torch.no_grad():
for param in [Link]():
param.mul_(1.0 - learning_rate * lambda_decay)
⚠ Common Wrong Answer: Adding the penalty to the loss inside the loop (that implements coupled L2, not decoupled decay).
Q35. Swiggy trains a massive LLM (Hermes) for text-to-SQL. The loss landscape is full of sharp minima and flat minima. How does L2 regularization affect
which minimum is found?
Answer Framework:
Sharp minima have large gradients (curvatures) at their edges. Flat minima are broad.
L2 regularization penalizes large weights. Because moving into sharp minima often requires extreme, specific weight values, L2 pressure naturally
pushes the optimizer out of sharp, overfitted crevices and encourages settling in broader, flatter minima that generalize better to unseen data.
⚠ Common Wrong Answer: "L2 makes the minima deeper."
Q36. Why does L1 regularization cause oscillations if standard gradient descent is used, and how does the Proximal Operator solve it?
Answer Framework:
Near \(w=0\), the gradient of \(|w|\) is \(+1\) or \(-1\). It never gets smaller as you approach zero.
A standard gradient step will jump entirely over \(w=0\) to the other side, oscillating back and forth infinitely without ever landing exactly on zero.
The Proximal Operator (Soft-Thresholding) fixes this. After a gradient step, if the step crosses zero, the operator forcibly sets the weight to exactly \
(0.0\).
⚠ Common Wrong Answer: "Gradient descent naturally stops at zero because the slope is zero." (The slope is undefined, not zero).
Q37. In production at Swiggy, how does Weight Decay impact model quantization for edge deployment (e.g., deploying on delivery partner phones)?
Answer Framework:
Q38. What is the condition number of the Hessian matrix, and how does L2 regularization improve it?
Answer Framework:
The Hessian describes the curvature of the loss. A high condition number (ill-conditioned) means the loss landscape is a steep ravine: gradients
oscillate wildly in one direction and move agonizingly slowly in another.
L2 regularization adds \(\lambda I\) (lambda times the identity matrix) to the Hessian.
This mathematically increases the smallest eigenvalues, bounding the condition number and making the ravine "rounder," allowing gradient descent to
converge much faster and more stably.
⚠ Common Wrong Answer: Blanking on the definition of the Hessian.
Q39. Can you apply L1 and L2 regularization to the activations of a neural network rather than the weights?
Answer Framework:
Why This Is Asked: Testing architectural creativity and knowledge of neuroscience analogies in ML.
Q40. [CODE QUESTION] In PyTorch, what is the consequence of applying weight_decay to LayerNorm parameters (gamma/beta) in your TrOCR
implementation?
Answer Framework:
It is generally harmful. Gamma and beta are low-dimensional scaling and shifting parameters, not high-dimensional weight matrices.
Penalizing them reduces the network's ability to properly normalize activations, leading to representation collapse without preventing any meaningful
overfitting.
You should filter them out of the optimizer group:
In a neural network, neurons act the same way. If they are always active, some neurons become highly specialized and over-reliant on the outputs of specific
neighboring neurons. Dropout randomly "turns off" a percentage of neurons during every training step. This forces every single neuron to learn independently useful
features, preventing the network from memorizing highly specific, fragile patterns.
The Inverted Dropout Trick: If we drop 50% of the neurons during training, the next layer only receives 50% of the normal input signal. At inference (testing) time, we
turn dropout off so the network has all its brainpower. But if all neurons fire, the next layer suddenly receives 200% of the signal it is used to, which will blow up the
activations!
To fix this mathematically without modifying the test-time code, we use the Inverted Dropout Trick: During training, we scale up the surviving neurons by \(\frac{1}{1 -
p}\). If \(p = 0.5\), we scale the survivors by \(\frac{1}{0.5} = 2\). Because we artificially doubled the signal of the survivors during training, the expected value matches
exactly what the layer will see at inference when 100% of the unscaled neurons fire.
Swiggy Relevance
Swiggy's MIMO (Multi-Input Multi-Output) model predicts delivery ETA based on weather, traffic, and restaurant prep time. It uses massive fully connected (dense)
layers. Without dropout, the model might rigidly memorize that "Restaurant X + Rain = exactly 45 minutes," failing to generalize to Restaurant Y. Dropout forces the
network to learn robust, generalized representations of weather and traffic independently of the specific restaurant.
Code Snippet
import torch
import [Link] as nn
Free Resources
Original Dropout Paper by Geoffrey Hinton ([Link]
Understanding Dropout in PyTorch ([Link]
In a deep neural network, Layer 2 is trying to learn how to map inputs to outputs. But Layer 2's inputs are the outputs of Layer 1. As Layer 1's weights update during
training, the scale and distribution of its outputs wildly shift. Layer 2 is constantly chasing a moving target. Batch Normalization fixes this by mathematically
standardizing the inputs to every layer so they always have a mean of 0 and a variance of 1.
The network calculates \(\mu_B\) and \(\sigma^2_B\) exactly from the current mini-batch.
It normalizes the data.
It also secretly maintains an Exponential Moving Average (EMA) of the mean and variance across all batches seen so far.
During Inference:
At test time, you might only pass a single image (batch size = 1). You cannot compute a standard deviation of 1 item!
The network completely ignores the current input for statistics. Instead, it uses the frozen EMA mean and variance it tracked during training to normalize the
test image.
Swiggy Relevance
Swiggy uses convolutional neural networks (CNNs) to classify millions of user-uploaded food images to detect inappropriate content. Training a 50-layer ResNet
without BatchNorm is nearly impossible; the gradients vanish. BatchNorm is the structural glue between every convolution and ReLU layer in Swiggy's vision
pipelines, ensuring fast convergence across massive multi-GPU clusters.
You must be able to articulate why Transformers abandon BatchNorm. BatchNorm computes statistics across the batch dimension. NLP sequences have highly
variable lengths (lots of padding tokens), which severely distorts batch statistics. LayerNorm computes the mean and variance across the feature dimension for a
single token, making it entirely independent of batch size and impervious to sequence length variations.
Code Snippet
import torch
import [Link] as nn
Free Resources
Batch Normalization Original Paper ([Link]
How Does Batch Normalization Help Optimization? (Debunking Covariate Shift) ([Link]
Answer Framework:
To prevent overfitting.
It does this by randomly deactivating a percentage of neurons during each forward pass.
This prevents complex co-adaptations where neurons rely heavily on specific neighboring neurons.
Answer Framework:
Why This Is Asked: To ensure you understand the difference between training and deployment phases.
It standardizes the activations of a layer to have a mean of 0 and a variance (or standard deviation) of 1.
However, it then applies learnable scale (\(\gamma\)) and shift (\(\beta\)) parameters so the network can adjust this distribution if necessary.
Answer Framework:
It is the phenomenon where the distribution of a layer's inputs changes during training because the parameters of the preceding layers are constantly
updating.
The original BatchNorm paper proposed this as the problem BatchNorm solves, though modern research suggests BN actually works by smoothing the
loss landscape.
Why This Is Asked: It is the most famous terminology associated with the algorithm.
Q5. Why does BatchNorm have learnable parameters \(\gamma\) (gamma) and \(\beta\) (beta)?
Answer Framework:
If we strictly forced a mean of 0 and variance of 1, we might restrict the representational power of the network.
For example, pushing data into the linear region of a Sigmoid function might destroy non-linear feature representations. \(\gamma\) and \(\beta\) allow
the network to optimally scale and shift the normalized data to recover expressive power.
Why This Is Asked: Tests understanding beyond just the basic standard normal math.
Q6. What happens if you run inference through a BatchNorm layer with a batch size of 1 without calling [Link]()?
Answer Framework:
The model will attempt to calculate the mean and variance of that single item.
The variance of a single item is 0. Normalizing by 0 (or \(\epsilon\)) destroys the data.
The output will be complete garbage.
Q7. Swiggy's ETA model has a massive fully connected layer. What is a standard dropout rate to start with?
Answer Framework:
A dropout rate of 0.5 (50%) is the industry standard starting point for dense, fully connected layers.
Q8. What is the fundamental difference in what Batch Normalization vs Layer Normalization computes its statistics across?
Answer Framework:
BatchNorm computes the mean and variance across the batch dimension (N) for a specific feature channel.
LayerNorm computes the mean and variance across the feature dimension (C or E) for a single specific sample/token.
Why This Is Asked: The most important distinction between the two techniques.
Q9. Which normalization technique is the default for CNNs, and which is the default for Transformers?
Answer Framework:
Q10. In your REBOUND application, if you applied dropout to the final coordinate regression layer, what effect does it have?
Answer Framework:
It prevents the final layers from memorizing the specific frames of the limited training video dataset, forcing it to learn generalized human pose
kinematics.
Answer Framework:
Because dropout zeroes out neurons during training, the sum of the activations is reduced. If \(p=0.5\), the next layer only sees half the signal.
To ensure the expected value matches the test phase (where all neurons fire), we divide the surviving neurons during training by \((1 - p)\).
This scales them up during training, meaning we don't have to modify any weights or scaling during inference.
Q12. Swiggy is training a deep CNN for food classification, but the gradients keep vanishing. How does BatchNorm fix this?
Answer Framework:
Without BN, as data passes through deep layers, activations shift and scale wildly, often pushing inputs into the flat, saturated regions of activation
functions (like the tails of Tanh or Sigmoid).
In these flat regions, the derivative is near zero, causing gradients to vanish during backprop.
BN forcefully recenters the data around 0, keeping activations in the steep, linear "healthy" regions of the activation functions where gradients flow
strongly.
Every training step with dropout creates a uniquely "thinned" neural network by masking different neurons.
With \(N\) neurons, there are \(2^N\) possible network architectures.
Training with dropout is effectively training a massive ensemble of these \(2^N\) sub-networks. At inference, running the full network approximates the
geometric mean of all these sub-networks.
Why This Is Asked: The most profound theoretical explanation of why dropout works so well.
Q14. Why do Transformers (like the one you used in TrOCR) fail when using Batch Normalization?
Answer Framework:
Answer Framework:
Q16. Swiggy's fraud detection team has an imbalanced, tiny dataset of 5,000 samples. Would you recommend a high dropout rate (0.7)?
Answer Framework:
No. Dropout requires a sufficiently large dataset so the network can see enough variations of the "thinned" sub-networks to learn robust features.
On a tiny dataset, aggressive dropout will cripple the model's capacity to learn at all, resulting in severe underfitting.
Answer Framework:
During training, BN maintains an Exponential Moving Average (EMA) of the batch means and variances.
When switched to eval(), the layer stops looking at the incoming batch data entirely. It relies solely on the frozen EMA statistics to normalize the
inference data.
Convolutional features are highly spatially correlated. If you drop pixel \((x, y)\), the adjacent pixel \((x+1, y)\) holds almost the exact same information.
The network just bypasses the dropout by looking at the neighbors, rendering standard dropout ineffective.
(Note: Specialized techniques like SpatialDropout drop entire feature maps instead).
Why This Is Asked: Understanding the interaction between regularization and spatial inductive biases.
Q19. You applied LayerNorm to your IndicBERT model. Does LayerNorm use EMA (Exponential Moving Average) statistics during inference?
Answer Framework:
No.
Because LayerNorm computes the mean and variance purely from the current token's feature vector, it calculates exact statistics on the fly during
inference. It does not need, nor track, historical batch statistics.
Q20. If you increase the batch size from 32 to 1024, how does this affect the regularizing property of BatchNorm?
Answer Framework:
Why This Is Asked: Understanding the interplay between batch size and implicit regularization.
Q21. A Swiggy junior ML engineer places a Dropout layer before a BatchNorm layer in a dense network. What goes wrong here?
Answer Framework:
Q22. [CODE QUESTION] Write a simple PyTorch snippet demonstrating how to implement LayerNorm manually (without [Link]) on a 3D tensor
(Batch, Sequence, Features).
Answer Framework:
You must compute mean and variance across the last dimension (dim=-1), keep dims for broadcasting, and apply \(\gamma\) and \(\beta\).
eps = 1e-5
mean = [Link](dim=-1, keepdim=True)
var = [Link](dim=-1, unbiased=False, keepdim=True)
normalized_x = (x - mean) / [Link](var + eps)
out = gamma * normalized_x + beta
Q23. Swiggy is training a real-time matching model for delivery partners using massive batch sizes on TPUs. The model converges, but generalizes poorly.
How might you adjust the normalization to fix this?
Answer Framework:
The massive batch size has eliminated the noisy regularization effect of BatchNorm.
To recover generalization, we should implement Ghost Batch Normalization.
The massive batch is split into virtual "ghost" mini-batches (e.g., chunks of 32). Statistics are computed and normalized independently within these
small chunks, injecting the necessary noise back into the optimization process while still utilizing the hardware efficiency of the massive overall batch.
⚠ Common Wrong Answer: "Just add more dropout." (Valid, but misses the BN-specific dynamic).
Q24. In your Sarathī RAG system, if you fine-tune the Llama 3.1 LLM, you will encounter RMSNorm instead of LayerNorm. What is the mathematical
difference?
Answer Framework:
RMSNorm (Root Mean Square Normalization) is a computationally cheaper variant of LayerNorm used in Llama.
LayerNorm recenters the data (subtracts the mean) and scales it (divides by standard deviation).
RMSNorm skips the recentering step entirely (it assumes the mean is near zero anyway) and only divides by the Root Mean Square of the activations.
This saves massive compute at the trillion-parameter scale with virtually zero loss in accuracy.
⚠ Common Wrong Answer: "RMSNorm normalizes across the batch."
Why This Is Asked: Cutting-edge LLM architectural knowledge directly relevant to Ashmi's resume.
Q25. You are debugging a PyTorch model. During training, validation loss is dropping perfectly. But the moment you call [Link](), the validation
accuracy crashes to random chance. What is the most likely culprit?
Answer Framework:
Answer Framework:
Post-LayerNorm puts the normalization on the main gradient path. In very deep networks, this causes the gradients to shrink near the input layers,
destabilizing training without extensive learning rate warmup.
Pre-LayerNorm applies normalization inside the residual block, leaving the main identity path completely untouched. Gradients flow perfectly
backwards, allowing for much deeper networks and eliminating the need for strict warmup schedules.
⚠ Common Wrong Answer: "Pre-LayerNorm is just computationally faster."
Q27. Swiggy has an edge computing initiative to run small CNNs directly on delivery partner phones. Why might you use "Batch Renormalization" or
"Group Normalization" for this?
Answer Framework:
Training models for edge devices often requires memory constraints, limiting training batch sizes to 2 or 4.
Standard BatchNorm fails at micro-batch sizes because the variance estimate is wildly inaccurate.
Group Normalization divides the channels of a single image into groups and normalizes within those groups, making it entirely independent of batch
size. It performs flawlessly even with a batch size of 1.
⚠ Common Wrong Answer: "Just freeze the BatchNorm layers."
Q28. [CODE QUESTION] If you implement a custom Dropout layer, how do you handle the gradient during the backward pass?
Answer Framework:
The backward pass of Dropout is incredibly simple. You must save the exact boolean mask generated during the forward pass.
During backward(), you multiply the incoming upstream gradients by that exact same mask.
If a neuron was dropped (0), it contributed nothing to the output, so it receives a gradient of 0. If it survived (1), the gradient passes through (scaled by \
(1/(1-p)\)).
⚠ Common Wrong Answer: "PyTorch autograd just figures it out." (You need to know the math).
Q29. You notice your deep CNN is suffering from dead ReLUs. How does Batch Normalization help prevent this?
Answer Framework:
Dead ReLUs occur when a large negative bias or massive weight shift pushes the pre-activation \(Wx+b\) into the negative domain for all inputs. The
ReLU outputs 0, the gradient becomes 0, and the neuron never updates again.
BatchNorm is placed before the ReLU. It explicitly standardizes the pre-activations to have a mean of 0. This guarantees that roughly 50% of the inputs
to the ReLU will be positive, ensuring the neuron stays alive and receives gradients.
⚠ Common Wrong Answer: "BatchNorm makes the learning rate smaller so it doesn't die."
Q30. Explain the theoretical argument that BatchNorm actually works by smoothing the optimization landscape rather than fixing covariate shift.
Answer Framework:
Researchers proved this by intentionally injecting massive covariate shift (noise) into networks after BatchNorm layers. The networks still trained
perfectly.
The real mechanism: BN makes the loss landscape \(\beta\)-smooth. It bounds the gradients of the loss, ensuring that a gradient step taken in one
direction doesn't drastically alter the gradients in a neighboring region. This Lipschitz continuity allows for massive learning rates without overshooting
the minimum.
⚠ Common Wrong Answer: Clinging to the original 2015 covariate shift theory without acknowledging the 2018 debunking.
Why This Is Asked: Separating candidates who read textbook summaries from those who follow deep learning research.
Q31. Derive the backpropagation gradients for a Batch Normalization layer with respect to its input \(x\).
Answer Framework:
This is famously complex because \(x_i\) influences the output directly, but also indirectly influences the batch mean \(\mu\) and variance \(\sigma^2\),
which in turn affect the normalization of every other \(x_j\) in the batch.
You must apply the multivariate chain rule: \(\frac{\partial L}{\partial x_i} = \frac{\partial L}{\partial \hat{x}_i} \frac{\partial \hat{x}_i}{\partial x_i} +
\frac{\partial L}{\partial \mu_B} \frac{\partial \mu_B}{\partial x_i} + \frac{\partial L}{\partial \sigma^2_B} \frac{\partial \sigma^2_B}{\partial x_i}\)
The cross-talk between batch elements via the mean/variance gradients is why BN gradients are so dense.
⚠ Common Wrong Answer: Forgetting the derivative paths through the mean and variance.
Q32. In a distributed training environment at Swiggy (e.g., 8 GPUs using PyTorch DistributedDataParallel), standard BatchNorm calculates statistics
per-GPU. Why is this problematic, and what is the solution?
Answer Framework:
If the global batch size is 256 across 8 GPUs, each GPU computes BatchNorm statistics on a local micro-batch of 32.
This restricts the accuracy of the statistics and breaks the mathematical equivalence of a true batch size of 256.
The solution is SyncBatchNorm ([Link]). During the forward pass, it performs an all-reduce communication across all GPUs to
compute the global mean and variance before normalizing.
⚠ Common Wrong Answer: "DDP automatically syncs the batch norms." (It syncs gradients, not forward pass statistics by default).
Q33. What is "Monte Carlo Dropout" (MC Dropout), and how can Swiggy use it for uncertainty estimation in ETAs?
Answer Framework:
Answer Framework:
Q35. Why does Weight Decay interact destructively with Batch Normalization's learnable scaling parameter \(\gamma\)?
Answer Framework:
Answer Framework:
Q37. If you use Instance Normalization (common in Style Transfer) instead of Batch Normalization, what exactly are you normalizing over?
Answer Framework:
InstanceNorm normalizes across the spatial dimensions (H, W) for a single channel of a single image.
It completely isolates the normalization to that specific feature map. It strips away global contrast/brightness information (which is why it's great for style
transfer) but retains the spatial structure.
⚠ Common Wrong Answer: Confusing it with LayerNorm (which normalizes across ALL channels for a single sample).
Why This Is Asked: Mastery of the "Normalization Taxonomy" (Batch vs Layer vs Instance vs Group).
Q38. Why might inserting a BatchNorm layer before the residual addition in a ResNet block cause training collapse at extreme depths (1000+ layers)?
Answer Framework:
If BN is placed on the main identity pathway (or immediately before the addition without a zero-initialized \(\gamma\)), it normalizes the accumulated
signal, fundamentally destroying the identity mapping \(F(x) + x\).
For information to flow cleanly through 1000 layers, the identity path must remain pristine. Proper ResNet design places BN inside the residual branch
(the \(F(x)\) part), and initializes the final BN's \(\gamma\) to 0. This ensures the block starts as a perfect identity mapping, guaranteeing stable
initialization at massive depths.
⚠ Common Wrong Answer: "BatchNorm always helps deep networks."
Why This Is Asked: Elite understanding of ResNet signal propagation (Identity Mappings in Deep Residual Networks paper).
Answer Framework:
In few-shot learning (e.g., MAML), models are trained to adapt to new tasks rapidly using very small support sets (e.g., 5 images).
BatchNorm completely breaks here because computing statistics on 5 images is disastrously noisy. Furthermore, the statistics of the support set
(training) and query set (testing) in a few-shot episode differ heavily.
This is why meta-learning architectures almost universally swap BN for Layer Normalization or Task Normalization.
⚠ Common Wrong Answer: "It just makes it slower."
Q40. [CODE QUESTION] In a multi-GPU setup, Swiggy is using mixed precision (FP16). Why must BatchNorm statistics (\(\mu, \sigma^2\)) still be
computed and stored in FP32?
Answer Framework:
Computing variance involves squaring numbers \((x - \mu)^2\) and summing them.
In FP16, the maximum representable value is 65,504. Squaring even moderately large activations quickly causes numerical overflow (resulting in NaN
or Inf).
Conversely, if activations are small, squaring them can cause underflow to 0.0, resulting in division by zero.
BN reductions must be done in FP32 to maintain numerical stability in mixed-precision training.
⚠ Common Wrong Answer: "Because PyTorch doesn't support FP16 BatchNorm."
Swiggy Relevance
Training Swiggy's massive recommendation engine (which matches millions of users to restaurants) involves navigating a loss landscape with billions of parameters.
Using basic gradient descent would guarantee getting stuck in a local minimum, resulting in terrible food recommendations. Advanced optimizers are required to
dynamically navigate this complex topography.
Code Snippet
import torch
import [Link] as nn
model = [Link](10, 1)
criterion = [Link]()
# 1. Forward Pass
outputs = model([Link](5, 10))
loss = criterion(outputs, [Link](5, 1))
Free Resources
Visualizing the Loss Landscape of Neural Nets ([Link] - Incredible paper with actual 3D plots of neural network loss landscapes.
Swiggy Relevance
When Swiggy trains massive computer vision models (CNNs) to classify menu items, they often prefer SGD with Momentum over modern adaptive optimizers like
Adam. While Adam converges faster initially, CNNs trained for a long time with SGD+Momentum consistently generalize better to new images.
Code Snippet
import torch
model = [Link](10, 1)
Free Resources
[Link]: Why Momentum Really Works ([Link] - The definitive visual guide.
Adam acts like a personalized tutor. It tracks the progress of every single weight in the network. If a weight is attached to a highly frequent, noisy feature, Adam dials
down its learning rate. If a weight is attached to a rare but highly informative feature, Adam boosts its learning rate. It provides an individual, adaptive learning rate for
every single parameter.
The Update Rule: \(\theta_{t+1} = \theta_t - \left( \frac{\eta}{\sqrt{\hat{v}_t} + \epsilon} \right) \cdot \hat{m}_t\)
If a parameter has been getting huge gradients (large \(v_t\)), we divide by a large number, shrinking the effective learning rate.
If a parameter has had tiny gradients, we divide by a tiny number, boosting its learning rate.
Swiggy Relevance
For NLP models like Swiggy's Hermes text-to-SQL system, or recommender systems dealing with sparse user-item interaction matrices, Adam is the undisputed king.
It handles sparse, unscaled gradients natively.
Code Snippet
import torch
model = [Link](10, 1)
Free Resources
Adam: A Method for Stochastic Optimization ([Link] - The original paper (highly readable).
The Fix in AdamW: AdamW calculates the exact same adaptive gradient step as Adam. But it applies the weight decay completely separately, directly to the weights:
\(\theta_{t+1} = \theta_t - \eta \cdot \left( \text{Adam\_Update} \right) - \eta \cdot \lambda \cdot \theta_t\)
The \(-\eta \cdot \lambda \cdot \theta_t\) term is pure, uncorrupted weight decay.
Swiggy Relevance
Any large language model or vision transformer deployed at Swiggy (like customer support RAG systems) is trained or fine-tuned using AdamW.
Code Snippet
import torch
model = [Link](10, 1)
Free Resources
Fixing Weight Decay Regularization in Adam ([Link] - [Link]'s excellent breakdown.
Swiggy Relevance
Training the MIMO delivery prediction model involves multiple output heads. Early in training, these heads conflict heavily. A strict warmup schedule prevents the
gradients from exploding early on.
Code Snippet
import torch
from [Link] import AdamW
from [Link].lr_scheduler import CosineAnnealingLR
from transformers import get_linear_schedule_with_warmup
scheduler_hf = get_linear_schedule_with_warmup(
optimizer,
num_warmup_steps=num_warmup_steps,
num_training_steps=num_training_steps
)
Free Resources
HuggingFace Scheduler Docs ([Link]
Answer Framework:
Answer Framework:
In steep ravines of the loss landscape, vanilla SGD oscillates violently back and forth between the walls, making very slow progress down the valley.
Momentum accumulates a velocity vector. Oscillating gradients cancel each other out, while consistent gradients accumulate, smoothing the trajectory
and accelerating convergence.
Answer Framework:
The 1st moment is the exponentially decaying average of past gradients (tracking direction, similar to momentum).
The 2nd moment is the exponentially decaying average of past squared gradients (tracking magnitude/variance, used to scale the learning rate).
Answer Framework:
The moving averages (\(m_t\) and \(v_t\)) are initialized as vectors of zeros.
During the first few steps, these estimates are heavily biased toward zero.
The bias correction step divides them by \((1 - \beta^t)\) to scale them up to accurate estimates during the early phase of training.
Why This Is Asked: Shows you actually know the Adam algorithm, not just the PyTorch import statement.
In the Adam update rule, we divide by the square root of the 2nd moment (\(\sqrt{v_t}\)).
Epsilon is a tiny constant (e.g., 1e-8) added to the denominator strictly to prevent a division by zero error.
Answer Framework:
To fix a bug where standard Adam applies L2 Regularization (Weight Decay) incorrectly.
Adam applies the penalty to the gradient before the adaptive scaling, which distorts the regularization. AdamW decouples it and applies it directly to the
weights.
Why This Is Asked: This is the most famous optimizer evolution in recent history.
Answer Framework:
An algorithm that dynamically adjusts the learning rate during the training process.
It typically starts high to explore the loss landscape, and decays to a tiny value to allow the optimizer to settle perfectly into the bottom of a minimum.
Answer Framework:
Starting training with a learning rate of \(0.0\) and linearly ramping it up to the target base learning rate over a specified number of steps.
It prevents massive, chaotic gradients during initial training from destroying the model's stability.
Q10. For Swiggy's image classification CNNs, why might researchers prefer SGD with Momentum over Adam?
Answer Framework:
While Adam converges much faster initially, it has a tendency to settle into "sharp" local minima which generalize poorly to unseen data.
SGD with Momentum, carefully tuned with a learning rate scheduler, explores the landscape more physically and consistently finds flatter, more robust
minima, yielding higher final test accuracy for CNNs.
Why This Is Asked: Knowing the tradeoff between training speed and generalization.
Q11. Explain Nesterov Momentum and why it is better than standard momentum.
Answer Framework:
Standard momentum calculates the gradient at the current position, then adds the velocity to take a step.
Nesterov calculates where the velocity would take you (the look-ahead position), and computes the gradient there.
This allows the optimizer to anticipate changes in the loss landscape and course-correct earlier, reducing the tendency to wildly overshoot minima.
Why This Is Asked: Differentiating between the two main types of momentum.
Q12. Swiggy has a sparse NLP dataset where the word "restaurant" appears 10,000 times and "hair" appears twice. How does Adam handle the learning
rates for the embeddings of these two words?
Answer Framework:
Adam scales the update by dividing by the square root of the accumulated squared gradients.
The embedding for "restaurant" receives massive, frequent gradients. Its denominator becomes huge, drastically shrinking its effective learning rate so
it doesn't bounce around.
The embedding for "hair" receives tiny, rare gradients. Its denominator is small, keeping its effective learning rate high so it can make meaningful
updates when it is finally seen.
Q13. In your TrOCR Hugging Face pipeline, the default optimizer is AdamW. What would happen if you forced it to use standard Adam?
Answer Framework:
Why This Is Asked: Applying deep learning history to Ashmi's actual project choices.
Answer Framework:
Q15. What is the difference between an epoch and a step in the context of a learning rate scheduler?
Answer Framework:
Answer Framework:
Q17. In Adam, the default for \(\beta_1\) is 0.9 and \(\beta_2\) is 0.999. What do these numbers represent?
Answer Framework:
They are the exponential decay rates for the moving averages.
\(\beta_1 = 0.9\) means the 1st moment (momentum) relies roughly on the last 10 steps.
\(\beta_2 = 0.999\) means the 2nd moment (variance tracking) has a very long memory, relying roughly on the last 1000 steps. This long memory is
required for stable scaling.
Why This Is Asked: Knowing what the hyperparameters actually control mathematically.
Q18. Swiggy's ETA model training loss is rapidly oscillating up and down wildly, never settling. What is the first hyperparameter you change?
Answer Framework:
Q19. You are fine-tuning a massive LLM. You set the learning rate to a tiny 1e-6, but the model's loss explodes to NaN on step 5. What scheduler feature
are you missing?
Answer Framework:
Warmup.
Even with a tiny learning rate, the completely untrained projection heads sitting on top of the LLM generate massive, chaotic gradients.
You must start the learning rate at absolute 0.0 and ramp it up to 1e-6 over hundreds of steps to allow the final layers to align before passing large
gradients backward.
A saddle point is a flat plateau that curves down in one direction but up in another.
It is dangerous because the gradient at the exact center is exactly zero.
Vanilla SGD will halt entirely at a saddle point, believing it has found a minimum. Momentum is required to "coast" through the flat spot and find the
downward curve.
Q21. [CODE QUESTION] Write a standard, bug-free PyTorch training loop for a single batch.
Answer Framework:
# 2. Forward pass
outputs = model(inputs)
loss = criterion(outputs, targets)
# 4. Update weights
[Link]()
Q22. Explain the physical memory cost of using the Adam optimizer compared to SGD.
Answer Framework:
SGD only requires storing the model weights and the current gradients (Memory = 2x parameter count).
Adam must store the weights, the gradients, the 1st moment (\(m\)), and the 2nd moment (\(v\)) for every single parameter.
Therefore, Adam consumes exactly double the optimizer state memory of SGD (Memory = 4x parameter count).
⚠ Common Wrong Answer: "They take the same memory."
Why This Is Asked: This is the precise reason algorithms like Adafactor or 8-bit Adam exist for LLM training—standard Adam consumes too much VRAM.
Q23. Swiggy wants to use Automatic Mixed Precision (AMP / FP16) to speed up training of a vision model. What specific parameter in the Adam optimizer
must you carefully monitor, and why?
Answer Framework:
Q24. In your TrOCR project, you froze the convolutional backbone and only fine-tuned the Transformer layers. How do you implement this in PyTorch so
the optimizer doesn't waste compute?
Answer Framework:
⚠ Common Wrong Answer: Just setting requires_grad=False without filtering the optimizer input.
Q25. What is gradient clipping, why is it necessary in LSTMs/RNNs, and how does it interact with the optimizer?
Answer Framework:
In sequential models like RNNs, gradients are multiplied repeatedly across time steps via the chain rule, leading to exponentially exploding gradients
that result in NaN weights.
Gradient clipping caps the maximum L2 norm of the gradient vector to a fixed threshold (e.g., 1.0).
It is applied after [Link]() but before [Link](). The optimizer then uses the clipped gradients for its internal moment
calculations.
⚠ Common Wrong Answer: "The optimizer does gradient clipping automatically."
Q26. You are using a Cosine Annealing learning rate scheduler, but your model converges to a terrible local minimum early and gets stuck there as the LR
decays. What variant of cosine annealing solves this?
Answer Framework:
Cosine Annealing with Warm Restarts (Stochastic Gradient Descent with Warm Restarts - SGDR).
Instead of a single curve down to zero, the LR drops to zero, and then instantly spikes back up to the maximum LR, and drops again in periodic cycles.
The sudden spike acts like a controlled explosion, blasting the optimizer out of the bad local minimum so it can find a better, flatter one.
⚠ Common Wrong Answer: "Just increase the initial learning rate."
Q27. How does the concept of "Sharp vs. Flat Minima" relate to model generalization at Swiggy?
Answer Framework:
A sharp minimum means the loss skyrockets if the weights change even slightly. A flat minimum means the weights can wiggle significantly without
changing the loss.
At inference time on real-world Swiggy data, the data distribution is slightly shifted from the training data. This shifts the loss landscape slightly.
If you are in a sharp minimum, that shift will push you up the steep wall, causing terrible accuracy. If you are in a flat minimum, the shift keeps you near
the bottom. Flat minima generalize better.
⚠ Common Wrong Answer: "Sharp minima are better because the loss is mathematically lower."
Why This Is Asked: The deepest intuition behind why we tune optimizers.
Q28. [CODE QUESTION] How do you pass different learning rates to different parts of a model in PyTorch (e.g., small LR for pre-trained backbone, large LR
for new classification head)?
Answer Framework:
You pass a list of dictionaries to the optimizer instead of a single parameter generator.
optimizer = [Link]([
{'params': model.pretrained_backbone.parameters(), 'lr': 1e-5},
{'params': model.new_head.parameters(), 'lr': 1e-3}
])
⚠ Common Wrong Answer: Trying to instantiate two separate optimizers. (Technically possible, but bad practice and breaks momentum/scheduler
tracking).
Q29. Adam divides the gradient by \(\sqrt{v_t}\). What happens mathematically if the gradient has been exactly constant for 1000 steps?
Answer Framework:
If the gradient is a constant \(c\), the 1st moment \(m_t\) converges to \(c\).
The 2nd moment \(v_t\) (squared gradients) converges to \(c^2\).
The update step is proportional to \(m_t / \sqrt{v_t} = c / \sqrt{c^2} = c / |c| = \pm 1\).
The magnitude of the gradient completely cancels out! The optimizer ignores the steepness of the slope and simply takes a step of size exactly equal to
the learning rate \(\eta\) in the direction of the sign.
⚠ Common Wrong Answer: "The step size gets bigger and bigger."
Q30. Why is the bias correction term \((1 - \beta^t)\) in Adam dependent on \(t\) (the time step)?
Answer Framework:
Because the moving average starts at \(0\), step 1 is a heavy mix of \(0\) and the new gradient, severely underestimating the true magnitude.
At \(t=1\), \((1 - \beta^1)\) is a small fraction, so dividing by it massively scales up the estimate to correct the bias.
As \(t \rightarrow \infty\), \(\beta^t \rightarrow 0\). The correction term \((1 - 0) = 1\). The bias correction mathematically fades away exactly as the
moving average accumulates enough real data to be naturally accurate.
⚠ Common Wrong Answer: "It's just a constant scaling factor."
Why This Is Asked: Understanding the elegance of the moving average initialization.
Tier 4 — Expert / Deep Dive (Hard)
Final rounds. Mathematical intuition. Failure modes. Scale.
Q31. Derive the L2 coupling problem in Adam mathematically. Show exactly why standard L2 regularization fails.
Answer Framework:
True weight decay target: \(\theta_{t+1} = \theta_t - \eta \nabla L - \eta \lambda \theta_t\).
Standard Adam adds L2 to the loss: \(Loss = L + \frac{\lambda}{2}\theta^2\).
The gradient becomes: \(g_t = \nabla L + \lambda \theta_t\).
Adam's update: \(\theta_{t+1} = \theta_t - \frac{\eta}{\sqrt{v_t}} g_t\).
Substitute \(g_t\): \(\theta_{t+1} = \theta_t - \frac{\eta}{\sqrt{v_t}} \nabla L - \frac{\eta \lambda}{\sqrt{v_t}} \theta_t\).
Conclusion: The weight decay term is now divided by \(\sqrt{v_t}\). It is dynamically scaled by the gradient history, which destroys the uniform penalty
required for true L2 regularization.
⚠ Common Wrong Answer: Failing to substitute the gradient into the denominator.
Q32. In distributed training across 64 GPUs at Swiggy, you increase your effective batch size from 256 to 16,384. According to the "Linear Scaling Rule,"
what must you do to the learning rate, and why?
Answer Framework:
You must scale the learning rate linearly by the same factor (multiply by 64).
Why: A massive batch size means the gradient variance is incredibly small (it perfectly represents the true dataset gradient). Because there is almost
zero noise, you can safely take massive leaps down the mountain without risk of bouncing in the wrong direction.
If you don't increase the LR, the model will take tiny, accurate steps, and training will take forever, completely wasting the 64 GPUs.
⚠ Common Wrong Answer: "Decrease the learning rate because the batch is bigger."
Why This Is Asked: Distributed deep learning laws (Goyal et al., "Accurate, Large Minibatch SGD").
Q33. What is the AMSGrad variant of Adam, and what theoretical flaw in Adam does it fix?
Answer Framework:
Standard Adam can theoretically fail to converge in highly specific synthetic scenarios because the denominator (\(\sqrt{v_t}\)) can occasionally shrink
(if recent gradients are small), causing a sudden, massive spike in the learning rate late in training.
AMSGrad fixes this by keeping a running maximum of all past \(v_t\) values. It strictly forces the denominator to be monotonically increasing or stable,
guaranteeing that the effective learning rate never spikes unexpectedly.
⚠ Common Wrong Answer: Blanking on the name.
Why This Is Asked: Deep knowledge of optimizer literature (ICLR 2018 Best Paper).
Q34. [CODE QUESTION] How do you implement Gradient Accumulation in PyTorch, and why is it useful?
Answer Framework:
Useful when your GPU memory is too small for a desired batch size (e.g., you want batch 32, but can only fit 8).
You run the forward/backward pass 4 times without zeroing gradients. Autograd naturally adds them together. Then you step the optimizer once.
accumulation_steps = 4
optimizer.zero_grad()
for i, (inputs, targets) in enumerate(dataloader):
outputs = model(inputs)
loss = criterion(outputs, targets) / accumulation_steps # scale loss!
[Link]() # accumulates
if (i + 1) % accumulation_steps == 0:
[Link]()
optimizer.zero_grad()
⚠ Common Wrong Answer: Forgetting to divide the loss by the accumulation steps, resulting in gradients 4x larger than intended.
Why This Is Asked: Essential engineering for training large models (LLMs/Vision) on limited hardware.
Q35. Why do optimizers like Adam struggle with the "Catastrophic Forgetting" phenomenon during sequential fine-tuning, and how might optimizer state
contribute to it?
Answer Framework:
When moving from Task A to Task B, Adam's momentum (\(m_t\)) and variance (\(v_t\)) states are still perfectly calibrated for the loss landscape of Task
A.
On step 1 of Task B, Adam uses this old momentum to violently update the weights in directions completely inappropriate for Task B, destroying the
weights learned for Task A.
Resetting the optimizer state (re-initializing Adam) when switching tasks is mandatory to prevent this immediate catastrophic shift.
⚠ Common Wrong Answer: "It's just a model capacity problem."
Q36. Swiggy uses RLHF (Reinforcement Learning from Human Feedback) to align a customer support LLM. The PPO algorithm uses two optimizers: one
for the Policy network, one for the Value network. Why is the learning rate for the Value network typically set 10x higher than the Policy network?
Answer Framework:
The Value network is solving a simple regression problem (predicting the expected reward). It needs to adapt quickly to provide accurate baselines.
The Policy network is navigating a highly sensitive, high-dimensional probability space. Large updates will collapse the policy (KL divergence explodes).
It must move very slowly.
⚠ Common Wrong Answer: "Because the value network is smaller."
Q37. What is "Gradient Centralization" and how does it act as an implicit regularizer inside the optimizer?
Answer Framework:
It is a technique where you subtract the mean of the gradient vectors from the gradients themselves before passing them to the optimizer update rule (\
(g_{new} = g - \text{mean}(g)\)).
Mathematically, it constrains the weight space to a hyperplane, which significantly smooths the loss landscape and improves the Lipschitz continuity of
the gradients. It makes training highly robust to bad initialization.
⚠ Common Wrong Answer: Confusing it with Batch Normalization.
Q38. Why does the Hugging Face implementation of AdamW include a correct_bias parameter that defaults to True, but standard PyTorch
[Link] does not have this flag explicitly exposed in the same way?
Answer Framework:
Hugging Face originally ported their AdamW directly from the BERT original source code (TensorFlow).
The original BERT AdamW implementation controversially omitted the bias-correction step for the first few steps, heavily relying on the learning rate
warmup to handle the early instability.
The correct_bias=True flag allows users to toggle between mathematically pure AdamW and the historically accurate BERT implementation.
PyTorch implements the mathematically pure version by default.
⚠ Common Wrong Answer: "Hugging face is just buggy."
Q39. What is the Hessian-Free (2nd Order) optimization approach, and why don't we use it for deep learning instead of 1st Order (Adam/SGD)?
Answer Framework:
1st order methods use the Jacobian (gradients). 2nd order methods (like Newton's method) use the Hessian (curvature/second derivatives), which
allows them to jump directly to the minimum in a single step for quadratic surfaces.
We don't use them because computing and inverting the Hessian matrix for a neural network with \(N\) parameters requires \(O(N^3)\) operations and \
(O(N^2)\) memory. For a 100-million parameter model, the Hessian has \(10^{16}\) elements, which is computationally impossible to store or invert.
⚠ Common Wrong Answer: "Second order methods don't work for neural networks." (They work beautifully, they are just impossible to compute).
Q40. [CODE QUESTION] How do you extract and save the internal state of an Adam optimizer (the moment vectors) so you can resume training later
exactly where you left off?
Answer Framework:
# Saving
checkpoint = {
'model_state': model.state_dict(),
'optimizer_state': optimizer.state_dict() # Critical! Contains m_t and v_t
}
[Link](checkpoint, '[Link]')
# Resuming
checkpoint = [Link]('[Link]')
model.load_state_dict(checkpoint['model_state'])
optimizer.load_state_dict(checkpoint['optimizer_state'])
⚠ Common Wrong Answer: Only saving the model weights. If you resume with a fresh Adam optimizer, \(m_t\) and \(v_t\) are zero, causing massive
gradient shocks that ruin the model.
In neural networks, the matrix multiplications (\(W \cdot x + b\)) are the straight pipes. They only perform linear transformations (scaling and rotating). If you stack 100
linear layers without activation functions, mathematically, they collapse into a single linear layer. An activation function is the "curved joint." It takes the straight line and
introduces a bend, a threshold, or a curve. This allows the neural network to warp its understanding of the data to fit incredibly complex, non-linear patterns (like the
shape of a dog in an image, or the sarcasm in a sentence).
With Activation (\(f\)): \(y_1 = f(W_1x)\). \(y_2 = f(W_2y_1)\). Because \(f\) is non-linear (like \(x^2\), or \(\max(0, x)\)), you can no longer collapse the math. The depth
now matters.
The Universal Approximation Theorem: This mathematical theorem states that a neural network with at least one hidden layer and a non-linear activation function
can approximate any continuous function to any degree of accuracy, provided it has enough neurons. Activation functions are the sole source of this superpower.
1. Linear Transformation: The neuron takes a weighted sum of its inputs and adds a bias: \(z = Wx + b\).
2. Activation: The neuron applies the non-linear activation function to that sum: \(a = f(z)\).
3. Forward Pass: It passes the result \(a\) to the next layer.
Swiggy Relevance
Swiggy's ETA prediction (MIMO) relies heavily on non-linear relationships. For example, traffic impact is non-linear: going from 10 cars to 20 cars has little effect, but
going from 10,000 to 10,010 cars causes gridlock. Activation functions allow the neural network to model these sharp, non-linear tipping points in delivery logistics.
Code Snippet
import torch
# Without activation
out_no_act = (x @ W1) @ W2
# Is exactly equal to a single layer: x @ (W1 @ W2)
Free Resources
Understanding Neural Networks: The Universal Approximation Theorem ([Link]
theorem-8a389a33d30a)
2. Leaky ReLU:
Formula: \(f(x) = \max(\alpha x, x)\) where \(\alpha\) is a small constant like 0.01.
Derivative: \(1\) if \(x > 0\), \(\alpha\) if \(x < 0\).
Why it exists: It fixes the Dying ReLU problem. Negative inputs now leak a tiny gradient back through the network, allowing "dead" neurons to slowly revive.
Use: Heavily used in GANs (Generative Adversarial Networks) where discriminator stability is critical.
Identical to Leaky ReLU, but \(\alpha\) is not a fixed constant; it is a learnable parameter updated via backpropagation. Used in advanced ResNets.
Formula: \(x\) if \(x > 0\), \(\alpha(e^x - 1)\) if \(x \leq 0\).
Why it exists: It creates a much smoother, curved negative region rather than a sharp angle. It pulls the mean activations closer to zero.
Cons: Computing \(e^x\) is computationally expensive compared to a simple \(\max()\).
5. SiLU / Swish:
Swiggy Relevance
For Swiggy's core deep learning models running at immense scale (like the MIMO delivery time regressor or computer vision models predicting food quality), inference
latency is critical. ReLU is the absolute fastest activation function available because it maps perfectly to low-level GPU hardware instructions (a simple max operation).
import torch
import [Link] as F
Free Resources
The Dying ReLU Problem Explained ([Link]
3. Softmax:
Swiggy Relevance
If Swiggy runs a binary fraud detection model on a transaction, the final node uses a Sigmoid activation to output a 98% probability of fraud. If Swiggy runs an image
classifier to detect if an uploaded photo is "Menu", "Food", "Storefront", or "Receipt", the final layer uses Softmax to output a probability distribution across those 4
mutually exclusive classes.
Code Snippet
import torch
import [Link] as F
Free Resources
Softmax and Temperature ([Link] - Excellent visual guide.
16.4 GELU and SwiGLU (Transformer Activations)
What Is It? (Plain English First)
ReLU is a harsh bouncer. It draws a strict line at exactly 0.0. Transformers (the architecture behind all LLMs) process incredibly nuanced, probabilistic data via
Attention. A harsh line causes instability.
GELU and SwiGLU are like bouncers that check your ID, but instead of an immediate "yes/no," they use a probability curve. They smoothly transition from blocking
negative numbers to letting positive numbers through. They are computationally expensive, but they are the secret sauce that makes massive Transformers
mathematically stable.
Formula: \(f(x) = x \cdot \Phi(x)\) where \(\Phi(x)\) is the Cumulative Distribution Function (CDF) of the standard normal distribution.
Approximation: Because calculating the CDF is expensive, it is usually approximated as: \(0.5x \left( 1 + \tanh\left(\sqrt{\frac{2}{\pi}} (x + 0.044715x^3)\right)
\right)\)
Intuition: Instead of a hard threshold like ReLU, GELU weights the input \(x\) by how likely it is to be positive under a normal distribution. It is a smooth,
probabilistic gate.
Use: The absolute standard for encoder-based Transformers like BERT, IndicBERT, and GPT-2.
Swiggy Relevance
If Swiggy deploys a customer-service chatbot powered by a state-of-s-the-art open-source model (like Llama 3), that entire system is built on SwiGLU activations. If
Swiggy trains a smaller, in-house embedding model for neural menu search, they are likely using GELU.
1. IndicBERT (Malayalam Cyberbullying): BERT architecture. It uses GELU in its Feed-Forward blocks.
2. Sarathī (Llama 3.1): Llama architecture. It explicitly replaced standard activations with SwiGLU. You must be able to state this if asked what architectural
improvements Llama made over older models.
import torch
import [Link] as F
Free Resources
GELU Paper ([Link]
GLU Variants Improve Transformer (SwiGLU Paper) ([Link]
Answer Framework:
To introduce non-linearity.
Without them, no matter how many layers a network has, the series of matrix multiplications mathematically collapses into a single linear
transformation.
Non-linear activations allow the network to approximate complex, curved, non-linear functions (Universal Approximation Theorem).
Why This Is Asked: The most fundamental question regarding neural network theory.
Q2. What is the mathematical formula for ReLU, and what is its derivative for positive inputs?
Answer Framework:
Answer Framework:
If a neuron's weights update such that its pre-activation sum (\(Wx + b\)) is always negative for all inputs, ReLU will constantly output 0.
Because the derivative of ReLU for negative inputs is 0, no gradients will ever flow backward through this neuron.
The neuron is permanently "dead" and cannot recover.
Why This Is Asked: Testing knowledge of common failure modes in basic architectures.
Q4. Name one activation function that solves the Dying ReLU problem and how it does it.
Answer Framework:
Leaky ReLU.
Instead of outputting exactly 0 for negative inputs, it outputs a small scaled version of the input (e.g., \(0.01x\)).
This allows a small, non-zero gradient to flow backward, allowing the neuron a chance to update and "revive."
Q5. Why is Sigmoid rarely used in hidden layers of deep networks today?
Answer Framework:
Why This Is Asked: Understanding deep learning history and why ReLU took over.
Q6. What activation function is standard for the hidden states of LSTMs/RNNs?
Answer Framework:
Tanh.
It is zero-centered and bounded between -1 and 1, which helps keep the internal memory states stable and prevents numbers from exploding over long
sequential updates.
Q7. If you are predicting whether a Swiggy image contains "Food", "Menu", "Receipt", or "Storefront" (mutually exclusive), what is the final activation
function?
Answer Framework:
Softmax.
It normalizes the output logits into a probability distribution that sums to exactly 1.
Q8. What activation function does BERT (like your IndicBERT model) use in its feed-forward layers?
Answer Framework:
Q9. What activation function does Llama 3 (like your Sarathī RAG model) use?
Answer Framework:
SwiGLU.
Q11. Swiggy wants to tag restaurants with attributes: "Offers Discounts", "Vegetarian Options", "Late Night", "Dine-in". A restaurant can have any
combination of these. What output activation function do you use?
Answer Framework:
Why This Is Asked: The most common trap in classification system design.
Q12. How does the "Temperature" parameter mathematically alter a Softmax distribution?
Answer Framework:
You divide the raw logits by the Temperature (\(T\)) before exponentiating. \(Softmax(z/T)\).
A high temperature (\(T > 1\)) shrinks the logits closer together, creating a flatter, more uniform distribution.
A low temperature (\(T < 1\)) exaggerates the differences, pushing the highest logit toward 100% and crushing the others, creating a sharp,
deterministic distribution.
Q13. In your Sarathī project, why did you set the Llama 3.1 temperature to 0.1?
Answer Framework:
Why This Is Asked: Connecting hyperparameter theory directly to Ashmi's resume logic.
Why This Is Asked: Understanding the intuition behind complex NLP formulas.
Q15. Why does the SwiGLU activation function require three weight matrices in the Feed-Forward Network instead of two?
Answer Framework:
Q16. If Tanh and Sigmoid both suffer from vanishing gradients, why is Tanh generally preferred over Sigmoid in hidden layers (like in LSTMs)?
Answer Framework:
Tanh is zero-centered (range -1 to 1), whereas Sigmoid is strictly positive (range 0 to 1).
Zero-centered outputs mean the gradients during backpropagation can easily flow in both positive and negative directions, preventing the weights from
zig-zagging inefficiently during gradient descent.
Answer Framework:
Q18. You are training a GAN (Generative Adversarial Network) to generate Swiggy food images. The discriminator network is suffering from dead neurons.
What is the standard fix?
Answer Framework:
Q19. What is the non-monotonic property of the Swish (SiLU) activation function?
Answer Framework:
A monotonic function (like ReLU) only goes up or stays flat. It never goes down.
Swish dips slightly below zero for small negative inputs before eventually returning to zero for large negative inputs.
This non-monotonic "bump" allows the network to capture slight negative correlations before cutting them off, which empirically improves deep CNN
performance.
Q20. In PyTorch, if you use [Link], should you apply a Softmax activation to the final layer of your model?
Answer Framework:
No.
[Link] in PyTorch internally applies LogSoftmax automatically before computing the negative log likelihood.
Applying Softmax yourself beforehand will mathematically apply it twice, destroying the gradients and ruining training.
Q21. [CODE QUESTION] Implement the Leaky ReLU function manually using PyTorch tensor operations without using
[Link].leaky_relu.
Answer Framework:
⚠ Common Wrong Answer: Using slow Python if/else statements instead of vectorized tensor operations.
Q22. Swiggy is transitioning their search ranking model from a 5-layer MLP to a 100-layer MLP. They currently use ReLU. What activation-related issues
might they face, and how should they mitigate them?
Answer Framework:
At 100 layers, they are highly likely to encounter widespread Dying ReLU problems, as repeated large updates will kill a massive percentage of the
network's capacity.
Mitigation: Switch to Leaky ReLU or SiLU (Swish) to ensure gradient flow for negative pre-activations. Ensure Batch Normalization is used before the
activations to keep inputs centered. Use He initialization specifically tuned for ReLUs.
⚠ Common Wrong Answer: "ReLU is fine for 100 layers without changes."
Q23. Why do large language models (like Llama) use SwiGLU, which increases parameter count via a third matrix, instead of just using GELU?
Answer Framework:
Gated Linear Units (GLUs) perform multiplicative gating (\(A \otimes B\)), which allows the network to act as a dynamic routing mechanism, deciding
precisely which information passes forward based on the context.
To make it a fair comparison, LLMs reduce the hidden dimension size of the FFN so the total parameter count remains exactly the same as a standard
GELU network. Even with fewer dimensions, the multiplicative routing of SwiGLU yields significantly lower perplexity/higher accuracy.
⚠ Common Wrong Answer: "They use it because it's faster to compute." (It's slower).
Q24. Explain the relationship between the Universal Approximation Theorem and the choice of activation function. Could a network use \(f(x) = x^2\) as its
activation?
Answer Framework:
The theorem requires the activation function to be non-constant, bounded, and monotonically-increasing (historically) or simply non-polynomial
continuous (modern proofs).
Yes, \(f(x) = x^2\) is non-linear and theoretically satisfies modern formulations of the theorem (networks with polynomial activations can approximate
functions).
However, in practice, \(x^2\) is a terrible choice because its derivative is \(2x\). For large inputs, the gradient explodes to infinity, making gradient
descent impossible to stabilize.
⚠ Common Wrong Answer: "No, you can only use ReLU or Sigmoid."
Why This Is Asked: Merging pure mathematics with practical optimization constraints.
Q25. [CODE QUESTION] You want to implement Knowledge Distillation to train a tiny Swiggy ETA model using a massive teacher model. How do you
implement Temperature Scaling in PyTorch to get the "soft targets" from the teacher?
Answer Framework:
You must divide the teacher's raw logits by \(T\) before applying Softmax.
# Note: student logits must ALSO be divided by T during the KL Divergence loss calculation
⚠ Common Wrong Answer: Dividing the output of the Softmax by \(T\) (Mathematically incorrect and breaks the sum-to-1 rule).
Q26. Why is the derivative of ReLU defined as \(0\) at exactly \(x=0\), when mathematically the derivative does not exist there?
Answer Framework:
At exactly \(x=0\), there is a "kink" in the function (a sharp corner), meaning the left-hand limit and right-hand limit do not match.
In machine learning, we use "subgradients" for non-smooth optimization. Any slope between 0 and 1 is a valid subgradient at \(x=0\). Software
frameworks like PyTorch arbitrarily pick 0 (or sometimes 0.5) to allow the backward pass to compute without throwing a NaN error. The probability of a
floating-point number being exactly 0.0000000 is infinitely small anyway, so it rarely impacts real training.
⚠ Common Wrong Answer: "The derivative is naturally 0 there."
Q27. In your TrOCR model, what happens if the inputs to the GELU activation function are heavily unnormalized (e.g., massive variance)?
Answer Framework:
Why This Is Asked: Understanding how normalization layers and activation layers perfectly intertwine.
Q28. If you have a neural network that must output a strictly negative number (e.g., predicting depth underwater), what activation function should the final
layer use?
Answer Framework:
Q29. What is the "Exploding Gradient" problem, and why don't activation functions like ReLU solve it?
Answer Framework:
Exploding gradients occur when the chain rule multiplies derivatives \(>1\) repeatedly, causing gradients to approach infinity.
ReLU solves the vanishing gradient problem because its positive derivative is \(1\), not \(<1\) like Sigmoid.
However, the chain rule multiplies the activation derivative by the weights. If the weight matrices have eigenvalues \(>1\), multiplying by ReLU's \(1\) still
allows the product to grow exponentially.
We need weight initialization (He/Xavier), Gradient Clipping, and Normalization to solve exploding gradients.
⚠ Common Wrong Answer: "ReLU solves both vanishing and exploding gradients."
Why This Is Asked: Clarifying a major misconception about what ReLU actually fixes.
Q30. [CODE QUESTION] Swiggy needs an ultra-fast approximation of GELU for an edge device where erf() (error function) is too slow. Write the
mathematical approximation commonly used in code.
Answer Framework:
def fast_gelu_approx(x):
# Uses tanh instead of the heavy Gaussian CDF
return 0.5 * x * (1 + [Link]([Link](2 / [Link]) * (x + 0.044715 * [Link](x, 3))))
⚠ Common Wrong Answer: Using the exact formula x * 0.5 * (1 + [Link](x / [Link](2))) which defeats the purpose of the fast
approximation prompt.
Why This Is Asked: Expert knowledge of how foundational models are optimized in source code.
Q31. Derive the derivative of the Sigmoid function \(\sigma(x)\) in terms of itself (i.e., express \(\sigma'(x)\) using \(\sigma(x)\)). Why is this specific
algebraic form historically significant?
Answer Framework:
\(\sigma(x) = (1 + e^{-x})^{-1}\)
Chain rule: \(\sigma'(x) = -1 \cdot (1 + e^{-x})^{-2} \cdot (-e^{-x})\)
Rewrite: \(\frac{e^{-x}}{(1 + e^{-x})^2} = \left(\frac{1}{1 + e^{-x}}\right) \left(\frac{e^{-x}}{1 + e^{-x}}\right)\)
Add/subtract 1 in numerator of second term: \(\sigma(x) \left(\frac{1 + e^{-x} - 1}{1 + e^{-x}}\right)\)
Result: \(\sigma'(x) = \sigma(x)(1 - \sigma(x))\).
Significance: Because the derivative can be calculated entirely from the output of the forward pass, early deep learning frameworks (which were highly
memory constrained) didn't need to save the pre-activation input \(x\) in memory for the backward pass. They just reused the stored output.
⚠ Common Wrong Answer: Failing the algebraic manipulation.
Q32. In your Sarathī project utilizing Llama 3.1, the SwiGLU activation function is defined as \(\text{Swish}(xW) \otimes xV\). What happens to the gradient
flow backward through this element-wise multiplication (\(\otimes\))?
Answer Framework:
By the product rule of calculus (\(d(uv) = u'v + uv'\)), the gradient splits into two distinct pathways.
Pathway 1 passes through the linear projection \(V\), scaled by the Swish gate.
Pathway 2 passes through the Swish gate and the linear projection \(W\), scaled by the \(V\) projection.
This dual-pathway gradient flow allows the optimizer to dynamically adjust both the "content" (\(V\)) and the "gate" (\(W\)) independently based on the
error signal, creating a highly stable and expressive optimization manifold compared to single-pathway ReLU networks.
⚠ Common Wrong Answer: Assuming standard single-path backpropagation.
Q33. What is the Lipschiz continuity of an activation function, and why does ReLU having a Lipschitz constant of 1 matter for network stability?
Answer Framework:
A function is 1-Lipschitz if the absolute difference between outputs is never greater than the absolute difference between inputs (\(|f(x) - f(y)| \leq |x -
y|\)).
ReLU's max slope is 1, so it is 1-Lipschitz.
This matters immensely for deep networks: it guarantees that the activation function itself will not amplify perturbations (noise, adversarial attacks, or
exploding gradients). The variance of the signal is strictly bounded by the weight matrices, not exponentially amplified by the activations.
⚠ Common Wrong Answer: Confusing Lipschitz continuity with differentiability.
Q34. [CODE QUESTION] Implement a custom PyTorch Autograd Function for a Heaviside step activation (0 if \(x<0\), 1 if \(x>0\)) using the Straight-Through
Estimator (STE) bypass for the backward pass.
Answer Framework:
The true derivative of a step function is 0 everywhere (and undefined at 0), meaning learning halts. STE fakes the backward pass by returning the
incoming gradient untouched (acting like the derivative is 1).
class StraightThroughStep([Link]):
@staticmethod
def forward(ctx, x):
return (x > 0).float()
@staticmethod
def backward(ctx, grad_output):
# Fake the gradient! Just pass it straight through.
return grad_output
Why This Is Asked: Expert autograd manipulation used heavily in Quantization and VQ-VAEs.
Q35. The Softmax function is mathematically translation invariant. Prove this, and explain why it causes numerical instability in code if not handled.
Answer Framework:
Proof: \(Softmax(z_i - c) = \frac{e^{z_i - c}}{\sum e^{z_j - c}} = \frac{e^{-c} e^{z_i}}{e^{-c} \sum e^{z_j}}\). The \(e^{-c}\) cancels out, returning original
Softmax.
Instability: If logits \(z\) are huge (e.g., 1000), \(e^{1000}\) overflows to Inf in float32, yielding NaN.
Solution: Because it is translation invariant, software implementations subtract the maximum logit from all logits (\(c = \max(z)\)). This makes the largest
value \(e^0 = 1\), strictly bounding the exponentiation to \((0, 1]\) and preventing overflow completely without changing the math.
⚠ Common Wrong Answer: Not knowing the max-subtraction trick.
Why This Is Asked: The most famous numerical stability trick in deep learning software engineering.
Q36. Contrast the use of Swish in EfficientNet with GELU in ViT (Vision Transformers). Why didn't Google use Swish for ViT?
Answer Framework:
Swish was discovered via Neural Architecture Search specifically to optimize CNN blocks (MobileNet/EfficientNet). Its non-monotonic bump helps
preserve spatial edge features.
ViT (Vision Transformer) ported the NLP Transformer architecture directly to vision. NLP architectures converged on GELU because its probabilistic
derivation (Gaussian CDF) perfectly models the expected distribution of dot-products in Attention mechanisms.
While mathematically similar, their empirical performance splits heavily along structural lines (CNNs favor Swish/SiLU, Attention favors GELU/SwiGLU).
⚠ Common Wrong Answer: "They are exactly the same."
Why This Is Asked: Deep architectural history spanning Vision and NLP.
Q37. Swiggy trains a model with ELU activations. The junior engineer initializes the weights using He (Kaiming) initialization. Why is this theoretically
mismatched?
Answer Framework:
He initialization (variance = \(2/n\)) was explicitly derived under the mathematical assumption that the activation function is ReLU, which perfectly zeroes
out exactly 50% of the activations, cutting the variance in half.
ELU does not zero out the negative half; it smoothly maps them to negative values. Therefore, ELU retains much more than 50% of the signal variance.
Using He initialization with ELU will result in the variance exponentially expanding across layers, potentially destabilizing early training. (Xavier or a
custom ELU initialization is required).
⚠ Common Wrong Answer: "He initialization is best for everything."
Why This Is Asked: Expert knowledge linking activation functions to their derived initialization schemes.
Q38. Why is computing the softmax across a vocabulary of 100,000 words (like in Llama 3) a massive computational bottleneck, and what is a classical
approximation to avoid it?
Answer Framework:
Softmax requires computing \(e^x\) for all 100,000 words to calculate the denominator sum. At every single generation step, this is a massive \(O(V)\)
operation.
Classical approximation: Hierarchical Softmax. It builds a binary tree of the vocabulary. Instead of calculating 100,000 probabilities, the model makes
binary decisions down the tree, reducing the complexity to \(O(\log_2 V)\) (approx. 17 operations).
(Note: Modern GPUs are so fast at matrix multiplication that dense Softmax is usually brute-forced anyway, but Hierarchical Softmax is the classical
algorithmic answer).
⚠ Common Wrong Answer: Blanking on the \(O(V)\) denominator sum problem.
Q39. Explain the relationship between the Log-Sum-Exp trick and Softmax.
Answer Framework:
The Log-Sum-Exp (LSE) is a smooth approximation of the maximum function: \(\text{LSE}(x) = \log(\sum e^{x_i})\).
Softmax is actually the gradient (derivative) of the Log-Sum-Exp function.
\(\frac{\partial}{\partial x_i} \log(\sum e^{x_j}) = \frac{e^{x_i}}{\sum e^{x_j}} = Softmax(x_i)\).
This elegant mathematical duality is why optimizing Cross Entropy Loss (which uses LSE internally) yields Softmax probabilities.
⚠ Common Wrong Answer: Not knowing they are related via calculus.
Q40. [CODE QUESTION] You are writing a custom CUDA kernel for PyTorch to fuse an activation function. Why is SiLU/Swish (\(\text{SiLU}(x) = x \cdot
\sigma(x)\)) significantly harder to memory-optimize during the backward pass than ReLU?
Answer Framework:
ReLU's derivative is just a sign check (x > 0). You only need the binary mask of the forward pass, which can be stored in a single bit.
SiLU's derivative is \(\text{SiLU}'(x) = \text{SiLU}(x) + \sigma(x)(1 - \text{SiLU}(x))\).
To compute this exactly in the backward pass, the autograd engine MUST store the full 32-bit floating-point input tensor \(x\) (or the exact forward
output) in VRAM. This massively increases the memory footprint during training compared to ReLU, causing memory bottlenecks for ultra-deep
networks.
⚠ Common Wrong Answer: "Because sigmoid is slow to compute." (Compute speed is irrelevant to the backward pass memory footprint problem).
Why This Is Asked: Elite understanding of how math dictates GPU memory architecture.
High Bias (Underfitting): You just look at the first question of one exam, declare "all math is just adding numbers," and go to sleep. You fail the test because
your theory was too simple to capture the real complexity. You were highly biased toward your simple theory.
High Variance (Overfitting): You memorize the exact numbers and answers of every single past exam question perfectly. But when the actual test changes
the numbers slightly, you fail completely because you can't generalize. Your performance varies wildly depending on the exact data you see.
The goal of Machine Learning is to find the perfect middle ground: a model complex enough to understand the underlying rules (low bias), but simple enough that it
doesn't memorize the noise (low variance).
The Math
The Total Error Decomposition: For any model, the expected error on unseen data is mathematically proven to be: \(\text{Total Error} = \text{Bias}^2 +
\text{Variance} + \text{Irreducible Error}\)
Bias: The difference between the average prediction of our model and the correct value.
Variance: The variability of the model prediction for a given data point.
Irreducible Error: The inherent noise in the data itself (you can never predict the exact ETA of a delivery because a random dog might run into the street).
Increasing model complexity (adding layers, neurons, or polynomial degrees) decreases Bias but increases Variance.
Adding Regularization (L1, L2, Dropout) increases Bias but decreases Variance.
Swiggy Relevance
Swiggy's MIMO (Multi-Input Multi-Output) delivery ETA model relies on highly dynamic features like traffic and weather. If the model is too complex (High Variance), it
might memorize that "Driver X on Tuesday at 4:02 PM took 12 minutes" and fail when it's 4:03 PM. Swiggy must actively increase the bias of this model using Dropout
and L2 Regularization so it learns the general trend of "Tuesday Afternoons" rather than memorizing exact timestamps.
Goal: Keep the variance of the inputs exactly equal to the variance of the outputs across a layer.
Formula: Draw weights from a distribution with Variance = \(\frac{1}{n_{in}}\) (or \(\frac{2}{n_{in} + n_{out}}\)).
Use: Designed explicitly for networks using Tanh or Sigmoid activations.
3. He (Kaiming) Initialization:
How: Computes the gradient over the entire dataset before taking a single optimizer step.
Pros: A perfectly accurate, noise-free gradient pointing exactly to the minimum.
Cons: Computationally impossible. You cannot fit 1 million Swiggy orders into GPU VRAM to calculate one step.
How: Computes the gradient using exactly one data point (Batch Size = 1).
Pros: Very low memory. Updates happen instantly.
Cons: The gradient is incredibly noisy (one weird order throws the model completely off). It also destroys hardware efficiency because GPUs are
designed to do massive parallel matrix math, not process one item at a time.
How: Computes the gradient on a small chunk of data (e.g., 32, 64, or 256 items).
Why we use it: It perfectly balances the two extremes.
It allows for massively parallel GPU vectorization.
The gradient is accurate enough to descend smoothly.
The slight noise from the mini-batch actually acts as a regularizer, helping the model bounce out of sharp local minima.
If the gradients are mostly \(0.1\), multiplying \(0.1 \times 0.1 \times 0.1 \dots\) quickly results in \(0.000001\). The gradient vanishes. Early layers never learn.
If the gradients are mostly \(10\), multiplying \(10 \times 10 \times 10 \dots\) quickly results in \(1,000,000\). The gradient explodes. The weights become NaN
(Not a Number) and the model crashes.
⚙ The Solutions
Fixing Vanishing Gradients:
1. ReLU Activations: As discussed, the derivative of ReLU is exactly 1, preventing the multiplication from shrinking.
2. Residual Connections (ResNets): Adding the input \(x\) to the output \(F(x)\). The derivative of \(x\) is 1. This creates an uncorrupted "highway" for gradients
to flow backward through hundreds of layers.
3. LSTMs: The cell state in an LSTM acts exactly like a ResNet highway across time, solving the vanishing gradient problem inherent in standard RNNs.
1. Gradient Clipping: Before calling [Link](), you forcefully cap the maximum norm of the gradient vector to a threshold (e.g., 1.0). (Standard in
RNNs/Transformers).
2. Batch Normalization: Keeps the inputs strictly bounded, preventing activations from growing exponentially.
3. Proper Initialization (He/Xavier): Prevents the initial forward pass from generating exponentially massive outputs.
Precision: Out of all the transactions the model claimed were fraud, how many were actually fraud? (False Positives hurt Precision).
Recall: Out of all the actual fraud in the real world, how many did the model successfully find? (False Negatives hurt Recall).
F1-Score: The harmonic mean of Precision and Recall. \(2 \cdot \frac{Precision \cdot Recall}{Precision + Recall}\).
High Recall Focus: (Swiggy Fraud). Missing a fraudster costs Swiggy $500. Blocking a normal user by accident (False Positive) just requires them to do an
SMS verification. You tune the model for High Recall (catch all fraud, accept some false alarms).
High Precision Focus: (Swiggy Push Notifications). If you send a discount code for Meat to a Vegetarian (False Positive), they uninstall the app. You tune for
High Precision (only send notifications you are 99% sure they want, even if you miss some users).
ROC-AUC (Receiver Operating Characteristic): Plots True Positive Rate vs False Positive Rate. It is the industry standard for general classification.
However, if the data is severely imbalanced (e.g., 1% positive), the huge number of True Negatives visually inflates the ROC curve, making the model look
better than it is.
PR-AUC (Precision-Recall Curve): Completely ignores True Negatives. It only evaluates how well the model handles the positive minority class. This is the
gold standard for severe imbalance.
Ashmi's Resume Connection
In your Malayalam Cyberbullying detection (IndicBERT), bullying comments are likely a minority class (e.g., 5-10% of total comments). If you evaluated your model
using Accuracy, it would look artificially high. You must evaluate this project using Macro F1-Score or PR-AUC to prove it actually detected the minority bullying class.
Answer Framework:
Models with high bias underfit the data (too simple, ignore patterns).
Models with high variance overfit the data (too complex, memorize noise).
As complexity increases, bias goes down and variance goes up. The goal is to find the optimal point that minimizes total error on unseen data.
Why This Is Asked: The most fundamental theory question in Machine Learning.
Answer Framework:
Symmetry breaking.
If all weights are identical, every neuron computes the same output, receives the same gradient, and updates by the exact same amount. The network
will never learn distinct features.
Q3. What is the difference between Batch Gradient Descent and Mini-Batch Gradient Descent?
Answer Framework:
Batch GD calculates the gradient using the entire training dataset at once before updating weights.
Mini-Batch calculates the gradient on a small subset (e.g., 64 items). It is much faster, fits in GPU memory, and the slight noise provides a regularizing
effect.
Answer Framework:
Precision: True Positives / (True Positives + False Positives). "Of all the ones I flagged, how many were right?"
Recall: True Positives / (True Positives + False Negatives). "Of all the real ones out there, how many did I catch?"
Q5. Why is Accuracy a bad metric for Swiggy's fraud detection system?
Answer Framework:
Answer Framework:
Answer Framework:
Answer Framework:
Why This Is Asked: Understanding how modern architectures fix old problems.
Answer Framework:
He (Kaiming) Initialization.
Q11. Swiggy is launching a new feature warning users if a restaurant is likely to cancel their order. A false positive means the user gets scared and orders
elsewhere. A false negative means the user orders and gets canceled on later. Which metric do you optimize for?
Answer Framework:
Why This Is Asked: Translating business problems into mathematical optimization targets.
Q12. Why does He Initialization multiply the variance by 2 compared to Xavier Initialization?
Answer Framework:
Xavier was designed for symmetric activations like Tanh that pass both positive and negative signals.
ReLU zeroes out exactly half of the input distribution (all negative numbers). This halves the variance of the forward signal.
He Initialization multiplies the starting weight variance by 2 to perfectly offset this 50% loss of signal, keeping variance stable across layers.
Q13. In your IndicBERT cyberbullying project, you have 5% bullying text and 95% normal text. Would you use ROC-AUC or PR-AUC to evaluate it, and
why?
Answer Framework:
Why This Is Asked: Deep knowledge of metric behavior under severe imbalance.
Q14. How does Mini-Batch SGD act as a regularizer compared to full Batch Gradient Descent?
Answer Framework:
Because a mini-batch is a small sample of the full dataset, its calculated gradient is just a noisy estimate of the true global gradient.
This noise causes the optimizer to take slightly erratic steps. This "wiggle" prevents the model from settling into sharp, narrow local minima, allowing it
to bounce out and find flatter, more robust minima that generalize better.
Q15. You are training an RNN and notice the loss suddenly becomes NaN. What happened, and how do you fix it?
Answer Framework:
The Exploding Gradient problem occurred. Gradients multiplied across time steps exceeded float limits and became infinity/NaN.
The fix is Gradient Clipping. I would implement [Link].clip_grad_norm_ to cap the maximum length of the gradient vector to 1.0 before
calling [Link]().
Q16. If your Swiggy ETA model has high bias on the training set, what steps do you take?
Answer Framework:
High bias on the training set means the model is underfitting. It lacks the capacity to learn the data.
Solutions: Increase network depth or width, decrease regularization (lower weight decay, lower dropout), or add more complex/polynomial features.
Answer Framework:
It is the theoretical lower bound of error caused by noise inherent to the data itself, not the model.
For example, if two identical Swiggy orders (same restaurant, same distance, same weather) take 20 mins and 25 mins because of a random traffic
light, no model can predict that 5-minute difference. That is irreducible error.
Q18. Is it possible for a model to have both high bias and high variance?
Answer Framework:
Yes.
A model can completely miss the general underlying trend of the data (High Bias) but simultaneously aggressively overfit to the local noise of the
training points (High Variance). This is common in highly unoptimized deep networks on small datasets.
Why This Is Asked: Breaking the assumption that it's a perfect sliding scale.
Q19. In PyTorch, what happens to the gradients if you set the batch size to 1?
Answer Framework:
Q20. You are using a Random Forest for fraud detection instead of a Neural Network. How do you control the Bias-Variance tradeoff in a Random Forest?
Answer Framework:
Increasing the maximum depth of the trees decreases bias but increases variance (overfitting).
Increasing the number of trees (ensembling) strictly decreases variance without increasing bias.
Limiting the min_samples_split or max_features increases bias but decreases variance.
Q21. Swiggy's fraud dataset has 100 fraud cases and 100,000 legitimate cases. You train a model and achieve 90% Recall but only 2% Precision. Explain
what this means to the Swiggy business team.
Answer Framework:
"90% Recall means we successfully caught 90 out of the 100 actual fraudsters. That's great."
"However, 2% Precision means that out of all the people we blocked, only 2% were actual fraudsters. The other 98% were innocent customers."
"To catch those 90 fraudsters, we had to block roughly 4,400 legitimate users. This model is overly aggressive and the customer support complaints will
be catastrophic."
Q22. [CODE QUESTION] Write PyTorch code to implement Gradient Clipping correctly within a training loop.
Answer Framework:
optimizer.zero_grad()
outputs = model(inputs)
loss = criterion(outputs, targets)
[Link]()
[Link]()
⚠ Common Wrong Answer: Clipping the weights instead of the gradients, or clipping before backward().
Q23. Why do Residual Connections (ResNets) solve the Vanishing Gradient problem mathematically?
Answer Framework:
A standard layer is \(y = F(x)\). The gradient involves \(\frac{\partial F}{\partial x}\).
A ResNet block is \(y = F(x) + x\). The gradient is \(\frac{\partial F}{\partial x} + 1\).
Even if \(\frac{\partial F}{\partial x}\) vanishes to 0, the \(+1\) remains. The gradient flows completely uncorrupted backwards through the \(x\) identity
pathway, allowing networks to scale to thousands of layers.
⚠ Common Wrong Answer: "It gives the network a shortcut." (Must explain the \(+1\) derivative math).
Why This Is Asked: Mathematical intuition of the most famous computer vision architecture.
Q24. In the context of the Bias-Variance tradeoff, what effect does the "Bagging" (Bootstrap Aggregating) technique used in Random Forests have?
Answer Framework:
Deep Decision trees are inherently low bias but extremely high variance (they memorize the data).
Bagging trains many independent, high-variance trees on random subsets of the data, and then averages their predictions.
Averaging independent models mathematically reduces the variance by a factor of \(N\) without altering the expected bias. Therefore, Bagging strictly
reduces variance.
⚠ Common Wrong Answer: "It reduces bias."
Q25. You initialize a deep network with random numbers drawn from a uniform distribution between [-1, 1]. Why will this network likely fail to train?
Answer Framework:
Why This Is Asked: Proving why mathematically derived initializations are required.
Q26. What is the difference between Micro-F1 and Macro-F1 in a multi-class classification problem?
Answer Framework:
Macro-F1 calculates the F1-score independently for each class, and then takes the unweighted average. It treats the "Fraud" class and "Legitimate"
class equally, regardless of size. Excellent for evaluating minority class performance.
Micro-F1 aggregates the total True Positives, False Positives, and False Negatives globally across all classes, and then calculates F1. In an imbalanced
dataset, the massive majority class entirely dominates the Micro-F1 score.
⚠ Common Wrong Answer: Swapping the definitions.
Q27. How does the choice of batch size interact with the Learning Rate mathematically?
Answer Framework:
The "Linear Scaling Rule". If you increase the batch size by a factor of \(k\) (e.g., from 32 to 256, \(k=8\)), you should increase the learning rate by the
same factor \(k\).
Why: A larger batch size reduces the variance (noise) of the gradient estimate. Because you are more confident in the gradient direction, you can take a
proportionally larger step without risk of divergence.
⚠ Common Wrong Answer: "If batch size is bigger, lower the learning rate."
Q28. [CODE QUESTION] How do you initialize a specific linear layer in PyTorch using Xavier (Glorot) Uniform initialization?
Answer Framework:
import [Link] as nn
import [Link] as init
Q29. In your TrOCR fine-tuning, you have limited Malayalam data. Does Transfer Learning (using pre-trained weights) primarily reduce Bias or Variance?
Answer Framework:
Why This Is Asked: Viewing modern NLP practices through classical ML theory lenses.
Q30. Explain the "Double Descent" phenomenon in modern deep learning, which seems to contradict the classical Bias-Variance tradeoff.
Answer Framework:
Classical theory says as model complexity passes the optimal point, variance takes over and test error goes up (a U-shaped curve).
Modern research shows that if you keep increasing complexity past the point where training error reaches zero (massive over-parameterization, like
LLMs), the test error suddenly starts going down again.
This happens because the model has so many parameters it can perfectly interpolate the training data using incredibly smooth, simple functions, acting
as an implicit regularizer.
⚠ Common Wrong Answer: Not knowing the term.
Why This Is Asked: The most bleeding-edge theoretical question in modern ML.
Tier 4 — Expert / Deep Dive (Hard)
Final rounds. Mathematical intuition. Failure modes. Scale.
Answer Framework:
Q32. In an extreme imbalanced dataset (1 positive for every 10,000 negatives), the loss function is completely dominated by easy negatives. What specific
Loss Function solves this mathematically, and how?
Answer Framework:
Q33. What is the Fisher Information Matrix, and how does it relate to the curvature of the loss landscape and the Bias-Variance tradeoff?
Answer Framework:
The Fisher Information Matrix (FIM) measures the amount of information that an observable random variable carries about an unknown parameter.
In ML optimization, the FIM is asymptotically equivalent to the Hessian matrix (the second derivatives of the loss) under certain conditions.
A high trace of the FIM implies sharp curvature (a sharp minimum). Sharp minima are highly sensitive to data perturbations, directly indicating high
variance and poor generalization.
⚠ Common Wrong Answer: Blanking on information theory.
Q34. [CODE QUESTION] You need to evaluate Swiggy's fraud model. Write a scikit-learn function to compute the PR-AUC (Average Precision) score.
Answer Framework:
⚠ Common Wrong Answer: Passing predicted hard labels (0/1) instead of probabilities (y_probs) to the scoring function.
Why This Is Asked: Proving you actually code your evaluation metrics correctly.
Q35. How does the SMOTE (Synthetic Minority Over-sampling Technique) algorithm work mathematically to combat class imbalance, and why must it only
be applied to the training set?
Answer Framework:
Mechanism: It takes a minority data point, finds its \(k\)-nearest neighbors in the feature space, and draws lines between them. It randomly selects
points along these lines to synthesize completely new, fake minority examples.
Why Train Only: If you apply SMOTE before splitting your data, synthetic data derived from the test set leaks into the training set. The model will
artificially perform perfectly on the test set because it essentially saw the answers during training (Data Leakage).
⚠ Common Wrong Answer: "It just copies minority rows." (That's simple upsampling. SMOTE interpolates).
Why This Is Asked: Knowing the algorithms and the catastrophic data engineering traps associated with them.
Q36. Explain the concept of "Label Smoothing" and how it acts as a regularizer.
Answer Framework:
Instead of training a model on hard one-hot targets [1.0, 0.0, 0.0], you train it on soft targets [0.9, 0.05, 0.05].
If a model is trained on hard targets, it will push its logits to infinity to achieve a Softmax probability of exactly 1.0. This leads to massive overconfidence
and extreme overfitting (high variance).
Label smoothing forces the model to stop pushing the logits once it reaches 90% confidence. This bounds the gradients and prevents the model from
memorizing the training data too rigidly.
⚠ Common Wrong Answer: Confusing it with Knowledge Distillation.
Q37. What is "Gradient Checkpointing" (or Activation Recomputation), and what tradeoff does it enforce?
Answer Framework:
During the forward pass of a deep network, all intermediate activations must be saved in GPU memory so they can be used for the chain rule during the
backward pass. This causes Out-Of-Memory errors for massive models like LLMs.
Gradient Checkpointing saves only a few "checkpoint" activations. During the backward pass, it dynamically recomputes the missing activations on the
fly by running partial forward passes again.
The Tradeoff: It drastically reduces GPU Memory (VRAM) usage, at the direct cost of increasing Training Time (compute) by roughly 30%.
⚠ Common Wrong Answer: "It saves gradients to disk."
Answer Framework:
BatchNorm calculates its mean and variance based on the current mini-batch.
A very small batch size creates extremely noisy statistical estimates, which injects heavy stochastic noise into the forward pass, acting as a strong
regularizer.
A massive batch size creates highly accurate estimates, almost entirely removing the regularizing noise.
Therefore, if you scale your batch size up massively, you often have to manually increase Dropout or Weight Decay to compensate for the lost implicit
regularization of BatchNorm.
⚠ Common Wrong Answer: "Batch size doesn't affect BatchNorm."
Q39. In metric learning (e.g., training embeddings for Swiggy user profiles), why is "Contrastive Loss" (like InfoNCE) mathematically superior to standard
classification loss?
Answer Framework:
Standard classification forces representations into fixed, discrete class buckets via a dense final layer.
Contrastive loss directly optimizes the distance in the continuous embedding space. It pulls positive pairs (similar users) together via dot product
maximization, and pushes negative pairs apart via a denominator sum.
This forces the neural network to learn a smooth, uniform hypersphere of feature representations, allowing it to seamlessly evaluate zero-shot or
unseen users using simple Cosine Similarity.
⚠ Common Wrong Answer: Not knowing what metric learning is.
Q40. [CODE QUESTION] How do you identify if PyTorch Autograd is encountering a mathematical anomaly (like returning NaN gradients) during a massive
training loop without stepping through it manually?
Answer Framework:
Why this module exists: Knowing your ML theory is necessary but not sufficient. Swiggy interviewers will ask "so how do you think we use this here?"
Knowing the exact systems Swiggy has built — by name, by architecture, by business purpose — is what separates a prepared candidate from a brilliant one
who didn't do their homework.
┌──────────────┐
│ CUSTOMERS │ ← Search, Recommendations, Personalization
└──────┬───────┘
│
┌────────────▼────────────┐
│ SWIGGY PLATFORM │ ← Fraud Detection, Ops, Analytics
│ (The Orchestrator) │
└────────────┬────────────┘
┌──────┴──────────────────┐
│ │
┌──────▼───────┐ ┌────────▼──────┐
│ RESTAURANTS │ │ DELIVERY │
│ │ │ PARTNERS │
└──────────────┘ └───────────────┘
← Menu ML, Search ← Routing, ETA, Batching
Old Swiggy search was keyword matching. You typed "biryani," it looked for restaurants with the word "biryani" in their menu. That breaks immediately if you type
"biriyani" (common alternate spelling), or if you type "something spicy and filling for dinner" — a query with no exact keyword match.
Neural search replaces this with an LLM-powered system that understands the meaning of what you're asking, not just the words.
Swiggy fine-tuned an LLM (likely a BERT-style encoder or a smaller generative model) on food-domain data — dish names, cuisine types, dietary preferences,
ingredient terms.
User queries are embedded into a vector. Menu items are also embedded into vectors.
Semantic similarity search (cosine similarity) retrieves the most relevant results.
The system handles:
Typos: "biriyani" → "biryani" (embedding-space proximity)
Conversational queries: "healthy lunch options" → maps to dishes tagged veg, low-calorie, salads
Intent understanding: "something for a birthday party" → party platters, desserts, large portions
Why It Beats Keyword Search
Keyword search is a lookup table. Neural search is a geometry problem — find the closest meaning in embedding space. It generalizes to unseen queries
automatically.
Ashmi's Connection
Your STYBAY multimodal search system is architecturally identical to this. You used FashionCLIP to embed product images and CLIP for text-to-image matching.
Swiggy's neural search embeds dish descriptions and user queries into the same space. Same principle, different domain. You have built this.
What To Say
"Swiggy's neural search is essentially the same architecture as my STYBAY multimodal search project — a dual-encoder model that embeds queries and items into a
shared semantic space, then uses ANN search to retrieve the most relevant results. At STYBAY I implemented this with FashionCLIP; at Swiggy's scale, it would be
backed by a fine-tuned LLM encoder with a managed vector index like Pinecone or a custom FAISS cluster."
A Siamese network is a pair of identical neural networks (same weights, shared architecture) that take two inputs and learn to measure how similar they are. Think of it
as a "similarity engine" trained specifically to understand that "pulao" and "rice pilaf" are the same thing, and that "biryani" is close to "pulao" but not identical.
Both networks share identical weights — this forces them to learn a consistent notion of similarity.
Trained with contrastive loss or triplet loss: pull similar items together in embedding space, push dissimilar items apart.
At inference: given a user query, find the restaurant menu item whose embedding is closest.
Ashmi's Connection
Contrastive learning is the training paradigm behind CLIP and FashionCLIP — both of which you used at STYBAY. CLIP trains a Siamese-style image encoder and
text encoder with contrastive loss. The Siamese network Swiggy uses for dish search is a text-only version of the same idea.
When you open Swiggy, the homepage isn't random. It shows you restaurants and dishes specifically chosen for you based on two things: what people similar to you
ordered (collaborative filtering) and what matches your personal taste profile (content-based filtering).
Build a user-item interaction matrix: rows = users, columns = restaurants, values = order frequency or ratings.
Find users with similar patterns to you (user-user) or find items ordered by the same set of users (item-item).
Matrix Factorization (SVD/ALS): Decompose the interaction matrix into two lower-rank matrices — user latent factors and item latent factors. The dot product
of a user vector and an item vector predicts how much that user would like that item.
Problem: Cold start. A new user has no history. A new restaurant has no orders.
1. Stage 1 (Recall): Generate candidates from both CF and CB models — the top 500 most likely items.
2. Stage 2 (Ranking): A neural ranker (often a deep learning model) scores and re-ranks the 500 candidates considering context: time of day, weather, current
promotions, user's last 3 orders, location.
Swiggy Specifics
Swiggy One users get different recommendations than regular users (premium signal)
Instamart uses content-based filtering heavily (grocery items have no "taste preference")
Festival periods trigger context-aware recommendations (biryani on Eid, sweets on Diwali)
Ashmi's Connection
Your STYBAY project is a content-based recommender — given an image or text query, find similar products by feature similarity. The FashionCLIP embedding IS
the feature vector for content-based filtering.
Swiggy has millions of food photos uploaded by restaurants. A multimodal model can look at a photo of a dish and understand what ingredients it likely contains, what
cuisine it belongs to, and what similar dishes exist — even if the restaurant gave it an unusual or misspelled name.
Architecture
Business Value
Ashmi's Connection
Your TrOCR project is architecturally similar — Vision Transformer encoder processes the image, autoregressive Transformer decoder generates text. The difference:
Swiggy's model generates ingredient tags from food photos; your TrOCR generates text characters from handwriting images. Same encoder-decoder paradigm.
Order Placed
│
├── [LEG 1] Assignment Time: How long to find & assign a delivery partner
│
├── [LEG 2] First-Mile Travel: Time for partner to reach the restaurant
│
├── [LEG 3] Restaurant Wait: Time for food to be prepared
│
├── [LEG 4] Last-Mile Travel: Time to travel from restaurant to customer
│
└── [LEG 5] Total ETA: Integrated prediction (not just sum of above)
Shared representations: the hidden layers learn features (weather, traffic density, restaurant load) that benefit ALL five predictions simultaneously.
Uncertainty correlation: if traffic is bad, legs 2 and 4 are both affected — the model captures this correlation.
Efficiency: one forward pass, five outputs.
Input Features
Model Architecture
The restaurant wait time is the most unpredictable leg. A restaurant might be handling a sudden surge, have a staff issue, or be understaffed on a rainy Sunday. MIMO
handles this by using real-time order queue data as an input feature.
Ashmi's Connection
MIMO uses the same deep learning training mechanics Ashmi should understand from her TrOCR and IndicBERT work: shared encoder layers, multiple output heads,
weighted multi-task loss. Her fine-tuning experience is directly relevant to understanding how Swiggy would retrain MIMO on new city data.
Instead of sending one delivery partner for one order, Swiggy can send one partner for two orders from nearby restaurants to two customers who live close together.
This is order batching — and deciding which orders to batch is an incredibly complex optimization problem.
The number of possible batch combinations explodes combinatorially. With 100 active orders and 20 delivery partners, the search space is astronomically large. You
cannot evaluate every combination in real time.
Business Impact
Order batching is one of Swiggy's most important cost levers. Fewer trips per order = lower fuel cost + lower partner payout per order + lower carbon footprint.
Swiggy pre-positions delivery partners in areas where orders are about to spike — BEFORE the orders come in. To do this, they predict order volumes 15 minutes into
the future for every zone in every city.
How It Works
Input: Historical order volume time series for each geo-zone, time of day, day of week, weather, ongoing promotions, local events (cricket match, concert),
past 15-minute actuals.
Model type: Likely a combination of:
LSTM or Temporal Convolutional Networks (TCN) for capturing sequential patterns
Gradient Boosting (LightGBM) for tabular feature importance
Transformer-based time series models (like Temporal Fusion Transformer) for long-range dependencies
Output: Predicted order count per zone for the next 15 minutes.
Action: Logistics system pushes incentives or routing nudges to partners in predicted high-demand zones.
Small zones in Tier-2 cities have very few historical orders. Demand forecasting for sparse zones requires transfer learning — train a global model, fine-tune per zone.
This is the same concept as Ashmi's IndicBERT fine-tuning on a low-resource language.
15 minutes is roughly the minimum time it takes to reposition a delivery partner. Forecasting further ahead introduces too much uncertainty. Forecasting less gives
insufficient time to act.
GPS navigation for delivery partners that updates in real time based on traffic, weather, road closures, and the current positions of OTHER delivery partners (to avoid
clustering).
How It Works
Graph-based routing: The road network is a weighted graph. Edge weights = estimated travel time (dynamically updated from GPS probe data).
Dijkstra's algorithm (or A*) finds the shortest path. But at Swiggy's scale, this runs thousands of times per second across the entire city graph.
ML component: Predicting edge weights (travel time) uses a model trained on historical GPS traces, incorporating: time of day, weather, day of week, current
traffic probe data.
Constraint satisfaction: Route must satisfy pickup sequence (restaurant first, then customer), time windows, and vehicle capacity.
Ashmi's Connection
Dijkstra's algorithm is in her Module 10 DSA C++ study guide. She has implemented it. Being able to say "I've implemented Dijkstra's from scratch in C++ and I
understand how Swiggy uses it at scale for dynamic routing" is a strong signal.
A small percentage of Swiggy users claim their order never arrived (or arrived wrong) to get a refund — even when it did arrive correctly. DeFraudNet is Swiggy's
custom deep learning model that decides whether a refund request is genuine or fraudulent.
Fraudsters are a tiny minority → severe class imbalance (1 fraud per 500 genuine complaints)
Fraudsters adapt their behavior to avoid detection
You cannot deny genuine complaints — customer experience impact is massive
The model must make decisions in real time (during the refund flow)
Architecture
User behavioral features: order history, refund history, account age, device fingerprint
Real-time contextual data: weather at delivery location (rain = more late orders = more genuine complaints), delivery partner's GPS trace (did they actually
reach the location?), restaurant preparation time logs
Network/graph features: is this user connected to other known fraudsters (same device, same payment method)?
NLP component: text analysis of the complaint description
Focal Loss: down-weights easy negatives (obvious non-fraud), focuses learning on hard cases near the decision boundary
SMOTE or class weighting during training
Threshold tuning: the decision threshold is NOT 0.5. It's calibrated to balance false positives (deny genuine complaints) vs false negatives (approve fraud)
Ashmi's Connection
Her Malayalam Cyberbullying Detection project faced the exact same class imbalance problem — abusive comments are rare. She used dataset augmentation to
address it. DeFraudNet uses focal loss and threshold tuning. Both are valid strategies; Ashmi should be able to discuss both and when each is preferred.
Swiggy has petabytes of business data in SQL databases. Previously, only data analysts with SQL knowledge could query it. Hermes is a GenAI system that lets a
non-technical Swiggy operations manager type "How many orders in Bangalore were cancelled due to rain last Tuesday?" and get the answer — without writing a
single line of SQL.
Hermes v3 IS what Ashmi built in Sarathī, scaled to enterprise. Both are RAG pipelines where:
Sarathī: retrieves from IRC technical standards → Llama 3.1 → cited engineering answer
Hermes: retrieves from database schema documentation → Claude/LLM → SQL query + answer
The Planner Agent in Sarathī maps directly to Hermes's multi-step query decomposition for complex questions that require joining multiple tables.
What To Say
"Hermes v3 is architecturally very similar to the Sarathī RAG pipeline I built. Both use a retrieval step to ground the LLM in specific context — in Sarathī I retrieved IRC
technical clauses, in Hermes the retrieval is over database schema documentation. The core challenge in both is the same: preventing hallucination by ensuring the
LLM generates answers strictly grounded in retrieved context."
Swiggy handles millions of customer complaints daily: "where is my order," "I got the wrong food," "the rider was rude," "I want a refund." Handling all of this with
human agents would be impossibly expensive. Swiggy built a multi-agent AI system on Databricks that handles most complaints automatically.
When an agent needs to respond about policies (refund eligibility, cancellation rules, delivery guarantees), it retrieves from Swiggy's internal policy knowledge base
using a vector database. This grounds responses in actual policy, preventing hallucinated commitments.
Ashmi's Connection
The Planner Agent architecture in Sarathī is a simplified version of this multi-agent system. Ashmi's agent decomposed complex engineering queries into sub-retrieval
steps. Swiggy's system decomposes customer intents into specialist agent workflows. The underlying design pattern is identical: ReAct (Reason + Act) with tool use.
MCP (Model Context Protocol) is a standard developed by Anthropic that allows AI assistants like Claude or ChatGPT to directly call external tools and APIs in a
structured, safe way. Swiggy has integrated MCP, meaning a user could theoretically say to Claude: "Order me the same biryani I had last week from Swiggy" — and
Claude would directly interact with Swiggy's ordering API to place the order.
How It Works
Swiggy exposes a set of "tools" via the MCP protocol: search_restaurants, get_menu, add_to_cart, place_order, track_order
An MCP-compatible AI assistant (Claude, ChatGPT) discovers these tools
The user's natural language intent is translated by the AI into a sequence of tool calls
Each tool call is a structured API request to Swiggy's backend
Business Significance
This represents a shift from Swiggy being an app to Swiggy being a platform that AI agents can use on behalf of users. The UI is no longer the app — it's any AI
assistant the user prefers.
Swiggy partnered with Sarvam AI to allow voice-based ordering in 11 Indian languages including Hindi, Tamil, Telugu, Kannada, Malayalam, Bengali, and others. A
user can speak in their native language to order food.
The ML Pipeline
Ashmi's entire research is on low-resource Indian language NLP. Her TrOCR work on Malayalam script, her IndicBERT Malayalam cyberbullying classifier — these
are the exact same problem space. Sarvam AI's multilingual models use similar techniques: training on multilingual Indian corpora, handling code-switching (mixing
languages), dealing with dialectal variation.
She can speak to this domain with genuine expertise. This is her home territory.
What To Say
"Swiggy's Sarvam AI partnership aligns directly with my research background. My TrOCR work at NIT Calicut was specifically on Malayalam — one of the 11
languages in Swiggy's voice ordering system. The core challenge in both is the same: Indian scripts have complex morphology, multiple scripts, and far less training
data than English. The techniques I used — custom tokenization for Malayalam morphology, transfer learning from multilingual pre-trained models — are the same
approaches Sarvam AI employs at scale."
Q1. Swiggy operates a three-sided marketplace. What are the three sides and can you name one ML system serving each side?
Answer Framework:
Why This Is Asked: Tests whether you understand Swiggy as a business, not just a tech product. Interviewers filter out candidates who treat it as a generic
tech company.
Q2. What is the difference between Swiggy's old keyword-based search and their new neural search system?
Answer Framework:
Keyword search: exact string matching, fails on typos, synonyms, conversational queries
Neural search: embeds query into vector space using a fine-tuned LLM, retrieves by semantic similarity
Example: "healthy lunch" has no keyword match → neural search finds low-calorie, veg items by meaning
Key technical difference: lookup table vs. geometry in embedding space
Why This Is Asked: Tests whether you understand the shift from symbolic to neural IR (information retrieval). A DS role at Swiggy likely touches search
quality.
Q3. What does MIMO stand for in Swiggy's delivery time prediction system and why is it better than building five separate models?
Answer Framework:
Why This Is Asked: Multi-task learning is a key DS concept. Tests whether you understand shared representations.
Q4. What is the cold start problem in recommendation systems, and how does Swiggy likely handle it?
Answer Framework:
Cold start: collaborative filtering fails for new users (no history) or new restaurants (no orders)
Solutions: content-based filtering for new items (use cuisine/price/location features), ask new users for onboarding preferences, use popularity-based
fallback
Swiggy-specific: new restaurants get a "launch boost" → exposed to users with matching cuisine preferences via content-based filtering
After enough orders accumulate, collaborative filtering takes over
Why This Is Asked: Cold start is a classic DS interview topic. Every recommendation system at scale faces it.
Q5. What is DeFraudNet and what makes fraud detection particularly challenging for Swiggy?
Answer Framework:
Why This Is Asked: Fraud detection is a realistic DS task at product companies. Interviewers want to see you understand imbalance and business cost
asymmetry.
Q6. What is Hermes at Swiggy and what is the underlying ML architecture that powers it?
Answer Framework:
Hermes: GenAI text-to-SQL system allowing non-technical employees to query data in natural language
Architecture: multi-step RAG pipeline — schema retrieval → SQL generation (LLM) → execution → result narration
Key components: vector database for schema documentation, LLM (Claude or similar) for SQL generation, validation + retry loop
Connect: "this is the same architecture as my Sarathī project, which I built from scratch"
Why This Is Asked: Text-to-SQL is a hot GenAI application. Shows you know Swiggy's internal tools and can connect your resume to them.
Q7. Why did Swiggy partner with Sarvam AI and what ML challenges does multilingual voice ordering solve?
Answer Framework:
Why This Is Asked: Tests domain awareness and cultural context relevance for Indian ML applications.
Q8. What is collaborative filtering and what is content-based filtering? When would Swiggy use each?
Answer Framework:
Collaborative filtering: "users like you also ordered X" — based on interaction patterns, not item features
Content-based filtering: "you ordered spicy food before, here's more spicy food" — based on item features and user preference profile
Swiggy uses CF: for established users with order history
Swiggy uses CB: for new users, new restaurants, niche items with few orders, Instamart (grocery has no taste preference)
Hybrid: candidate generation (CF + CB) → neural ranker re-ranks with context
Why This Is Asked: Fundamental RecSys question. Every DS at a food delivery company must understand this.
Q9. What is a Siamese Neural Network and how does Swiggy use one for dish search?
Answer Framework:
Siamese network: two identical networks (shared weights) that take two inputs and output a similarity score
Training: contrastive loss — pull similar dish name pairs close, push dissimilar pairs apart
Swiggy use: handles "biriyani"/"biryani" spelling variants, suggests "pulao" when "biryani" is out of stock
Key property: the shared weights force a consistent notion of similarity
Connect: "this is the same contrastive learning paradigm as CLIP, which I used at STYBAY"
Why This Is Asked: Tests understanding of metric learning, which underlies search and recommendations.
Answer Framework:
MCP (Model Context Protocol): allows AI assistants (Claude, ChatGPT) to call Swiggy's APIs directly via structured tool definitions
User can order via Claude without opening the Swiggy app
Strategic significance: Swiggy becomes a platform/backend, not just an app — distribution through any AI interface
Technical: Swiggy exposes tools (search, cart, order, track) that MCP-compatible agents can call
Broader trend: the UI is becoming the AI assistant, not the native app
Why This Is Asked: Shows awareness of the latest industry trends and Swiggy's forward-looking strategy.
Q11. You are building Swiggy's restaurant recommendation system for a user who just signed up and placed their first order. Walk me through which model you would
use at each stage of their journey.
Answer Framework:
Day 0 (no history): content-based only — use onboarding preferences + location + time of day + restaurant popularity in their area
After 1st order: start building preference profile — cuisine type, price range, delivery time preference revealed
After 5+ orders: begin collaborative filtering — enough signal to find similar users
After 20+ orders: full hybrid — CF generates candidates, neural ranker scores them with full context
Key insight: the system should be designed so the model automatically transitions as data accumulates
Why This Is Asked: Tests whether you can think in ML system lifecycle terms, not just model selection.
Q12. Swiggy's demand forecasting model predicts order volume 15 minutes ahead per geo-zone. What would happen if a zone has very few historical orders (a new
neighbourhood in a Tier-3 city)? How would you handle it?
Answer Framework:
Problem: sparse time series → model has no reliable patterns → high variance forecasts
Solution 1: Global model with zone ID as a categorical embedding — transfers patterns from data-rich zones
Solution 2: Hierarchical forecasting — aggregate at city level (reliable), disaggregate to zone using population/area ratios
Solution 3: Bayesian approach — start with a strong prior (city-level distribution), update as data accumulates
Connect to Ashmi: transfer learning from a high-resource to a low-resource setting — same problem as Malayalam NLP
Why This Is Asked: Sparsity/cold start in time series is a real production challenge. Tests practical ML thinking.
Q13. A Swiggy data scientist notices that DeFraudNet has 99% accuracy on the test set, but the fraud team says it's not catching fraudsters. What is the most likely
explanation and how would you fix it?
Answer Framework:
Root cause: class imbalance. If 99% of cases are genuine, a model that predicts "genuine" every time gets 99% accuracy
The accuracy metric is completely useless here
Fix 1: use F1-score, Precision-Recall AUC, or recall@precision threshold instead of accuracy
Fix 2: retrain with focal loss, class weights, or SMOTE to address imbalance
Fix 3: adjust decision threshold from 0.5 to a lower value to increase recall (catch more fraudsters even at cost of some false positives)
Frame as: "the metric was wrong before the model was wrong"
Why This Is Asked: The accuracy paradox with imbalanced data is a classic trap. This tests whether you default to the right metrics.
Q14. How does Swiggy's MIMO model handle the fact that restaurant preparation time is far more unpredictable than travel time? What engineering decisions would
you make?
Answer Framework:
Restaurant wait time has higher variance than travel time — same restaurant behaves differently on Sunday evenings vs weekday afternoons
Feature engineering: add real-time queue depth (how many pending orders at this restaurant right now), historical variance not just mean, live prep time
feedback if available
Model decision: use Huber loss for this output head instead of MSE — more robust to the occasional 45-minute outlier wait
Architecture: could give the restaurant wait head more capacity (wider/deeper) since it needs to learn more complex patterns
Uncertainty quantification: output a confidence interval not just a point estimate — "27 ± 8 minutes"
Why This Is Asked: Tests whether you think about model design as a function of data characteristics, not one-size-fits-all.
Q15. Swiggy's customer support RAG agent confidently gives a customer wrong refund eligibility information, leading to a complaint escalation. How would you debug
and fix this?
Answer Framework:
Step 1: Was this a retrieval failure or a generation failure? Run the same query, check what chunks were retrieved — were the right policy sections
fetched?
Step 2 (Retrieval failure): improve chunking strategy (semantic over fixed-size), improve embedding model, add metadata filtering by policy category
Step 3 (Generation failure): the LLM hallucinated despite correct retrieval — add stricter system prompt "only answer from provided context," add
citation enforcement
Step 4: implement RAGAS evaluation — measure context precision, context recall, faithfulness scores automatically
Connect to Ashmi: "In my Sarathī project I reduced hallucinations by 90% using a Planner Agent to ensure multi-step retrieval before generation — the
same approach applies here"
Why This Is Asked: RAG failure modes are actively being tested at companies deploying GenAI. Shows production-readiness thinking.
Q16. You are asked to evaluate whether Swiggy's neural search is actually better than the old keyword search. How do you design this evaluation?
Answer Framework:
Offline evaluation: curate a test set of queries with human-labeled relevant results. Measure NDCG@10, MRR, Precision@K for both systems.
Online A/B test: serve neural search to 10% of users, keyword search to remaining. Measure: click-through rate, order conversion from search, time to
first order, search abandonment rate.
Specific metric: search abandonment rate (user searches, finds nothing, leaves) — this is where neural search should win on typo/conversational
queries
Edge case: neural search might surface unexpected results that feel wrong even if semantically similar — monitor negative feedback rates
Why This Is Asked: Evaluation design is a core DS skill. Many candidates can build models but can't evaluate them rigorously.
Q17. Swiggy is launching in a new city. The MIMO model has never seen data from this city. How do you handle ETA prediction on day one?
Answer Framework:
Option 1: Deploy the global MIMO model as-is — it has learned city-agnostic features (weather effects, time-of-day patterns). Performance will be
reasonable but suboptimal.
Option 2: Transfer learning — fine-tune the global model on the new city's first week of data. Start generalized, adapt quickly.
Option 3: Use city-type clustering — find existing cities with similar characteristics (population density, road network type, cuisine mix) and use their
model as the starting point.
Conservative approach: widen the confidence intervals in the new city, show "30-45 min" instead of "37 min" until data accumulates.
Why This Is Asked: Transfer learning and domain adaptation in production is a frequent scenario at fast-scaling companies.
Q18. How would you use the Siamese Network dish similarity scores to build a "frequently bought together" feature on Swiggy?
Answer Framework:
Siamese gives semantic similarity. But "bought together" is about complementarity, not similarity (biryani + raita, not biryani + another biryani).
Use collaborative filtering on co-purchase data to find actual complements.
Combine: use Siamese similarity to handle vocabulary (match "raita" to "dahi raita" correctly), use co-purchase CF to determine what goes together.
Final ranking: score = co-purchase frequency × margin contribution × delivery feasibility from same restaurant.
Why This Is Asked: Tests whether you can combine multiple signals correctly. A purely semantic approach would fail here.
Q19. A delivery partner using Swiggy's dynamic routing app says the suggested route keeps taking him through a flooded road even when he manually avoided it
twice. What is the ML problem here and how do you fix it?
Answer Framework:
Problem: the edge weight model hasn't incorporated the partner's feedback signal (manual deviation = implicit "this route is bad")
Fix 1: collect implicit feedback — when partners deviate from suggested route, flag those edges as potentially unreliable
Fix 2: multi-source data fusion — combine GPS probes, partner deviations, traffic API, and social media flood reports into edge weight estimation
Fix 3: human-in-the-loop: allow partners to explicitly report blocked roads, weight these reports heavily in real-time routing
ML angle: the model needs an online learning component that updates edge weights within minutes, not just nightly retraining
Why This Is Asked: Real-world ML systems must handle feedback loops and user signals. Tests systems thinking.
Q20. Swiggy's order batching RL agent was trained in Bangalore. It is now being deployed in Chennai. What concerns do you have?
Answer Framework:
Road network structure is different (Chennai has more narrow roads, different grid layout)
Cuisine mix changes (filter coffee + idli orders have different packaging/prep times than biryani)
Order density patterns are different (lunch peak is more pronounced in Chennai)
RL concern: the reward function was calibrated on Bangalore delivery times — reward shaping may be wrong for Chennai
Mitigation: fine-tune the agent on Chennai simulator data before live deployment. Start with a conservative batching policy (only batch when similarity is
very high). Gradually increase batching aggressiveness as the agent adapts.
Why This Is Asked: Distribution shift in RL is a serious production problem. Tests whether you understand the risks of deploying ML across contexts.
Q21. Design the ML system for Swiggy's "Predictive Reorder" feature — it proactively notifies a user on Friday evening that their "usual Friday biryani" is available
from their favourite restaurant. Define the problem, the data, and the model architecture.
Answer Framework:
Frame as: binary classification — "will this user order from this restaurant in the next 2 hours?" scored per (user, restaurant, time_slot) pair
Features: user's historical order day/time patterns, days since last order from this restaurant, restaurant's current availability + ETA, weather (rain →
more delivery orders), previous notification response rate
Model: LightGBM or a small neural network. Not a large model — this runs for millions of user-restaurant pairs hourly.
Personalization challenge: user's "usual" changes over time. Use recency-weighted order history.
Output: push notification trigger if score > threshold AND restaurant is actively open AND predicted delivery time < user's historical tolerance
⚠ Common Wrong Answer: "Use a recommendation system." Wrong framing — this is about timing and trigger prediction, not item selection. The
item is already known (their usual). The question is when to notify.
Why This Is Asked: Feature design from scratch is a core senior DS skill. Tests end-to-end thinking from business problem to model deployment.
Q22. Swiggy's Hermes text-to-SQL system is generating syntactically valid SQL that runs without errors but returns wrong answers (e.g., total revenue is doubled
because of an accidental JOIN fan-out). How do you detect and prevent this?
Answer Framework:
Detection: build an automated sanity check layer — compare output numbers against known business metrics (daily revenue ± 20% of last week). Flag
anything outside range.
Root cause: fan-out from unintentional Cartesian products or JOIN duplication — the LLM doesn't understand that a many-to-many JOIN multiplies
rows.
Prevention 1: few-shot examples in the prompt that explicitly show correct JOIN patterns for the schema and WRONG patterns to avoid.
Prevention 2: schema documentation in the RAG layer should include cardinality notes ("orders-to-users is many-to-one, always join on user_id")
Prevention 3: add a SQL validation agent that checks for known anti-patterns (no GROUP BY with aggregation, Cartesian joins) before executing.
⚠ Common Wrong Answer: "Improve the LLM model." The LLM is not the problem — the context (schema documentation quality and prompt design)
is.
Why This Is Asked: SQL correctness validation in text-to-SQL systems is a real production challenge at data companies.
Q23. [CODE QUESTION] Write the SQL query Swiggy's Hermes system might need to generate for: "Find the top 3 restaurants in each city by number of orders in
the last 30 days, but only include restaurants with an average rating above 4.0."
Answer Framework:
WITH recent_orders AS (
-- Step 1: Filter to last 30 days only
SELECT
o.restaurant_id,
COUNT(*) AS order_count
FROM orders o
WHERE o.order_date >= DATE_SUB(NOW(), INTERVAL 30 DAY)
AND [Link] = 'delivered'
GROUP BY o.restaurant_id
),
restaurant_stats AS (
-- Step 2: Join with restaurant info and filter by rating
SELECT
r.restaurant_id,
[Link],
[Link],
r.avg_rating,
COALESCE(ro.order_count, 0) AS order_count
FROM restaurants r
LEFT JOIN recent_orders ro ON r.restaurant_id = ro.restaurant_id
WHERE r.avg_rating > 4.0
AND r.is_active = TRUE
),
ranked AS (
-- Step 3: Rank within each city
SELECT
*,
RANK() OVER (PARTITION BY city ORDER BY order_count DESC) AS city_rank
FROM restaurant_stats
)
-- Step 4: Keep only top 3 per city
SELECT city, name, avg_rating, order_count, city_rank
FROM ranked
WHERE city_rank <= 3
ORDER BY city, city_rank;
Key decisions: use RANK() not ROW_NUMBER() so tied restaurants both appear; use LEFT JOIN + COALESCE so restaurants with zero orders still
show if rating qualifies; filter status = 'delivered' to exclude cancelled orders from count.
⚠ Common Wrong Answer: Using a subquery instead of CTE (harder to read and debug in Hermes context), or using ROW_NUMBER() which would
arbitrarily exclude one restaurant if two are tied.
Why This Is Asked: Window functions + CTEs + business logic filters are exactly what a DS at Swiggy writes daily.
Q24. Swiggy's recommendation system starts showing the same 5 restaurants to a user repeatedly even though they've ordered from all 5 recently. Diagnose the
problem and propose a fix.
Answer Framework:
Root cause: the model is likely optimizing for short-term CTR (click-through rate) rather than long-term user satisfaction. High past engagement → high
predicted engagement → same items keep winning.
This is an "exploration-exploitation" problem — the model exploits known preferences, never explores new restaurants.
Fix 1: add a "diversity penalty" — the ranking score is penalized if the same restaurant appeared in the last N recommendations.
Fix 2: add recency decay — restaurants ordered recently get a score discount to force variety.
Fix 3: epsilon-greedy exploration — 10% of recommendation slots are filled with exploration candidates (new restaurants in area with good ratings).
Fix 4: reframe the reward — train on long-term engagement (30-day retention) not next-click prediction.
⚠ Common Wrong Answer: "Retrain the model with more data." More data won't fix a feedback loop — it will make the model more confident in the
same wrong recommendations.
Why This Is Asked: Feedback loops and exploration-exploitation are critical RecSys production problems. This tests beyond textbook ML.
Q25. You are designing the feature engineering pipeline for DeFraudNet. What are the 10 most important features you would engineer and why?
Answer Framework:
User-level behavioral: (1) lifetime refund rate, (2) refund rate in last 30 days (recent drift detector), (3) account age in days, (4) total lifetime order value
Order-level: (5) time between order delivery and complaint submission (fraudsters often complain instantly), (6) order value (high-value orders have
higher fraud incentive), (7) payment method (COD vs card vs wallet — different risk profiles)
Contextual: (8) weather at delivery time (rain = more genuine complaints), (9) delivery partner GPS trace — did the partner reach the delivery location?,
(10) restaurant historical complaint rate for this dish
Graph feature (advanced): (11) network similarity to known fraudulent accounts (same device ID, same payment method used by flagged accounts)
⚠ Common Wrong Answer: Only using user-level features and ignoring the GPS/contextual features. The most powerful signals are the cross-
referencing of the complaint against real-time evidence.
Why This Is Asked: Feature engineering is the most important skill in applied DS. Tests domain creativity and understanding of fraud dynamics.
Q26. Swiggy wants to add a "Mood-Based Ordering" feature — the user selects their mood (celebrating, comfort food, healthy, adventurous) and gets personalised
recommendations. How would you build the ML system for this?
Answer Framework:
Step 1: Tag the item catalog — use the multimodal dish understanding model to tag each dish with mood-relevant attributes (e.g., "chocolate cake" →
celebratory, comfort; "quinoa salad" → healthy).
Step 2: Build mood-aware user profiles — from past orders, infer which mood-tagged items each user gravitates toward when in that mood (if they
ordered biryani on Fridays and cake on weekends, that's their "comfort" profile).
Step 3: Mood-conditional ranking — when user selects "Celebrating," re-weight the standard recommendation score by the item's "celebratory" attribute
score × user's historical affinity for celebratory items.
Step 4: Cold start for mood: a new user in "Adventurous" mode gets cuisine types they've never ordered before, highly rated, novel dishes.
Evaluation: A/B test on order completion rate and satisfaction survey score for mood-triggered sessions vs standard recommendations.
Why This Is Asked: Feature design combining multiple ML components into a coherent user-facing product is a DS leadership skill.
Q27. [CODE QUESTION] Swiggy's data team asks you to write a Python function that takes a list of orders (as dicts) and computes the "order velocity" for each user
— defined as the number of orders placed in the last 7 days. This is a feature for DeFraudNet.
Answer Framework:
def compute_order_velocity(
orders: List[Dict],
reference_date: datetime = None
) -> Dict[int, int]:
"""
Computes 7-day order velocity for each user.
Args:
orders: List of dicts with keys: user_id (int), order_date (datetime), status (str)
reference_date: The date to compute "last 7 days" from. Defaults to now.
Returns:
Dict mapping user_id -> number of delivered orders in last 7 days
"""
if reference_date is None:
reference_date = [Link]()
return dict(velocity)
# Example usage:
orders = [
{"user_id": 1, "order_date": datetime(2026, 4, 20), "status": "delivered"},
{"user_id": 1, "order_date": datetime(2026, 4, 22), "status": "delivered"},
{"user_id": 1, "order_date": datetime(2026, 4, 10), "status": "delivered"}, # > 7 days ago
{"user_id": 2, "order_date": datetime(2026, 4, 24), "status": "cancelled"}, # not delivered
{"user_id": 2, "order_date": datetime(2026, 4, 23), "status": "delivered"},
]
Key decisions: filter by status == "delivered" not just any order; defaultdict(int) for clean counting; reference_date parameter makes
the function testable (don't hardcode [Link]()).
⚠ Common Wrong Answer: Using [Link]() directly inside the function makes it untestable in unit tests. Always parameterize time.
Why This Is Asked: Practical feature engineering in Python is tested in DS rounds. Tests clean code habits.
Q28. Swiggy's demand forecasting model was highly accurate for Bangalore but is performing poorly in Mumbai. You check and find the model's RMSE in Mumbai is
3x higher. What are the top 5 diagnostic checks you run?
Answer Framework:
Check 1: Data distribution shift — plot the feature distributions for Bangalore vs Mumbai. Are peak hours different? Is the order volume scale different?
Are weather patterns used as features calibrated for Bangalore rain but not Mumbai monsoons?
Check 2: Zone granularity — Mumbai zones might be defined differently (larger or smaller areas). The model's spatial aggregation may be mismatched.
Check 3: Missing features — does Mumbai have a local event calendar (cricket at Wankhede) that isn't in the training data? Local events spike demand
unpredictably.
Check 4: Training data recency — is the model trained only on Bangalore historical data? It has seen zero Mumbai patterns.
Check 5: Evaluation consistency — is RMSE computed on the same time horizon? A 15-minute RMSE vs 30-minute RMSE gives very different
numbers.
Fix path: collect Mumbai data, fine-tune the global model on Mumbai. Add city-specific features.
⚠ Common Wrong Answer: "The model is overfitting." Overfitting shows as good train/bad val on the SAME data distribution, not cross-city
degradation. This is distribution shift, not overfitting.
Why This Is Asked: Diagnosing production model degradation is a core DS skill. Tests systematic thinking.
Q29. You are told Swiggy's RAG customer support agent gives different answers to the same question on different days. What causes this and how do you fix it?
Answer Framework:
Root cause 1: LLM temperature > 0. The generation step is stochastic — even with the same retrieved context, the LLM samples different tokens. Fix:
set temperature=0 for factual support responses.
Root cause 2: ANN retrieval is approximate — on different days, slightly different chunks may be retrieved due to index updates or proximity ties. Fix:
switch to exact KNN for the small, stable policy knowledge base. Or fix the retrieved chunks by using metadata filtering to always retrieve the canonical
policy document first.
Root cause 3: The policy knowledge base itself was updated and old chunks are still indexed. Fix: implement a document versioning system — when a
policy is updated, delete and re-embed the old chunks.
Root cause 4: No guardrails — the LLM is free to use its parametric memory when context is insufficient. Fix: add strict system prompt "if the answer is
not in the provided context, say 'I don't have that information.'"
⚠ Common Wrong Answer: "Use a better LLM." The problem is determinism and retrieval consistency, not model capability.
Why This Is Asked: RAG production reliability is a hot topic. Tests deep understanding of where non-determinism enters the system.
Q30. Swiggy's order batching RL agent is batching two orders from restaurants 3km apart, causing one customer to wait 25 extra minutes. The agent learned this from
training data where batching always maximised total throughput. What is the fundamental ML problem and how do you redesign the reward function?
Answer Framework:
Problem: the reward function maximised a global metric (total deliveries per hour) without enforcing individual-level constraints. The agent learned to
sacrifice one customer for system-wide efficiency.
This is a constrained optimization problem incorrectly formulated as unconstrained RL.
Redesign: add a hard constraint — any batching decision that increases either customer's delivery time by more than X minutes (e.g., 8 minutes) is
inadmissible regardless of system-level benefit.
Implementation: either a penalty term in the reward (-1000 for violating time constraint) or a constrained RL formulation (Lagrangian relaxation).
Also add: customer satisfaction proxy — delivery time deviation from promised ETA, not just raw time. Promising 30 min and delivering in 38 min is
worse than promising 40 and delivering in 38.
⚠ Common Wrong Answer: "Collect more training data." The reward function is wrong — no amount of data fixes an incorrect optimization objective.
Why This Is Asked: RL reward design is notoriously tricky. Tests whether you understand that the objective function IS the algorithm.
Answer Framework:
Scale: Swiggy has ~500,000 restaurants × average 30 dishes = ~15 million item vectors. At 1024 dimensions each, that's 15M × 1024 × 4 bytes =
~60GB just for the vectors.
Exact KNN cost: for each user query, compute cosine similarity with all 15M vectors = 15M dot products. At 1 billion FLOPs/sec per CPU core, that's
~30 seconds per query. Completely infeasible for real-time search.
HNSW (Hierarchical Navigable Small World): builds a multi-layer graph where:
Bottom layer: all vectors connected to their nearest neighbors
Higher layers: progressively fewer "express" connections (like a highway system)
Query: enter at the top layer, greedily traverse to the closest node, drop to the next layer, repeat
Time complexity: O(log N) instead of O(N) for exact search
The tradeoff: HNSW may not return the true nearest neighbor — it returns a very close approximate. Recall@K is typically 95-99% — acceptable for
search.
⚠ Common Wrong Answer: "ANN is approximate because it uses random sampling." HNSW is not random — it uses a deterministic graph traversal.
The approximation comes from greedy search that may miss the global optimum.
Why This Is Asked: ANN is the backbone of every vector search system. A DS building search/RecSys must understand why exact search fails and what
tradeoffs ANN introduces.
Q32. Swiggy's MIMO model is exhibiting "label leakage" — the model achieves unrealistically good RMSE during offline evaluation but performs much worse in
production. Walk through every possible source of leakage in the MIMO ETA pipeline and how you would detect each.
Answer Framework:
Leakage source 1: Temporal leakage — the train/test split was done randomly instead of by time. Future orders were used to predict past orders. Fix:
always split time series data chronologically — train on months 1-10, test on months 11-12.
Leakage source 2: Feature leakage — using features computed at order completion time (e.g., "actual delivery time" of past orders) as a feature for the
current prediction. Fix: strict feature timestamp audit — every feature must be available at the moment the prediction is made.
Leakage source 3: Restaurant historical preparation time computed on the full dataset including the test period. Fix: compute rolling statistics using
only data prior to the prediction timestamp.
Leakage source 4: Scale leakage — normalization parameters (mean, std) computed on the entire dataset including test. Fix: fit the scaler ONLY on
training data, apply to test.
Detection: if offline RMSE is 2x better than production — this is the primary signal. Deploy model on a shadow system logging both offline prediction
and production truth for same orders.
⚠ Common Wrong Answer: "The model is overfitting." Overfitting causes bad performance on TEST data. If test performance looks great but
production is bad, it's almost always leakage or distribution shift, not overfitting.
Why This Is Asked: Data leakage is the most common silent failure in production ML. Tests rigorous experimental thinking.
Q33. Swiggy is considering replacing their LightGBM demand forecasting model with a Temporal Fusion Transformer (TFT). Walk through the specific architectural
advantages TFT has over gradient boosting for multi-horizon time series forecasting, and describe one scenario where LightGBM would still be the correct choice.
Answer Framework:
TFT advantages:
Multi-horizon native: TFT produces predictions for all future timesteps simultaneously with a single forward pass. LightGBM requires a
separate model per horizon (or iterative prediction which compounds error).
Attention-based temporal dependencies: TFT's temporal self-attention can learn that "Saturday at 7pm 4 weeks ago" is more relevant than
"yesterday at 2pm" for this zone. LightGBM cannot express this — it needs you to manually engineer "same_weekday_4_weeks_ago" features.
Gating mechanism: TFT uses gated residual networks to adaptively suppress irrelevant features. LightGBM uses feature importance but
cannot suppress features differently per sample.
Uncertainty quantification: TFT natively produces quantile forecasts (P10, P50, P90). LightGBM requires separate quantile regression
models.
When LightGBM wins:
Very small training datasets (< 10,000 samples per zone). TFT needs large data to train effectively. For sparse zones in new cities, LightGBM
with manual temporal features will outperform.
Strict latency requirements (< 5ms inference). TFT forward pass is significantly slower.
⚠ Common Wrong Answer: "TFT is always better because it's a Transformer." Model selection depends on data size, feature engineering budget,
latency constraints, and interpretability requirements.
Why This Is Asked: Model selection for time series is a nuanced real-world decision. Tests depth of DL vs classical ML trade-off understanding.
Q34. Swiggy's multimodal search system (FashionCLIP analog) is working well for popular dishes but performing poorly for rare regional dishes (e.g., "Kozhikodan
biryani" or "Chettinad kuzhambu"). Explain the mathematical reason this happens and propose two solutions.
Answer Framework:
Mathematical root cause: CLIP-style models are trained with contrastive loss on paired (image, text) data. The embedding space is learned from co-
occurrence statistics. Rare dishes appear few times in training data → their embedding vectors have high variance → the model hasn't converged to a
stable, meaningful representation for them.
In information-geometric terms: the rare dish embeddings are in low-density regions of the embedding manifold where the loss gradient provided
minimal training signal.
Solution 1: Domain-specific fine-tuning. Collect a dataset of regional Indian dish images with canonical text descriptions. Fine-tune the CLIP model on
this data. Even 1,000 regional dish examples can significantly improve embeddings for rare dishes.
Solution 2: Retrieval augmentation for embeddings. At query time, if a dish name isn't found with high confidence in the vector index, fall back to a
text expansion step — use an LLM to expand "Kozhikodan biryani" into "Malabar biryani, rice dish with Malabar spices, coconut, chicken, Kozhikode
style" — then embed the expansion. The expanded query lands in a denser, more stable region.
⚠ Common Wrong Answer: "Add more training data in general." Generic data doesn't help rare regional dishes. Domain-specific, curated data for the
long tail is what's needed.
Why This Is Asked: Long-tail performance in embedding models is a critical production problem for India-specific applications. Tests understanding of
embedding learning dynamics.
Q35. DeFraudNet uses a deep learning model. A Swiggy ML engineer suggests switching to an XGBoost model instead because "it's more interpretable and the fraud
team can understand the decisions." Evaluate this argument rigorously and give your recommendation.
Answer Framework:
Where the argument is correct: XGBoost does provide feature importance and SHAP values, making each decision interpretable. For the fraud team to
build cases against fraudulent accounts, they need to explain WHY a request was flagged. "Your refund rate in the last 7 days is 3x the city average
AND your complaint was filed within 30 seconds of delivery" is a defensible explanation.
Where the argument is wrong: interpretability is not binary. Deep learning models can also be made interpretable using SHAP, LIME, attention weights,
or integrated gradients. DeFraudNet likely uses tabular features + network features, where XGBoost is actually competitive in accuracy.
The real question: what is the accuracy gap? If DeFraudNet catches 92% of fraudsters and XGBoost catches 85%, that 7% difference represents real
money. Calculate the financial impact before making the switch.
Recommendation: the right approach is to add a SHAP explainability layer on top of DeFraudNet — not to replace it. This gives interpretability without
sacrificing accuracy. Alternatively, use XGBoost as a "shallow" first-stage filter (fast, interpretable) and DeFraudNet as a second-stage for borderline
cases.
⚠ Common Wrong Answer: Either "deep learning is always better" or "interpretability always wins." The answer requires quantifying the tradeoff in
business terms.
Why This Is Asked: Model selection arguments in industry are rarely purely technical. Tests business-aware ML judgment.
Q36. Swiggy's Hermes text-to-SQL system is generating SQL queries that time out on the production database when the analyst asks about "all orders in the last year
by restaurant." The SQL is correct but slow. How do you fix this without modifying the database schema?
Answer Framework:
First diagnosis: run EXPLAIN ANALYZE on the generated query. Is the database doing a full table scan? Is an index being used?
Fix 1: Improve the generated SQL. Instruct the LLM via few-shot examples and system prompt to:
Always filter by status = 'delivered' first (dramatically reduces rows)
Use DATE_TRUNC for date grouping instead of computed date functions that prevent index use
Add LIMIT 1000 by default for exploratory queries
Avoid SELECT * — specify only needed columns
Fix 2: Pre-aggregate. Create materialized views or summary tables (daily_restaurant_orders, monthly_revenue) and instruct the LLM to prefer these
over the raw orders table.
Fix 3: Query guardrails. Before executing, scan the generated SQL for patterns known to cause full scans (no WHERE clause on large tables, ORDER
BY without LIMIT on millions of rows). Auto-inject LIMIT or warn the user.
⚠ Common Wrong Answer: "Add more database indexes." Schema changes require DBA approval and production changes. The question explicitly
says without schema modification.
Why This Is Asked: SQL performance is a real DS responsibility. Tests practical database knowledge beyond just writing correct queries.
Q37. Ashmi, your Sarathī RAG project reduced hallucinations by 90%. An interviewer asks: "How exactly did you measure hallucination rate? This seems like a
subjective metric." How do you answer this rigorously?
Answer Framework:
Acknowledge the interviewer is right to probe this — hallucination is genuinely hard to measure.
Method 1 (most defensible): Factual consistency scoring. Manually create a test set of 100 questions with ground-truth answers from IRC standards.
Run both baseline Llama and RAG-Llama. Human annotators rate each answer: (a) factually correct, (b) partially correct, (c) hallucinated. Hallucination
rate = fraction in category (c).
Method 2: Automated faithfulness scoring using RAGAS. RAGAS computes "faithfulness" — the fraction of the generated answer's claims that are
supported by the retrieved context. Score of 0.9+ = low hallucination.
Method 3: Citation verification. Since Sarathī produces citation-grounded answers, check each cited clause: does the answer's claim match what the
cited clause actually says?
The 90% reduction: baseline Llama (no RAG) hallucinated on ~40% of technical questions (verified by human eval on the test set). RAG-Llama
hallucinated on ~4%. That's the 90% reduction.
⚠ Common Wrong Answer: "I just tested it and it seemed much better." This is not a measurement — it's an observation. Always have a test set,
always have a metric.
Why This Is Asked: This is a trap to see if impressive-sounding metrics on the resume are backed by rigorous methodology. The inability to explain
measurement is a serious red flag.
Q38. Swiggy processes 10 million orders per day. The recommendation model currently takes 50ms to score each (user, restaurant) pair. There are 200 restaurants in
a typical user's city. At peak (1 million concurrent users), is this system feasible? If not, redesign the architecture.
Answer Framework:
Math: 1M users × 200 restaurants × 50ms = 10 billion milliseconds of compute per second = 10 million seconds of compute = requires 10,000 CPU
cores running continuously at peak. NOT feasible as stated.
Redesign: Two-stage retrieval + ranking architecture.
Stage 1 (Recall, fast): a lightweight model (matrix factorization lookup) retrieves top 50 candidates from 200 in < 1ms using precomputed user
and item embeddings (just a dot product).
Stage 2 (Ranking, slower): the expensive 50ms neural ranker runs on only 50 candidates instead of 200. Total: 1ms + 2.5ms = 3.5ms.
Precomputation: recompute user embeddings every 15 minutes (not real-time). Cache them. Restaurant embeddings recomputed nightly.
Batching: rank all 50 candidates in a single batched forward pass through the neural ranker — GPUs are efficient at batch scoring.
Result: system now handles peak with ~10x fewer resources.
⚠ Common Wrong Answer: "Use a faster model." Switching models doesn't solve the O(users × items) scaling problem. The architecture (two-stage)
is the fix, not the model.
Why This Is Asked: ML system design for scale is tested in senior DS and ML engineering rounds. Tests ability to reason about computational complexity.
Q39. Swiggy is expanding to Southeast Asia. The Sarvam AI multilingual models are trained on Indian languages. The new market includes Thai, Indonesian, and
Vietnamese. Walk through the transfer learning strategy you would recommend and identify the specific challenges unique to these languages.
Answer Framework:
What transfers: the ASR acoustic modeling for similar phoneme sets (Vietnamese shares some phoneme overlap with Hindi). The intent classification
architecture transfers — the model structure is language-agnostic. Food domain NLU patterns transfer (ordering verbs, quantity words, dish names
work similarly cross-culturally).
What does NOT transfer: Thai uses a unique script with no word boundaries (no spaces between words). This breaks all standard tokenizers — need a
Thai-specific word segmentation model as a preprocessing step. Vietnamese uses tone markers that change word meaning — standard embedding
models ignore these. Indonesian uses a Latin script but with very different morphology.
Strategy:
1. For Indonesian (Latin script): easiest. Fine-tune on food-domain Indonesian data using mBERT or XLM-R as the backbone. These multilingual
models include Indonesian.
2. For Vietnamese: use PhoBERT (Vietnamese BERT) as the NLU backbone. It's pre-trained and handles tones.
3. For Thai: use WangchanBERTa (Thai BERT). Special challenge: word segmentation must be solved first.
Data strategy: collect food-ordering dialogues in each language. Use back-translation from English food-ordering datasets as a starting point.
⚠ Common Wrong Answer: "Just fine-tune Sarvam AI's model on new language data." Sarvam AI's model is not publicly available for fine-tuning.
More fundamentally, some languages need script-specific preprocessing that fine-tuning alone cannot fix.
Why This Is Asked: International ML expansion is a real challenge at scale-up companies. Tests whether you understand that language ≠ just data — it's
script, morphology, and linguistic structure.
Q40. If you joined Swiggy's DS team tomorrow, which of your projects would you pitch as most directly applicable to an open problem Swiggy has, and how would you
scope the first 90-day roadmap?
Answer Framework:
Best pitch: Sarathī → Hermes v3 improvement. "I've built exactly this architecture from scratch. I understand the failure modes: retrieval precision,
semantic chunking, Planner Agent design. I can contribute immediately to improving Hermes's schema retrieval recall and reducing SQL generation
errors."
90-day roadmap:
Days 1-30: Deep dive into Hermes v3's current architecture. Identify the top 3 failure categories from production logs (wrong schema retrieved,
SQL with fan-out error, ambiguous user intent). Establish baseline RAGAS metrics.
Days 31-60: Implement one targeted fix per failure category. Evaluate using the RAGAS suite + shadow mode deployment. Target: reduce
hallucination rate by 30%.
Days 61-90: Design and run A/B test of improved Hermes on 10% of internal users. Measure: query success rate, SQL execution error rate,
user satisfaction. Write tech report for the team.
Alternative pitch: STYBAY → neural search improvement. "I've implemented multimodal search with ANN. Swiggy's neural search for regional dish
names in Indian languages is a known hard problem. My background in low-resource Indian language NLP (IndicBERT, TrOCR) is directly relevant."
⚠ Common Wrong Answer: Pitching a greenfield project or something Swiggy already does well. The strongest pitch identifies a real gap, connects it
to your resume, and shows concrete 90-day deliverables — not vague "I'd like to improve recommendations."
Why This Is Asked: This question tests self-awareness, company research, and ambition calibrated to a junior hire. The best answer is specific, humble about
what you don't know, and confident about what you do.
Document complete. If your interview is in under 7 days: start with the Question Bank (Tier 1 + Tier 2), then re-read Domain 1 (Consumer) and Domain 3 (Operations)
— these are most likely to come up in a DS screening. Read the full document if time permits.