def token_ids_to_sentence(token_ids, rev_vocabulary, word_level=True):
    """Decode a sequence back to its string representation

    >>> rev_vocabulary = ['_PAD', '_GO', '_EOS', '_UNK', '1', '2', '3']
    >>> token_ids = [5, 6, 4, 2, 0, 0, 0, 0, 0]
    >>> token_ids_to_sentence(token_ids, rev_vocabulary, word_level=False)
    '231'

    >>> rev_vocabulary = ['_PAD', '_GO', '_EOS', '_UNK', 'un', 'deux']
    >>> token_ids = [5, 3, 5, 2, 0, 0, 0, 0, 0]
    >>> token_ids_to_sentence(token_ids, rev_vocabulary)
    'deux _UNK deux'

    """
    sep = " " if word_level else ""
    return sep.join(rev_vocabulary[idx] for idx in token_ids if idx > 2)