We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
← Decoding Strategies step 5 of 8
Hard
End-to-End
Beam Search
Implement beam search decoding.
Given a log-probability matrix where log_probs[t][v] is the log-probability
of token v at time step t, find the top-k highest-scoring sequences.
At each time step:
- Expand each beam with all possible next tokens
-
Score each candidate:
beam_score + log_probs[t][v] -
Keep only the top
beam_widthcandidates
Input:
-
log_probs: shape(T, V)— log-probabilities at each time step -
beam_width: number of beams to keep (int)
Output: A dict with:
- “sequences”: the best sequence (list of token indices, length T)
-
“score”: the log-probability score of the best sequence (scalar)
Loading visualization…
Nothing accepted yet. When a submission passes, the code that passed shows up
here, one entry per mode.
Stuck?
PyTorch reference solution
Sign in to attempt this problem and reveal the reference solution.