Problem library
ML building blocks, one implementation at a time.
Practice the functions, model classes, and training loops inside production ML systems.
Precision@K
Measure relevant results among the highest-scored k examples.
Recall@K
Measure how many relevant items appear in the top k results.
NDCG
Normalize discounted gain against the best possible ranking.
Mean Average Precision
Average Precision over every relevant item in the ranked list.
AUC
Measure pairwise ordering quality across positive and negative examples.
Log Loss
Evaluate probabilistic predictions with numerical stability.
Calibration Error
Measure how far predicted probabilities are from empirical positive rates.
Weighted AUC
Implement Weighted AUC with production-minded edge case handling.
Grouped AUC
Implement Grouped AUC with production-minded edge case handling.
Binary Cross-Entropy
Implement stable binary cross entropy with optional weights.
Softmax Cross-Entropy
Implement Softmax Cross-Entropy with production-minded edge case handling.
Pairwise Ranking Loss
Implement Pairwise Ranking Loss with production-minded edge case handling.
Hinge Loss
Implement Hinge Loss with production-minded edge case handling.
Focal Loss
Implement Focal Loss with production-minded edge case handling.
Sample Weighting
Implement Sample Weighting with production-minded edge case handling.
Negative Sampling
Implement Negative Sampling with production-minded edge case handling.
IPS Weighting
Implement IPS Weighting with production-minded edge case handling.
PyTorch Training Step
Run one PyTorch forward, MSE loss, backward, optimizer step, and updated prediction pass.
Minibatch Iterator
Implement Minibatch Iterator with production-minded edge case handling.
Feature Normalization
Implement Feature Normalization with production-minded edge case handling.
Categorical Encoding
Implement Categorical Encoding with production-minded edge case handling.
Sequence Padding
Pad or truncate variable-length token sequences and build attention masks.
Time-Window Aggregation
Aggregate timestamped values into fixed windows while preserving empty gaps.
Deduplication
Remove duplicate identifiers while preserving their first-occurrence order.
Time-Based Train/Test Split
Split events chronologically without future leakage.
Top-K Heap
Select highest-scoring items efficiently with deterministic heap ordering.
Cosine Similarity
Compare vectors while handling zero norms safely.
Brute-Force Nearest Neighbor
Find exact nearest neighbors by exhaustively ranking Euclidean distances.
Inverted Index
Build token posting lists and evaluate deterministic conjunctive queries.
BM25
Score documents using term frequency, IDF, and length normalization.
Two-Stage Ranker
Retrieve a bounded candidate set before applying a stronger ranking signal.
Reranker Interface
Preserve candidate identity while fusing and ranking aligned score batches.
Compare Two Datasets
Debug deterministic schema and aligned-row comparisons between datasets.
Detect Null Drift
Flag suspicious changes in feature null rates.
Feature Distribution Comparison
Debug fixed-bin PSI calculation and drift classification.
Label Distribution by Segment
Debug segment-local label distributions with stable dense output axes.
Calibration by Bucket
Debug a per-bin calibration table while preserving gaps and empty buckets.
Confusion Matrix by Group
Debug deterministic grouped TN, FP, FN, and TP counts.
PyTorch Contrastive Loss
Debug a mini-batch query-document contrastive trainer with in-batch negatives.
PyTorch Streaming Softmax
Compute stable softmax probabilities from chunked logits with an online max and denominator.
Stable Softmax
Convert logits into probabilities without overflow or underflow.
Masked Softmax
Normalize only valid logits while assigning masked positions zero probability.
Sinusoidal Positional Encoding
Build deterministic position vectors from paired sine and cosine frequencies.
Layer Normalization
Implement LayerNorm and compare its Pre-LN and Post-LN placement in a residual block.
SwiGLU Feed-Forward Block
Gate an up projection with stable SiLU before projecting back to model width.
Scaled Dot-Product Attention
Compute stable masked attention from query, key, and value matrices.
BPE Merge
Apply one deterministic byte-pair encoding merge across a token sequence.
BPE Tokenizer
Tokenize Unicode text with ranked BPE merges and encode the final symbols as vocabulary IDs.
Multi-Head Attention
Project, split, attend, concatenate, and mix multiple attention heads.
Grouped-Query Attention
Build a reusable layer that shares projected key-value heads across contiguous query-head groups.
Rotary Positional Encoding
Rotate paired query or key features with position-dependent frequencies.
KV Cache Update
Write newly projected keys and values into a reusable autoregressive cache.
Greedy Decoding
Select the highest-logit token at each generation step until EOS or a length limit.
Temperature Sampling
Sample autoregressive tokens from temperature-scaled logits with deterministic random draws.
Top-K Sampling
Sample autoregressive tokens after restricting each temperature-scaled distribution to its deterministic top-k set.
Top-P Sampling
Sample autoregressive tokens from the smallest deterministic nucleus that reaches a probability threshold.
PyTorch Causal Mask
Build a batched boolean decoder self-attention mask from causal order and key padding.
PyTorch Pairwise Distances
Use singleton dimensions and broadcasting to compute every row-pair distance.
PyTorch Batched Embedding Lookup
Look up token embeddings while preserving batch and sequence axes.
PyTorch Final Logits Selection
Select each padded sequence's last valid vocabulary-logit row for autoregressive decoding.
MMoE Task Routing
Mix shared expert outputs with an independent softmax gate for each task.
Sparse MoE Routing
Route each token to a capacity-limited top-k subset of experts.
KNN Classifier
Fit a complete nearest-neighbor classifier and predict labels for new examples.
K-Means Clustering
Train a deterministic K-Means model from initial centroids through convergence.
Gaussian Mixture Model
Fit a diagonal-covariance Gaussian mixture model with expectation-maximization.
Principal Component Analysis
Learn deterministic principal directions and use them for dimensionality reduction and reconstruction.
Linear Regression Trainer
Train linear regression end to end with explicit gradients and parameter updates.
Logistic Regression Trainer
Train a numerically stable binary classifier with gradient descent.
Two-Layer Neural Network Trainer
Implement forward propagation, manual backpropagation, and prediction for a small MLP.