69 hands-on ML coding exercises

Practice ML/AI coding interviews.

Build fluency with focused Python and NumPy exercises across metrics, training, retrieval, debugging, and models from scratch. Run tests instantly in your browser.

Free to start · No signup required · Remote PyTorch execution supported

scaled_dot_product_attention.pyPyTorch
import math
import torch

def scaled_dot_product_attention(query, key, value, mask):
    # 1. Compute scaled query-key scores
    d_k = query.shape[-1]
    scores = query @ key.transpose(-2, -1) / math.sqrt(d_k)

    # 2. Mask and apply stable softmax
    scores = scores.masked_fill(~mask, float("-inf"))
    weights = torch.softmax(scores, dim=-1)

    # 3. Weighted sum of values
    return weights @ value
6 / 6 public tests passed

Seven practical tracks

Focused implementations. Real ML judgment.

Guided roadmaps

Know what to practice next.

Follow focused problem sets that connect foundations to practical outcomes, starting with systematic ML debugging.

Explore roadmaps