'Builds a vocabulary mapping from word to index based on the sentences.
Returns vocabulary mapping and inverse vocabulary mapping.'

def build_vocab(self, sentences):

    word_counts = collections.Counter(sentences)
    vocabulary_inv = [x[0] for x in word_counts.most_common()]
    vocabulary_inv = list(sorted(vocabulary_inv))
    vocabulary = {x: i for (i, x) in enumerate(vocabulary_inv)}
    return [vocabulary, vocabulary_inv]
