KatInterview

End-to-End Molecular Pair Regression System Design

Machine LearningModel answer
HardModel answerMachine Learningml-system-designcheminformaticsregression

Last updated

Design a complete ML pipeline to predict a real-valued interaction score for pairs of molecules, covering data quality, featurization, splitting, modeling, evaluation, and deployment.

Setting

You have a tabular dataset where each row represents a chemical pair experiment:

compound_acompound_binteraction_score
ethanolacetic acid2.34
.........

interaction_score is a continuous real number. The dataset has roughly 50,000 rows covering around 5,000 distinct compounds. Your task is to build a system that predicts interaction_score for new compound pairs, including pairs where one or both compounds were never seen during training.


What to Cover

1. Exploratory Data Analysis

  • What statistical checks and plots would you run on the label column?
  • How would you handle compound names that refer to the same substance (synonyms, inconsistent casing, alternate notations)?
  • How would you detect that row (A, B, score) and row (B, A, score) represent the same experiment?
  • What constitutes a data leakage risk in this dataset?

2. Feature Engineering

  • How do you convert a compound name into a numeric representation? Describe at least three options at different levels of complexity.
  • How do you construct a single feature vector for a pair of compounds while respecting the symmetry property (swapping A and B should not change the prediction)?
  • How do you handle compounds that appear at inference time but were absent from training?

3. Data Splitting

  • Describe at least four distinct split strategies.
  • For each, state what generalization scenario it simulates and what leakage risk it carries.
  • What evaluation buckets should you always report?

4. Modeling

  • Describe a progression from simple baselines to complex neural models.
  • How would you incorporate uncertainty estimates, and how would you validate that the uncertainty is well-calibrated?

5. Training and Evaluation

  • Which loss functions and evaluation metrics are appropriate, and when would you choose each?
  • How do you structure cross-validation to avoid optimistic estimates?
  • What slices would you inspect during error analysis?

6. Robustness and Generalization

  • What techniques reduce overfitting or improve scaffold generalization?
  • How would you use data augmentation specific to molecular data?
  • How would you detect and respond to distribution shift between training data and production queries?

7. Production

  • Describe the inference pipeline, including how precomputed molecular representations are stored and served.
  • What would trigger a model retraining?
  • What scientific safety guardrails matter here?

What Is Expected

A structured answer covering all seven areas. Justify trade-offs, call out common mistakes, and give concrete numbers or names (libraries, algorithms, metrics) where useful. You do not need to write working code, but pseudocode or equations are welcome where they add clarity.

Hints

Hint 1

Before choosing any model, pin down what the score physically means (rate constant, yield, dimensionless ratio?) because this drives whether you should model log(score), what noise floor is achievable, and which metric to optimize.

Hint 2

Symmetry is the single most common mistake: plain concatenation [e_A, e_B] is order-dependent, so pair (A,B) and pair (B,A) will receive different predictions. Use element-wise sum, product, and absolute difference instead, or a Siamese encoder with a symmetric pooling head.

Hint 3

The split strategy is not a detail — it defines what 'generalization' means. Always report performance broken into at least three buckets: both compounds seen in training, one compound unseen, and both compounds unseen. The last bucket is the hardest and the most important for real discovery workflows.