from typing import Counter


def create_vocabulary(text):
    """Create vocabulary dictionaries.

    Args:
        text(str): raw text.

    Returns:
        char2id(dict): character to id mapping.
        id2char(dict): id to character mapping.
    """
    char2id = {'<PAD>': 0}
    id2char = {0: '<PAD>'}
    freq = Counter(text)
    for char, _ in freq.most_common():
        id = len(char2id)
        char2id[char] = id
        id2char[id] = char

    return char2id, id2char