import collections


def generate_vocab(text):
    """
    Generate a vocabulary from `text`.

    Tokens are assumed to be separated by whitespaces. <unk> characters
    have been explicitely removed from this vocabulary generator.
    """
    tokens = text.split()
    counter = collections.Counter(tokens)
    # We do not want to store the <unk>, <s>, </s> character in vocabulary
    del counter["<unk>"]
    del counter["<s>"]
    del counter["</s>"]
    count_pairs = sorted(counter.items(), key=lambda x: -x[1])
    unique_tokens, _ = zip(*count_pairs)
    vocab = dict(zip(unique_tokens, range(len(unique_tokens))))
    return vocab