def _create_dictionary(sequences):
    """
    Create id/token mappings for sequences.
    :param sequences: list of token sequences
    :return: mappings from id to token, and token to id
    """
    tokens = {}
    for s in sequences:
        for token in s:
            tokens[token] = tokens.get(token, 0) + 1

    sorted_tokens = sorted(tokens.items(), key=lambda x: -x[1])  # inverse sort
    id2token = []
    token2id = {}
    for i, (t, _) in enumerate(sorted_tokens):
        id2token.append(t)
        token2id[t] = i

    return id2token, token2id