Six Fundamentals on a Delivery App: SHAP, Word2vec, Forests, Normalization, Bias-Variance, Attention

MediumClassical ML

Reported in interviews at Gopuff

Problem statement

You interview for a team at a grocery-delivery app. The interviewer walks through six fundamentals, each tied to something the team ships: explaining a basket-size model to the marketing team, learning product embeddings from shopping sessions, predicting late deliveries with tree ensembles, normalizing vectors for similarity search, diagnosing a demand model, and the transformer that encodes search queries.

  1. SHAP. A model predicts the number of items in a basket as $f = 10 + 4\,\text{promo} + 6\,\text{promo} \cdot \text{member}$, where both inputs are 0/1. Using the single background row $(\text{promo}, \text{member}) = (0, 0)$, what is the SHAP value of member for a customer with $(1, 1)$? What does a SHAP value explain, and why do correlated features complicate it?
  2. Word2vec. Product ids in each shopping session are treated as a "sentence". Many products are rare. Should the team train with CBOW or skip-gram, and what is the key limitation of one vector per product?
  3. Random forests. A bagged ensemble of 300 deep trees that considers every feature at every split barely beats a single tree on late-delivery prediction, where one feature (distance) dominates. What change helps, and why?
  4. L1 and L2 normalization. A product vector is $v = (3, -4, 0, 12)$. What is the last component after L2 normalization? Contrast it with L1 normalization, and say what to do with an all-zero vector.
  5. Bias and variance. At one store and day the true expected demand is 10 units. Five models trained on five independent samples of history predict 12, 14, 10, 16 and 13. The noise variance of actual demand around its expectation is 2. What is the expected squared prediction error of this modeling procedure at that point?
  6. Transformers. Explain scaled dot-product self-attention, multiple heads, positional information and masking, how cost grows with query length, and how the resulting token vectors differ from word2vec vectors.
Show hint

For each part, recall the exact definition first: Shapley averaging, the variance of an average, and the error decomposition.

Relevant roles: ML Engineer, Data Scientist and Applied Scientist.

Related free problems