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
- A Floor That Moves (Easy, free): Min-p sampling throws away unlikely tokens, but the cutoff moves with how sure the model is.
- 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.
- Finish the Model's Sentence (Easy, free): A language model's JSON often arrives cut off, with brackets still open.
- 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.
- 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.
- 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.
- Greedy Decoding (Easy): Given a score for every word in a model's vocabulary, return the index of the highest score.
- KV Cache Window (Easy): Given a stream of keys and a max length, return what's left in the cache, oldest first.
- Label Smoothing (Easy): Given a one-hot label and a smoothing amount eps, return the smoothed label, rounded to 4 decimals.
- Normalize an Embedding (Easy): Given an embedding vector, scale it to length 1, rounded to 4 decimals.
- 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.
- 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.
- Keep the Best Beams (Medium, free): Beam search keeps several half-finished sentences alive instead of betting on one.
- 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.
- 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.
- Walk Toward the Query (Medium, free): Vector databases do not compare a query with every stored vector.
- Which Side of Each Line (Medium, free): Locality-sensitive hashing gives similar vectors the same short code, so finding near-duplicates becomes a lookup.
- 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.
- INT8 Quantization (Medium): Given a list of decimal weights, convert them to integers from -127 to 127.
- 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.
- 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.
- 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.
- 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.
- Temperature Softmax (Medium): Given a list of scores and a temperature, return softmax probabilities, rounded to 4 decimals.
- Top-K Sampling Filter (Medium): Given a list of scores and k, return the indices of the k highest scores, highest first.
- 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.
- 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.
- Relevant, Not Repetitive (Hard, free): The five most relevant passages for a question are often the same paragraph five times.
- BPE Merge Step (Hard): Given a list of tokens, return the neighboring pair that shows up most often, as [left, right].
- Nucleus (Top-P) Sampling (Hard): Given a list of probabilities and a threshold p, return the indices to keep, most likely first.
- Reciprocal Rank Fusion (Hard): Given two ranked lists of documents, return every document sorted by its fused score, best first.
- Rotary Position Embedding (Hard): Given a vector, a position, and theta, rotate the vector and return it, rounded to 4 decimals.
- 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