The decoder writes one German word at a time, and each step offers many possible words. Taking the most likely one every time (greedy) can paint it into a corner. Beam search keeps the few best beginnings at every step and only decides at the end. Here is that search for your sentence.
The translation with a beam of 4
Anna hat einen kleinen Hund . Sie mag ihn .
Greedy (always the top word): Anna hat einen kleinen Hund . Sie mag ihn .
The search, step by step
Each column is one step. A box is a beginning kept in the beam; a box with a square is a translation that ended there. A line joins each box to the beginning it extends; the path of the chosen translation is marked. The candidates dropped at each step are counted under the column.
The finished translations, ranked with the length penalty
#
Translation
Words
Log-probability
Length penalty
Score
1
Anna hat einen kleinen Hund . Sie mag ihn .
11
−0.8043
1.801
−0.4465
2
Anna hat einen öffnen einen kleinen Hund . Sie mag ihn .
13
−7.9367
1.933
−4.1055
3
Anna hat einen kleinen Hund . Sie mag ihn . Lampe .
13
−8.3971
1.933
−4.3437
4
Anna hat einen kleinen Hund . Sie mag ihn . Auto .
13
−8.4355
1.933
−4.3635
5
Anna hat einen kleinen Mann . Sie mag ihn .
11
−7.9613
1.801
−4.4198
6
Anna hat einen Eine Hund . Sie mag ihn .
11
−8.0386
1.801
−4.4627
How beam search decides
At every step, each beginning in the beam is extended by its most likely next words, and of all those candidates only the best few (the beam width) are kept, ranked by log-probability: the sum of the logarithms of each word's probability, 0 for certain, more negative for less likely. A candidate ending with </s> is a finished translation and leaves the beam. The search stops when it has as many finished translations as the beam is wide.
Every extra word adds a negative log-probability, so longer translations would always lose. The length penalty divides each finished translation's log-probability by ((5 + length) / 6)^α before they are compared: α = 0 ignores length, bigger α favours longer translations.
In the paper (6.1)
“we used beam search with a beam size of 4 and length penalty α = 0.6”