WRITE · TRACE · UNDERSTAND

Beam Search

Greedy search discards every alternative immediately.

Your experiment

beam_search(transitions, start, steps, width) returns the highest log-score token path (including start) after exactly steps expansions. transitions maps a token to (next_token, probability) pairs; all expanded tokens have successors and probabilities > 0. Keep width paths; ties use lexicographic path order.

Python runs in your browser. Your draft stays on this device.

What to look for

Greedy search discards every alternative immediately. Keep a bounded set of complete prefixes, sum log probabilities and prune globally after each step.

Watch your code work

Ready to experiment

Write a solution or load the worked answer, then choose Trace & check.

Step through arrays, variables and training curves produced by your own Python.