NumPy allowed · plain Python earns 10 bonus points
Softmax(logits) → probability distribution
Explore multiple high-probability generation hypotheses simultaneously using Beam Search.
Implement beam_search_step(current_beams, candidate_log_probs, beam_width, eos_token_id). For each beam in current_beams: if is_done is True, carry it forward unchanged; otherwise expand it across all vocabulary tokens $v$, updating score = round(beam['score'] + log_prob[v], 4) and setting is_done = True if $v == ext{eos_token_id}$. Sort all candidate hypotheses descending by score (breaking ties lexicographically by sequence). Prune to beam_width entries. Return dict with beams and all_done (True if every pruned beam is done). Raise ValueError if beam_width <= 0 or if input list lengths mismatch.
beam_search_step(current_beams: list[dict], candidate_log_probs: list[list[float]], beam_width: int, eos_token_id: int) -> dict