fairseq
fairseq copied to clipboard
Beam Size Search is defined to be 2 * beam in Fairseq
Why in Fairseq sequence generator we have this:
# number of candidate hypos per step
cand_size = 2 * beam_size # 2 x beam size in case half are EOS
https://github.com/facebookresearch/fairseq/blob/1f533150710a3b393650dc4e3998c3675e42e3c9/fairseq/sequence_generator.py#L321
For example, if the input beam size is 2, then we are running a beam search with 4 beam width. Why is this necessary?
Also, when eos appears, why do we replace its cumulative score with the one after in the top 4 entries? what is the purpose?
scores.view(bsz, beam_size, -1)[:, :, step] = torch.gather(
cand_scores, dim=1, index=active_hypos
)
https://github.com/facebookresearch/fairseq/blob/1f533150710a3b393650dc4e3998c3675e42e3c9/fairseq/sequence_generator.py#L565