def update_top_seqs(top_seqs, beam_bptr, top_words):
    """
    Args:
        top_seqs: [batch, beam, num_words]
        beam_bptr: [batch, beam]
        top_words: [batch, beam]
    Return:
        top_seqs: [batch, beam, num_words+1]
    """
    new_seqs = []
    for bi_seqs, bi_bptr, bi_words in zip(top_seqs, beam_bptr, top_words):
        new_bi_seqs = [bi_seqs[bptr] + [word] for bptr, word in zip(bi_bptr, bi_words)]
        new_seqs.append(new_bi_seqs)
    return new_seqs