def build_vocab_fn(chars):
    """Build functions for mapping characters to integer ids and vice versa."""
    vocab_dict = dict()
    for char in chars:
        vocab_dict[char] = len(vocab_dict) + 1
    reverse_vocab_dict = dict(zip(vocab_dict.values(), vocab_dict.keys())) 
    def char2id(char):
        if char in chars:
            return vocab_dict[char]
        else:
            return 0
    def id2char(i):
        if i > 0 and i < len(chars) + 1:
            return reverse_vocab_dict[i]
        else:
            return ' '
    return char2id, id2char