def post_process_response(token_ids, reader, merge=True):
    """Post-process the decoded sequence.

    Truncate from the first <eos> and remove the <bos> and <eos> tokens.
    Convert token_ids to words(merge=True) or tokens(merge=False)

    Args:
        token_ids: Token id sequence.
        merge: If true, merge subwords (tokens) into words, otherwise return tokens.

    Returns:
        token_ids: Truncated token_ids.
        response: A word list or a token list.
    """
    eos_pos = len(token_ids)
    for i, tok_id in enumerate(token_ids):
        if tok_id == reader.eos_id:
            eos_pos = i
            break
    token_ids = token_ids[1:eos_pos]
    response = reader.tokenizer.convert_ids_to_tokens(token_ids)
    if merge:
        response = reader.tokenizer.merge_subword(response)
    return token_ids, response