results["predictions"][b].append(pred)
results["attention"][b].append(
attn if attn is not None else [])
non_finished = end_condition.eq(0).nonzero().view(-1)
// If all sentences are translated, no need to go further.
if len(non_finished) == 0:
break
// Remove finished batches for the next step.
After Change
if attention is not None else None))
// End condition is the top beam finished and we can return
// n_best hypotheses.
if top_beam_finished[i] and len(hypotheses[b]) >= n_best:
best_hyp = sorted(
hypotheses[b], key=lambda x: x[0], reverse=True)
for n, (score, pred, attn) in enumerate(best_hyp):