Problem library

ML building blocks, one implementation at a time.

Practice the functions, model classes, and training loops inside production ML systems.

69 problems

Precision@K

Measure relevant results among the highest-scored k examples.

MetricsEasyPractice

Recall@K

Measure how many relevant items appear in the top k results.

MetricsEasyPractice

NDCG

Normalize discounted gain against the best possible ranking.

MetricsMediumPractice

Mean Average Precision

Average Precision over every relevant item in the ranked list.

MetricsMediumPractice

AUC

Measure pairwise ordering quality across positive and negative examples.

MetricsMediumPractice

Log Loss

Evaluate probabilistic predictions with numerical stability.

MetricsEasyPractice

Calibration Error

Measure how far predicted probabilities are from empirical positive rates.

MetricsMediumPractice

Weighted AUC

Implement Weighted AUC with production-minded edge case handling.

MetricsHardPractice

Grouped AUC

Implement Grouped AUC with production-minded edge case handling.

MetricsHardPractice

Binary Cross-Entropy

Implement stable binary cross entropy with optional weights.

Loss & TrainingEasyPractice

Softmax Cross-Entropy

Implement Softmax Cross-Entropy with production-minded edge case handling.

Loss & TrainingMediumPractice

Pairwise Ranking Loss

Implement Pairwise Ranking Loss with production-minded edge case handling.

Loss & TrainingMediumPractice

Hinge Loss

Implement Hinge Loss with production-minded edge case handling.

Loss & TrainingEasyPractice

Focal Loss

Implement Focal Loss with production-minded edge case handling.

Loss & TrainingMediumPractice

Sample Weighting

Implement Sample Weighting with production-minded edge case handling.

Loss & TrainingMediumPractice

Negative Sampling

Implement Negative Sampling with production-minded edge case handling.

Loss & TrainingMediumPractice

IPS Weighting

Implement IPS Weighting with production-minded edge case handling.

Loss & TrainingHardPractice

PyTorch Training Step

Run one PyTorch forward, MSE loss, backward, optimizer step, and updated prediction pass.

Loss & TrainingMediumPractice

Minibatch Iterator

Implement Minibatch Iterator with production-minded edge case handling.

Data & FeaturesEasyPractice

Feature Normalization

Implement Feature Normalization with production-minded edge case handling.

Data & FeaturesEasyPractice

Categorical Encoding

Implement Categorical Encoding with production-minded edge case handling.

Data & FeaturesMediumPractice

Sequence Padding

Pad or truncate variable-length token sequences and build attention masks.

Data & FeaturesEasyPractice

Time-Window Aggregation

Aggregate timestamped values into fixed windows while preserving empty gaps.

Data & FeaturesMediumPractice

Deduplication

Remove duplicate identifiers while preserving their first-occurrence order.

Data & FeaturesEasyPractice

Time-Based Train/Test Split

Split events chronologically without future leakage.

Data & FeaturesMediumPractice

Top-K Heap

Select highest-scoring items efficiently with deterministic heap ordering.

Retrieval & RankingEasyPractice

Cosine Similarity

Compare vectors while handling zero norms safely.

Retrieval & RankingEasyPractice

Brute-Force Nearest Neighbor

Find exact nearest neighbors by exhaustively ranking Euclidean distances.

Retrieval & RankingMediumPractice

Inverted Index

Build token posting lists and evaluate deterministic conjunctive queries.

Retrieval & RankingMediumPractice

BM25

Score documents using term frequency, IDF, and length normalization.

Retrieval & RankingHardPractice

Two-Stage Ranker

Retrieve a bounded candidate set before applying a stronger ranking signal.

Retrieval & RankingHardPractice

Reranker Interface

Preserve candidate identity while fusing and ranking aligned score batches.

Retrieval & RankingMediumPractice

Compare Two Datasets

Debug deterministic schema and aligned-row comparisons between datasets.

DebuggingEasyPractice

Detect Null Drift

Flag suspicious changes in feature null rates.

DebuggingMediumPractice

Feature Distribution Comparison

Debug fixed-bin PSI calculation and drift classification.

DebuggingMediumPractice

Label Distribution by Segment

Debug segment-local label distributions with stable dense output axes.

DebuggingMediumPractice

Calibration by Bucket

Debug a per-bin calibration table while preserving gaps and empty buckets.

DebuggingMediumPractice

Confusion Matrix by Group

Debug deterministic grouped TN, FP, FN, and TP counts.

DebuggingHardPractice

PyTorch Contrastive Loss

Debug a mini-batch query-document contrastive trainer with in-batch negatives.

DebuggingMediumPractice

PyTorch Streaming Softmax

Compute stable softmax probabilities from chunked logits with an online max and denominator.

DebuggingMediumPractice

Stable Softmax

Convert logits into probabilities without overflow or underflow.

Neural Networks & LLM ComponentsEasyPractice

Masked Softmax

Normalize only valid logits while assigning masked positions zero probability.

Neural Networks & LLM ComponentsMediumPractice

Sinusoidal Positional Encoding

Build deterministic position vectors from paired sine and cosine frequencies.

Neural Networks & LLM ComponentsMediumPractice

Layer Normalization

Implement LayerNorm and compare its Pre-LN and Post-LN placement in a residual block.

Neural Networks & LLM ComponentsMediumPractice

SwiGLU Feed-Forward Block

Gate an up projection with stable SiLU before projecting back to model width.

Neural Networks & LLM ComponentsMediumPractice

Scaled Dot-Product Attention

Compute stable masked attention from query, key, and value matrices.

Neural Networks & LLM ComponentsMediumPractice

BPE Merge

Apply one deterministic byte-pair encoding merge across a token sequence.

Neural Networks & LLM ComponentsMediumPractice

BPE Tokenizer

Tokenize Unicode text with ranked BPE merges and encode the final symbols as vocabulary IDs.

Neural Networks & LLM ComponentsHardPractice

Multi-Head Attention

Project, split, attend, concatenate, and mix multiple attention heads.

Neural Networks & LLM ComponentsHardPractice

Grouped-Query Attention

Build a reusable layer that shares projected key-value heads across contiguous query-head groups.

Neural Networks & LLM ComponentsHardPractice

Rotary Positional Encoding

Rotate paired query or key features with position-dependent frequencies.

Neural Networks & LLM ComponentsHardPractice

KV Cache Update

Write newly projected keys and values into a reusable autoregressive cache.

Neural Networks & LLM ComponentsMediumPractice

Greedy Decoding

Select the highest-logit token at each generation step until EOS or a length limit.

Neural Networks & LLM ComponentsEasyPractice

Temperature Sampling

Sample autoregressive tokens from temperature-scaled logits with deterministic random draws.

Neural Networks & LLM ComponentsMediumPractice

Top-K Sampling

Sample autoregressive tokens after restricting each temperature-scaled distribution to its deterministic top-k set.

Neural Networks & LLM ComponentsMediumPractice

Top-P Sampling

Sample autoregressive tokens from the smallest deterministic nucleus that reaches a probability threshold.

Neural Networks & LLM ComponentsMediumPractice

PyTorch Causal Mask

Build a batched boolean decoder self-attention mask from causal order and key padding.

Neural Networks & LLM ComponentsMediumPractice

PyTorch Pairwise Distances

Use singleton dimensions and broadcasting to compute every row-pair distance.

Neural Networks & LLM ComponentsEasyPractice

PyTorch Batched Embedding Lookup

Look up token embeddings while preserving batch and sequence axes.

Neural Networks & LLM ComponentsEasyPractice

PyTorch Final Logits Selection

Select each padded sequence's last valid vocabulary-logit row for autoregressive decoding.

Neural Networks & LLM ComponentsEasyPractice

MMoE Task Routing

Mix shared expert outputs with an independent softmax gate for each task.

Neural Networks & LLM ComponentsHardPractice

Sparse MoE Routing

Route each token to a capacity-limited top-k subset of experts.

Neural Networks & LLM ComponentsHardPractice

KNN Classifier

Fit a complete nearest-neighbor classifier and predict labels for new examples.

ML Models From ScratchMediumPractice

K-Means Clustering

Train a deterministic K-Means model from initial centroids through convergence.

ML Models From ScratchMediumPractice

Gaussian Mixture Model

Fit a diagonal-covariance Gaussian mixture model with expectation-maximization.

ML Models From ScratchHardPractice

Principal Component Analysis

Learn deterministic principal directions and use them for dimensionality reduction and reconstruction.

ML Models From ScratchMediumPractice

Linear Regression Trainer

Train linear regression end to end with explicit gradients and parameter updates.

ML Models From ScratchMediumPractice

Logistic Regression Trainer

Train a numerically stable binary classifier with gradient descent.

ML Models From ScratchMediumPractice

Two-Layer Neural Network Trainer

Implement forward propagation, manual backpropagation, and prediction for a small MLP.

ML Models From ScratchHardPractice