All puzzles › Applied ML and AI

Applied ML and AI Practice Problems

33 puzzles (10 easy, 16 medium, 7 hard), 13 free, in Python, JavaScript and C++.

The code that ships inside real AI systems: decoding, attention, tokenizers, quantization and RAG.

The puzzles, easiest first

  1. A Floor That Moves (Easy, free): Min-p sampling throws away unlikely tokens, but the cutoff moves with how sure the model is.
  2. Already Paid For (Easy, free): A model server can skip work for any prompt that starts the same way as one it has already processed.
  3. Finish the Model's Sentence (Easy, free): A language model's JSON often arrives cut off, with brackets still open.
  4. Was This Written by a Model (Easy, free): One way to watermark a language model is to make it quietly prefer green tokens, where which tokens are green depends on the token before.
  5. Context Window Budget (Easy): Given the token count of each chat message, oldest first, and a token budget, return how many messages you can keep.
  6. Early Stopping (Easy): Given the validation loss after each epoch and a patience number, return the epoch where training should stop, or -1 if it never does.
  7. Greedy Decoding (Easy): Given a score for every word in a model's vocabulary, return the index of the highest score.
  8. KV Cache Window (Easy): Given a stream of keys and a max length, return what's left in the cache, oldest first.
  9. Label Smoothing (Easy): Given a one-hot label and a smoothing amount eps, return the smoothed label, rounded to 4 decimals.
  10. Normalize an Embedding (Easy): Given an embedding vector, scale it to length 1, rounded to 4 decimals.
  11. Fold In the Adapter (Medium, free): LoRA fine-tunes a model without touching its weights: it trains two thin matrices, b and a, whose product is the change.
  12. Hold Back the Tail (Medium, free): A chat interface shows text as it arrives, but must never show the stop sequence, and the stop sequence can arrive split across chunks.
  13. Keep the Best Beams (Medium, free): Beam search keeps several half-finished sentences alive instead of betting on one.
  14. One Bit per Dimension (Medium, free): An embedding can be squeezed to one bit per dimension and still find the right document most of the time.
  15. Pad Less, Pay Less (Medium, free): A model processes prompts in batches, and every prompt in a batch is padded to the length of the longest one.
  16. Walk Toward the Query (Medium, free): Vector databases do not compare a query with every stored vector.
  17. Which Side of Each Line (Medium, free): Locality-sensitive hashing gives similar vectors the same short code, so finding near-duplicates becomes a lookup.
  18. Causal Attention Mask (Medium): Given n, return an n by n grid where row i has a 1 in every column up to and including i, and 0 after.
  19. INT8 Quantization (Medium): Given a list of decimal weights, convert them to integers from -127 to 127.
  20. Mixture-of-Experts Router (Medium): Given a grid where each row holds one token's scores for every expert, return the winning expert for each token.
  21. Overlapping RAG Chunks (Medium): Given a list of tokens, a chunk size, and an overlap, split the tokens into chunks that share overlap tokens with the chunk before.
  22. Repetition Penalty (Medium): Given a list of scores, the indices of tokens already used, and a penalty, return the scores with the used ones pushed down, rounded to 4 decimals.
  23. Speculative Decoding (Medium): Given the tokens a small draft model guessed and the tokens the big model actually wants, return how many tokens you get from this round.
  24. Temperature Softmax (Medium): Given a list of scores and a temperature, return softmax probabilities, rounded to 4 decimals.
  25. Top-K Sampling Filter (Medium): Given a list of scores and k, return the indices of the k highest scores, highest first.
  26. Warmup + Cosine Decay (Medium): Given a step, the number of warmup steps, the total steps, and a base learning rate, return the rate at that step, rounded to 6 decimals.
  27. How Many Rounds of Tool Calls (Hard, free): An agent has n tool calls to make, numbered from 0, and some need another call's result first.
  28. Relevant, Not Repetitive (Hard, free): The five most relevant passages for a question are often the same paragraph five times.
  29. BPE Merge Step (Hard): Given a list of tokens, return the neighboring pair that shows up most often, as [left, right].
  30. Nucleus (Top-P) Sampling (Hard): Given a list of probabilities and a threshold p, return the indices to keep, most likely first.
  31. Reciprocal Rank Fusion (Hard): Given two ranked lists of documents, return every document sorted by its fused score, best first.
  32. Rotary Position Embedding (Hard): Given a vector, a position, and theta, rotate the vector and return it, rounded to 4 decimals.
  33. Scaled Dot-Product Attention (Hard): Given a query vector and a list of key vectors, return a score for each key, rounded to 4 decimals.

Practice another pattern

Or browse by subject

Browse all 676 puzzles