def decode2string(index2token, indices, end_token="END_TOKEN", remove_END_TOKEN=False):
    """
    Decode a list of indices to string.
    Args:
        index2token: a dictionary that maps indices to tokens
        indices: a list of indices that correspond to tokens
        remove_END_TOKEN: boolean indicating whether to remove the "END_TOKEN" (optional)
    Returns:
        the decoded string
    """
    decoded = [index2token[index] for index in indices]
    while True:
        if remove_END_TOKEN == True and decoded != []:
            if decoded[-1] == end_token:
                del decoded[-1]
            else:
                break
        else:
            break
    return (' ').join(decoded)