Skip to content

About

Machine learning coding interview problems, from scratch in NumPy, with tests.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Machine learning coding interview problems, from scratch in NumPy

40 problems of the kind set in the implementation round of ML engineering, research and quant interviews: write the softmax, the backward pass, the attention layer or the AUC yourself, without a library.

Each file holds the problem statement, a starter function and the test table. Write the function, then run the file: python problems/stable_softmax.py. NumPy is the only dependency.

The lessons, hints, worked solutions and an in-browser editor are at https://academicquant.co.uk/machine-learning-coding?utm_source=github&utm_medium=repo

Topic Problem Level Solution
Numerical stability Softmax that never overflows Easy lesson and solution
Numerical stability Cross-entropy loss and its gradient from logits Medium lesson and solution
Numerical stability Binary cross-entropy from logits Medium lesson and solution
Linear models Ridge regression in closed form Easy lesson and solution
Linear models Linear regression by gradient descent Medium lesson and solution
Linear models Logistic regression with an L2 penalty Medium lesson and solution
Neural networks Forward pass of a two-layer network Easy lesson and solution
Neural networks Backpropagation through a two-layer network Hard lesson and solution
Neural networks The Adam optimiser, with bias correction Medium lesson and solution
Training a network Inverted dropout, forward and backward Easy lesson and solution
Training a network Gradient clipping by global norm Easy lesson and solution
Training a network Linear warm-up with cosine decay Easy lesson and solution
Deep learning layers Layer normalisation Easy lesson and solution
Deep learning layers Batch normalisation in training mode Medium lesson and solution
Deep learning layers Scaled dot-product attention with a causal mask Medium lesson and solution
Deep learning layers 2-D convolution with stride and padding Medium lesson and solution
Sequence models One step of an LSTM cell Medium lesson and solution
Sequence models One step of a GRU cell, as PyTorch computes it Medium lesson and solution
Sequence models Beam search decoding Hard lesson and solution
Embeddings and retrieval Top-k search by cosine similarity Easy lesson and solution
Embeddings and retrieval The InfoNCE contrastive loss Medium lesson and solution
Embeddings and retrieval Skip-gram with negative sampling: loss and gradients Hard lesson and solution
Classic algorithms k-nearest neighbours classifier Easy lesson and solution
Classic algorithms k-means clustering (Lloyd's algorithm) Medium lesson and solution
Classic algorithms Principal component analysis Medium lesson and solution
Classic algorithms Best decision-tree split by Gini impurity Medium lesson and solution
Probabilistic models Gaussian naive Bayes classifier Medium lesson and solution
Probabilistic models One EM step for a Gaussian mixture Medium lesson and solution
Probabilistic models The Viterbi algorithm for a hidden Markov model Medium lesson and solution
Probabilistic models Stationary distribution of a Markov chain Easy lesson and solution
Statistics in code Running mean and variance in one pass Easy lesson and solution
Statistics in code ROC AUC from scores, with ties Medium lesson and solution
Statistics in code Spearman rank correlation (the information coefficient) Medium lesson and solution
Statistical inference The autocorrelation function of a series Easy lesson and solution
Statistical inference Regression coefficients with standard errors and t-statistics Medium lesson and solution
Statistical inference An exact permutation test for a difference in means Medium lesson and solution
Statistical inference A one-dimensional Kalman filter Medium lesson and solution
Ranking and evaluation metrics NDCG at k Easy lesson and solution
Ranking and evaluation metrics Expected calibration error Medium lesson and solution
Ranking and evaluation metrics Macro-averaged F1 across classes Easy lesson and solution

The problems and tests are original. Every reference solution is checked against an independent implementation (exact arithmetic, brute force or finite differences) on these tests and on random inputs.

About

Machine learning coding interview problems, from scratch in NumPy, with tests.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages