Problem library

ML building blocks, one implementation at a time.

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

22 problems

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