Beam search with finished hypotheses
Implement fixed-width beam search over a supplied transition table.
What’s going wrong
Original LLM Architecture lab. Implement the missing behavior in solve(data) and keep the supplied JSON interface. Use Python’s standard library.
Input start is a condition token, transitions[token] is a row of next-token log scores, eos is an end token, and width >= 1. Start from empty generated tokens with score zero. For up to steps rounds expand unfinished beams by every next token, keep completed EOS beams unchanged in the same pool, and retain the best width by descending cumulative score then lexicographically ascending generated IDs. Return ordered {tokens,score} results. The start token is never included in output.
Small, well-formed JSON inputs and standard-library Python arithmetic. Keep full precision during computation. The supplied output wrapper rounds results to six decimal places.
Expected behavior
Implement fixed-width beam search over a supplied transition table.
Reproduction
{"start":3,"transitions":[[-1,-2,-3,-4],[-2,-3,-0.05,-4],[0,0,0,0],[-0.4,-0.6,-4,-10]],"eos":2,"width":2,"steps":2}[{"tokens":[1,2],"score":-0.65},{"tokens":[0,0],"score":-1.4}]{"start":0,"transitions":[[0,-1,-2],[0,-1,-2],[0,-1,-2]],"eos":2,"width":3,"steps":0}[{"tokens":[],"score":0}]{"start":0,"transitions":[[-1,-2,-0.1],[-1,-1,-1],[0,0,0]],"eos":2,"width":2,"steps":3}[{"tokens":[2],"score":-0.1},{"tokens":[0,2],"score":-1.1}]Before you begin
- Python functions, lists and dictionaries
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.