At each step every sequence in the beam is extended by every possible next token, the candidates are scored by total log-probability, and the top k are kept. Greedy decoding is beam search with k = 1. Typical beams are 4 to 10 wide; wider beams cost more and often stop improving quality.
Example: the first token is A with probability 0.5 or B with 0.4. After A, the best next token has probability 0.4; after B, 0.9. Greedy decoding takes A and ends with 0.5 × 0.4 = 0.20. A beam of 2 keeps both A and B and finds B followed by its best token, 0.4 × 0.9 = 0.36.
Follow-ups: since each extra token multiplies in a probability below 1, beam search favors short outputs, so scores are normalized by length, as in Google's neural machine translation system (Wu and colleagues, 2016). For open-ended text it produces bland, repetitive output (Holtzman and colleagues, 2019, on neural text degeneration), which is why chat models sample with temperature and top-p instead. Beam search remains common in translation, speech recognition and other tasks with one right answer.