Made by systemdesign.academy, the site with 984 interactive system design and AI engineering lessons.
See all 120 questions in this pack22 sections, in the order the PDF prints them. The answers are in the PDF; 5 are free below.
Linear algebra: vectors and similarity (9)
1.What is a vector in machine learning, and how is it more than just a list of numbers? junior
2.What are the L1 and L2 norms of a vector? Compute both for (3, 4) and say where each is used in ML. junior
3.What does the dot product of two vectors tell you geometrically? junior
4.Compute the cosine similarity of a = (3, 4) and b = (4, 3) by hand. What does the result mean? juniorfree below
5.For embedding search, should you use cosine similarity, dot product or Euclidean distance? When do they give the same ranking? mid
6.How do you project one vector onto another? Work an example and say where projection is used in ML. mid
7.What does it mean for two vectors to be orthogonal, and what does a cosine of 0 tell you about two embeddings? junior
8.People say king - man + woman = queen in word embeddings. Is that true? Explain what is really going on. senior
9.Why are random vectors in high dimensions almost orthogonal, and what does that mean for nearest-neighbor search? senior
Linear algebra: matrices as transformations (10)
10.Multiply W = [[1, 2, 0], [-1, 0, 3]] by x = (2, 1, 4) by hand. junior
11.What does it mean that a matrix is a transformation? Show what A = [[2, 1], [0, 1]] does to the plane. mid
12.A batch of 32 MNIST images goes into a dense layer with 128 units. What are the shapes, and what is the rule for when two matrices can be multiplied? midfree below
13.Why is matrix multiplication not commutative? Give an example where AB ≠ BA. mid
14.What is the transpose of a matrix, and where do transposes appear in ML code? mid
15.What are the identity matrix and the inverse of a matrix? Why do we almost never compute an inverse in ML code? senior
16.What does the determinant of a matrix mean geometrically? mid
17.What is the rank of a matrix, and how does linear dependence among features cause problems in a model? senior
18.Walk me through a linear layer y = Wx + b: the shapes, a numeric example and the parameter count. mid
19.How many floating-point operations does a matrix multiplication take? Work out the count for a real layer. senior
Linear algebra: eigenvalues, PSD matrices, PCA and SVD (6)
20.What is a positive semi-definite matrix, and why are a covariance matrix and XᵀX always positive semi-definite? mid
21.What are eigenvectors and eigenvalues? Compute them by hand for A = [[2, 1], [1, 2]]. senior
22.Walk me through PCA step by step on a tiny dataset. senior
23.What is the explained variance ratio in PCA, and how do you choose the number of components? mid
24.What is the singular value decomposition (SVD), and how is it different from an eigendecomposition? senior
25.What is a low-rank approximation, and how does LoRA use the low-rank idea to fine-tune large models cheaply? staff
Calculus: derivatives (4)
26.What is a derivative, in plain words, and why does a machine learning engineer care about it? junior
27.What is the difference between a numerical derivative and an analytic derivative? Which one do deep learning frameworks use? junior
28.What is the derivative of ReLU, and what is a dead ReLU? junior
29.Derive the derivative of the sigmoid function. What is its maximum value, and why does that matter for deep networks? mid
Calculus: chain rule and gradients (7)
30.Explain the chain rule and work through one example by hand. junior
31.What are partial derivatives and the gradient? Compute the gradient of f(x, y) = x² + 3y² at (2, 1) and explain why it points in the direction of steepest ascent. mid
32.What is a Jacobian, and how does it show up in backpropagation? senior
33.Derive the gradient of the mean squared error for linear regression and compute it on a small dataset. mid
34.Show that the gradient of cross-entropy loss with respect to the logits, after a softmax, is p - y. Use numbers. senior
35.What causes vanishing and exploding gradients? Show it with numbers and list the fixes. senior
36.What does the Hessian tell you about a loss surface, and how does curvature limit the learning rate? staff
Calculus: backpropagation by hand (7)
37.What is a computational graph? Run a forward and backward pass on f = (x + y)·z with x = 1, y = 3, z = -2. mid
38.Why is reverse-mode automatic differentiation (backpropagation) so efficient for training neural networks? When would forward mode be better? staff
39.Run the forward pass of a tiny 2-input, 2-hidden, 1-output network by hand and compute the loss. mid
40.Now run the backward pass on the same 2-2-1 network and give the gradient for every weight. senior
41.How do you do gradient checking? What step size do you use, and how do you judge the result? senior
42.Using the gradients from the 2-2-1 network, do one SGD update and show that the loss goes down. mid
43.Write PyTorch code that reproduces the hand-computed gradients of the 2-2-1 network using autograd. mid
Calculus: initialization and normalization (3)
44.Explain Xavier (Glorot) and He initialization. Where do the variance formulas come from? senior
45.Why can't we initialize all the weights of a neural network to zero? junior
46.Compute LayerNorm by hand for x = (1, 2, 4, 9), and explain why Transformers use LayerNorm or RMSNorm instead of BatchNorm. mid
Calculus: training deep networks (3)
47.What does dropout do at training time and at test time, and why do we scale the kept activations by 1/(1 - p)? junior
48.What is gradient accumulation, when do you use it, and what can go wrong? staff
49.Why do residual (skip) connections make very deep networks trainable? Explain with the gradient. senior
Optimization: loss functions (4)
50.What is the difference between MSE and MAE? Which one is more sensitive to outliers, and why? junior
51.Why does minimizing mean squared error correspond to maximum likelihood under Gaussian noise? State the assumptions. senior
52.What is the Huber loss, and why would you use it instead of MSE or MAE? mid
53.How do you choose a loss function for a new ML problem? Walk through your reasoning. staff
Optimization: gradient descent and learning rate (5)
54.Do one step of gradient descent by hand on f(w₁, w₂) = w₁² + 2w₂², starting at (2, 2) with learning rate 0.1. junior
55.What happens when the learning rate is too large or too small? Show it on f(x) = x². mid
56.What is the difference between convex and non-convex loss functions? What are local minima and saddle points, and which ones matter for deep networks? senior
58.Explain learning-rate warmup and cosine decay. Compute the learning rate at a few steps of a real schedule. senior
Optimization: optimizers, regularization and clipping (5)
59.How does momentum work? Work through two steps and compare with plain gradient descent. mid
60.Write the Adam update and work through the first step, including bias correction. Why is the first step about the size of the learning rate? senior
61.What is the difference between L1 and L2 regularization? Why does L1 give sparse weights? mid
62.What is the difference between L2 regularization inside Adam and decoupled weight decay (AdamW)? Why does it matter? staff
63.How does gradient clipping by norm work? Compare it with clipping by value and say how you would use it in a large training run. staff
Probability: rules (7)
64.What are a sample space and an event? Roll two fair dice: what is the probability that the sum is 7? junior
65.Of 1,000 support tickets, 300 mention "refund", 200 mention "late delivery" and 80 mention both. What is the probability that a random ticket mentions refund or late delivery? junior
66.You have 1,000 labeled emails: 120 are spam and contain "free", 80 are spam without "free", 40 are not spam but contain "free", and 760 are neither. What are the joint and marginal probabilities, and are "spam" and "contains free" independent? junior
67.You run 100 servers and each one fails on a given day with probability 1%, independently. What is the probability that at least one fails today? senior
68.What is the difference between independent and mutually exclusive events? Can two events be both? mid
69.In 1,000 emails, 160 contain "free" and 120 of those are spam; 200 emails are spam in total. What is P(spam | contains "free")? Is it the same as P(contains "free" | spam)? junior
70.A rack has 10 GPUs and 3 are faulty. You pick 2 at random without replacement. What is the probability that both are faulty? mid
Probability: Bayes' theorem (8)
71.A disease affects 1% of people. A test catches 90% of sick people (sensitivity) and wrongly flags 9% of healthy people (false positive rate). You test positive. What is the chance you are sick? midfree below
72.Write Bayes' theorem and explain the prior, likelihood, evidence and posterior with a small example. mid
73.Same test (1% prevalence, 90% sensitivity, 9% false positive rate). You test positive, take the test again, and test positive a second time. What is the chance you are sick now? senior
74.30% of your email is spam. The word "winner" appears in 20% of spam and 1% of normal email. An email contains "winner". What is the probability that it is spam? mid
75.Extend the spam filter to two words with naive Bayes. What does the "naive" assumption say, and how do you classify an email that contains both "free" and "meeting"? senior
76.The naive independence assumption is almost always false for text. Why does naive Bayes still classify well, and when should you not trust it? staff
77.Fraud is 0.1% of transactions. Your model catches 95% of fraud and flags 1% of legitimate transactions. What fraction of flagged transactions are really fraud? senior
78.What is the base-rate fallacy, and how does it show up when you deploy a classifier to a new population? senior
Probability: distributions (8)
79.What is a random variable? What is the difference between a discrete and a continuous one, with ML examples? junior
80.What is the difference between a PMF, a PDF and a CDF? Can a probability density be greater than 1? mid
81.Each LLM call fails independently with probability 0.2. In 10 calls, what is the probability of exactly 2 failures? Explain Bernoulli and binomial along the way. mid
82.What is the normal distribution and the 68-95-99.7 rule? Use it on a real example. junior
83.What is a z-score? Asha scores 82 in a test with mean 70 and standard deviation 8, and 90 in another test with mean 80 and standard deviation 10. Which result is better? mid
84.An API gets on average 4 requests per second. Assuming Poisson arrivals, what is the probability of more than 6 requests in a given second? senior
85.You are modeling four quantities: requests per minute, whether a user clicks, clicks out of 1,000 views, and the time a job takes. Which distribution would you pick for each, and how would you check the choice? staff
86.Where does the uniform distribution show up in ML, and how do you turn a uniform random number into a sample from another distribution, for example the next token? senior
Probability: expectation and variance (4)
87.An LLM endpoint returns short answers (500 tokens) 70% of the time, medium (2,000 tokens) 25% of the time and long (8,000 tokens) 5% of the time. What is the expected number of output tokens per call, and what does it mean for cost? mid
88.A job retries 0 times with probability 0.6, once with probability 0.3 and twice with probability 0.1. Compute the mean, variance and standard deviation of the number of retries. mid
89.What is linearity of expectation, and why does it not need independence? Use it to find the expected number of people who get their own hat back when n hats are handed out at random. senior
90.A request calls service A, then service B. A's latency has standard deviation 30 ms and B's has 40 ms. What is the standard deviation of the total latency, and how does covariance change the answer? staff
Statistics: describing data (3)
91.Your delivery-time column has a few stuck orders that took hours. Would you report the mean, the median or the mode, and how would you fill missing values in that column? junior
92.Why do we divide by n - 1 instead of n when we compute a sample variance? mid
93.How does the IQR rule find outliers? Work it through on real numbers. junior
Statistics: inference (4)
94.What is the difference between covariance and correlation? And why does correlation not prove causation? mid
95.What does the central limit theorem say, and why does it matter so much in ML and A/B testing? senior
96.What is a standard error, and how do you build a 95% confidence interval? Work an example. mid
97.What does a p-value actually mean, and what does it not mean? senior
Statistics: estimation with MLE, MAP and Bayes (4)
98.Explain maximum likelihood estimation using a coin. What is the MLE of P(heads) after 7 heads in 10 flips? mid
99.Show that L2 regularization is MAP estimation with a Gaussian prior on the weights. Work a small example. mid
100.How would you estimate a coin's bias, or a click-through rate, in a Bayesian way? Show the update with a Beta prior after 7 heads in 10 flips. staff
101.What does it mean for an estimator to be biased? Is an unbiased estimator always better? senior
Statistics: evaluating models (4)
102.Explain the bias-variance trade-off with numbers. senior
103.Your team tried 50 model configurations and reported the best test-set accuracy, 82.3%. What is wrong with that number, and how should train, validation and test splits be used? staff
104.Given a confusion matrix, compute precision, recall and F1. When do you care about each? junior
105.What does a ROC curve show, and what does an AUC of 0.81 actually mean? senior
Information theory: entropy (2)
106.In information theory, what is the 'information' or 'surprise' of an event, and why is it -log p? junior
107.What is the entropy of a coin, and of a distribution over K classes? What is the maximum? mid
Information theory: cross-entropy and KL divergence (8)
108.Compute the cross-entropy loss for a 3-class prediction, both with a one-hot label and with a soft label. mid
109.Your softmax returns NaN on the logits (1000, 1001, 1002). Why, and how do you fix it? mid
110.What is KL divergence? Compute it in both directions and explain why it is not symmetric. senior
111.What is perplexity in a language model? Compute it from a few token probabilities. senior
112.Why is minimizing cross-entropy the same as maximum likelihood estimation? Show it on a small example. staff
113.Show that cross-entropy equals entropy plus KL divergence. Why does that matter when you train a model? senior
114.Why do we not use mean squared error for classification with a sigmoid output? Compare the gradients numerically. stafffree below
115.What happens to log loss when a model is confidently wrong, and how does label smoothing help? staff
Capstone: embeddings and attention by hand (5)
116.Why is an embedding lookup the same as multiplying a one-hot vector by a matrix, and why do frameworks not do the multiplication? mid
117.Compute scaled dot-product attention by hand for two tokens with d_k = 2. seniorfree below
118.Walk me through the tensor shapes in multi-head attention. staff
119.Why does attention divide the scores by √d_k? What goes wrong without it? staff
120.Why does the cost of attention grow with the square of the sequence length, and what does that mean in practice? staff
Vectors (3, 4) and (4, 3) from the origin with the small angle between them marked θ ≈ 16.26° and cos θ = 24/25 = 0.96.
Why it is asked: Cosine similarity is the default score in semantic search (search by meaning, not exact words) and RAG (retrieval-augmented generation, where an LLM first looks up relevant text), and computing it by hand shows you know what it ignores.
The cosine similarity is 0.96, which means the two vectors point in almost the same direction: the angle between them is about 16.26°.
Cosine similarity is the cosine of the angle between two vectors. It keeps direction and ignores length:
cos(a, b) = (a·b) / (‖a‖ ‖b‖)
where a·b is the dot product (multiply position by position and add) and ‖a‖ is the length of a, the square root of the sum of its squared entries.
Step by step for a = (3, 4), b = (4, 3):
1. Dot product: 3·4 + 4·3 = 24.
2. Lengths: ‖a‖ = √(9 + 16) = 5 and ‖b‖ = √(16 + 9) = 5.
3. Cosine: 24 / (5 · 5) = 24 / 25 = 0.96.
4. Angle: arccos(0.96) ≈ 16.26° (2 decimals).
How to read the value. It always lies between -1 and 1:
- 1: same direction.
- 0: at a right angle, no shared direction.
- -1: opposite directions.
Length really is ignored. For p = (1, 2, 3) and q = (2, 4, 6), q is just 2 × p, and cos(p, q) = 28 / (√14 · √56) = 28 / 28 = 1, a perfect match even though q is twice as long.
This is why cosine is popular for text embeddings: we usually care about what a text is about (the direction), not about the overall size of the numbers (the length).
What the interviewer listens for
cos = a·b / (‖a‖‖b‖), range -1 to 1.
Worked: 24 / 25 = 0.96, angle ≈ 16.26°.
Scaling a vector does not change its cosine with anything.
1 same, 0 unrelated, -1 opposite.
Follow-ups the interviewer may ask
What is cosine distance? Hint: 1 - cosine similarity, so 0.04 here.
Can cosine similarity be negative for embeddings? Hint: yes in principle, though many text models rarely produce negative scores for real texts.
How do you compute it fast for millions of vectors? Hint: normalize once, then it is a dot product, a single matrix multiply.
Common mistakes
Reporting the dot product (24) as the similarity.
Thinking 0.96 means '96% of the meaning is shared'; it is the cosine of an angle, not a percentage.
Shape grids for a 4 by 3 matrix times a 3 by 2 matrix giving 4 by 2, with one row and one column combining into one output cell.
Why it is asked: Shape errors are the most common bug in model code. The interviewer checks the inner-dimension rule and how frameworks store weights.
The input is 32 × 784, the weight matrix is 784 × 128, and the output is 32 × 128. The rule: an (m × k) matrix times a (k × n) matrix gives an (m × n) matrix, and the two inner sizes (k and k) must match.
Where the numbers come from:
- MNIST is a famous dataset of 28 × 28 pictures of handwritten digits 0-9. A dense layer with 128 units is a layer of 128 neurons, each connected to every input pixel.
- Each image is 28 × 28 = 784 gray pixels, flattened into one row of 784 features.
- 32 images stacked as rows give X of shape (32 × 784): batch × features.
- W has one column per unit: (784 × 128).
- Y = XW is (32 × 128): one row of 128 outputs per image. The bias, 128 numbers, is added to every row (broadcasting).
Why the inner sizes must match: entry (i, j) of the result is the dot product of row i of X and column j of W, and a dot product needs two vectors of the same length, here 784.
Two practical details:
- PyTorch's nn.Linear(784, 128) stores its weight as (128 × 784), that is (out × in), and computes Y = XWᵀ + b. Same math, transposed storage.
- With extra leading dimensions, such as (batch, tokens, features), where tokens are the word pieces of a text, the @ operator multiplies the last two dimensions and treats the rest as a batch: (8 × 50 × 768) @ (768 × 3072) gives (8 × 50 × 3072).
What the interviewer listens for
(m × k)(k × n) = (m × n); inner sizes must match.
Worked: (32 × 784)(784 × 128) = (32 × 128).
Bias is broadcast across the batch rows.
nn.Linear stores W as (out × in) and uses XWᵀ.
Follow-ups the interviewer may ask
How many parameters does this layer have? Hint: 784 × 128 + 128 = 100,480.
What shape does a (B × n × d) tensor have after @ (d × d_ff)? Hint: (B × n × d_ff).
Why put the batch first? Hint: one large matrix multiply per batch keeps the GPU busy.
Common mistakes
Writing the weight as (128 × 784) and forgetting the transpose in a hand-written layer.
Flattening images to (784 × 32) and mixing up batch and feature axes.
Three isometric columns for 10,000 people tested: 90 true positives, 891 false positives and 981 positives in total, drawn to scale.
Why it is asked: It is the most asked Bayes question. The interviewer checks whether you anchor on the 90% or work through the 1% prior.
About 9.2%, not 90%. Most positives come from the huge healthy group, so a positive result is still more likely a false alarm than a real case.
Terms: sensitivity = P(test positive | sick). False positive rate = P(test positive | healthy). Specificity = P(test negative | healthy) = 1 - false positive rate = 0.91. Prevalence = P(sick) before any test, which is the prior.
The clearest way is natural frequencies. Imagine 10,000 people:
- Sick: 1% of 10,000 = 100 people. The test catches 90% of them: 90 true positives (10 are missed).
- Healthy: 9,900 people. 9% of them test positive anyway: 891 false positives.
- Total positives: 90 + 891 = 981.
- P(sick | positive) = 90 / 981 ≈ 0.0917, about 9.2%.
The same with Bayes' theorem: P(sick | +) = P(+ | sick) × P(sick) / P(+) = (0.90 × 0.01) / (0.90 × 0.01 + 0.09 × 0.99) = 0.009 / 0.0981 ≈ 0.0917.
The test still did its job. Belief rose from 1% to 9.2%, about 9 times higher. It is a screening result that calls for a better second test, not a diagnosis.
A negative result is very reassuring: P(sick | negative) = 10 / (10 + 9,009) = 10 / 9,019 ≈ 0.0011, about 0.11%.
The same pattern appears in fraud models, content moderation and any alert on a rare event: when the condition is rare, even a good test produces mostly false alarms.
What the interviewer listens for
Use the prior: 1% prevalence.
10,000 people: 90 true positives vs 891 false positives.
P(sick | +) = 90 / 981 ≈ 0.0917.
A negative is very reassuring: ≈ 0.0011.
Follow-ups the interviewer may ask
What if prevalence were 10%? Hint: 0.09 / (0.09 + 0.081) ≈ 0.5263.
Which number should improve to raise the posterior most? Hint: the false positive rate, because the healthy group is 99 times larger.
What is the specificity here? Hint: 1 - 0.09 = 0.91.
Common mistakes
Answering 90% (confusing P(+ | sick) with P(sick | +)).
Two gradient curves against the logit for a true label of 1: cross-entropy stays near 1 when the model is confidently wrong, while MSE collapses toward 0, with values 0.9933 and 0.01321 marked at z = -5.
Why it is asked: Tests whether you can derive gradients through the sigmoid and explain a design choice from first principles.
With a sigmoid output, the MSE gradient is multiplied by the sigmoid's slope, which is nearly zero when the model is confidently wrong, so learning stalls exactly where it is needed; cross-entropy cancels that factor.
Setup: z is the raw score (logit), ŷ = σ(z) = 1 / (1 + e^(-z)) is the predicted probability, and y ∈ {0, 1} is the label. The sigmoid's slope is ŷ(1 - ŷ).
- MSE, L = (ŷ - y)²: by the chain rule, ∂L/∂z = 2(ŷ - y) · ŷ(1 - ŷ).
- Cross-entropy, L = -[y ln ŷ + (1 - y) ln(1 - ŷ)]: the gradient simplifies to ∂L/∂z = ŷ - y.
Worked example, true label y = 1 (4 significant figures):
- z = -5, confidently wrong: ŷ = 0.006693. Cross-entropy gradient -0.9933. MSE gradient 2 × (-0.9933) × 0.006693 × 0.9933 = -0.01321, about 75 times smaller.
- z = -2: ŷ = 0.1192. Cross-entropy -0.8808, MSE -0.1850.
- z = 0: ŷ = 0.5. Cross-entropy -0.5, MSE -0.25.
So with MSE, beyond a point, the worse the mistake, the weaker the push to fix it. With cross-entropy the push grows toward 1 as the model gets more wrong.
Two more reasons:
- For logistic regression, cross-entropy is convex in the weights (one minimum); MSE through a sigmoid is not, and has flat regions.
- Cross-entropy is the maximum likelihood loss for a yes/no (Bernoulli) label, so it trains calibrated probabilities.
Some write MSE as ½(ŷ - y)², which halves the MSE gradients above; the conclusion stays the same.
What the interviewer listens for
MSE gradient carries the factor ŷ(1 - ŷ), which vanishes at saturation (the sigmoid's flat part).
Cross-entropy gradient is ŷ - y, no vanishing factor.
Worked at z = -5: -0.9933 vs -0.01321, about 75 times.
Cross-entropy is convex for logistic regression and is the Bernoulli MLE.
Follow-ups the interviewer may ask
Does the same hold for softmax? Hint: yes, softmax plus cross-entropy gives gradient q - p with no extra slope factor.
Is MSE ever used on probabilities? Hint: the Brier score (mean squared error between probabilities and 0/1 labels) is MSE on probabilities, used to evaluate calibration, not usually to train.
Why compute the loss from logits? Hint: PyTorch's BCEWithLogitsLoss (binary cross-entropy that takes raw scores) uses a stable log-sum-exp form and avoids ln 0.
Common mistakes
Saying MSE 'cannot' be used, rather than explaining why it trains badly.
A handwritten derivation of attention for two tokens: scores, scaling by √2, row softmax weights 0.6698 and 0.3302, and outputs (1.6605, 2.6605) and (2, 3).
Why it is asked: Interviewers at LLM teams ask this to see that you know every step of attention, not just the formula.
Attention gives each token a new vector that is a weighted average of the value vectors, with weights from how well its query matches each key: Attention(Q, K, V) = softmax(QKᵀ / √d_k) V.
Symbols: Q (queries), K (keys) and V (values) hold one row per token. A query is what a token is looking for, a key is what each token offers, a value is the information it passes on. d_k is the length of each query and key; softmax turns a row of scores into positive weights that add up to 1: softmax(zᵢ) = exp(zᵢ) / Σⱼ exp(zⱼ).
Inputs (2 tokens, d_k = 2): Q = [[1, 0], [1, 1]], K = [[1, 0], [0, 1]], V = [[1, 2], [3, 4]].
1. Scores S = QKᵀ. Token 1: (1, 0)·(1, 0) = 1 and (1, 0)·(0, 1) = 0. Token 2: 1 and 1. So S = [[1, 0], [1, 1]].
2. Divide by √2 ≈ 1.4142: [[0.7071, 0], [0.7071, 0.7071]].
3. Softmax per row. Row 1: exp(0.7071) ≈ 2.0281 and exp(0) = 1, so the weights are 2.0281 / 3.0281 ≈ 0.6698 and 0.3302. Row 2: two equal scores give 0.5 and 0.5.
4. Output = weights × V. Token 1: 0.6698·(1, 2) + 0.3302·(3, 4) ≈ (1.6605, 2.6605). Token 2: 0.5·(1, 2) + 0.5·(3, 4) = (2, 3).
(Outputs use the unrounded weights; all values rounded to 4 decimals.)
In a decoder such as GPT, a causal mask (which stops a token from looking at later tokens) sets the score for token 1 looking at token 2 to minus infinity before the softmax, so token 1 gets weights (1, 0) and output (1, 2).
What the interviewer listens for
softmax(QKᵀ/√d_k)V, row by row.
Worked: weights (0.6698, 0.3302) and (0.5, 0.5).
Outputs (1.6605, 2.6605) and (2, 3).
Causal mask uses minus infinity before softmax.
Follow-ups the interviewer may ask
What changes in cross-attention? Hint: Q comes from one sequence, K and V from another, such as the encoder output.
Why softmax rather than plain normalization? Hint: it handles negative scores and gives smooth gradients.
How does the KV cache use this? Hint: during generation, earlier K and V rows are stored and only the new query row is computed.
Common mistakes
Applying softmax over the whole matrix instead of each row.
Linear algebra, gradients, probability and Bayes, statistics, optimization and a tiny network by hand.
120 questions and 147 diagrams, each with why it is asked, a full answer, what the interviewer listens for, follow-ups, common mistakes and a diagram. By Roni Das.
24 junior · 42 mid · 36 senior · 18 staff
Sections, from small ideas to big ones
Linear algebra: vectors and similarity
Linear algebra: matrices as transformations
Linear algebra: eigenvalues, PSD matrices, PCA and SVD
Calculus: derivatives
Calculus: chain rule and gradients
Calculus: backpropagation by hand
Calculus: initialization and normalization
Calculus: training deep networks
Optimization: loss functions
Optimization: gradient descent and learning rate
Optimization: optimizers, regularization and clipping
Probability: rules
Probability: Bayes' theorem
Probability: distributions
Probability: expectation and variance
Statistics: describing data
Statistics: inference
Statistics: estimation with MLE, MAP and Bayes
Statistics: evaluating models
Information theory: entropy
Information theory: cross-entropy and KL divergence