def build_dict(word_counter, vocab_size=50000):
    """
    Builds dictionary and reverse dictionary of most common words in word_counter.
        Number of words to include in the dictionary is set by dict_size.
    :param word_counter: collections.Counter() with keys = word and values = number of
    occurrences. Case sensitive.
    :param vocab_size: Upper limit on vocabulary size. If number of unique words
        greater than vocab_size, will take most commonly occurring words
    :return: tuple:
        0) dictionary of words to integers (most common word is 0, next most
            common is 1, ...)
        1) reverse dictionary of integers to words (same integer to word mapping as
            "forward dictionary"
    """
    top_words = word_counter.most_common(vocab_size)
    top_words.sort(key=lambda t: -t[1])
    dictionary = dict()
    for idx, word in enumerate(map(lambda t: t[0], top_words)):
        dictionary[word] = idx

    return dictionary