'Updates internal vocabulary based on a list of texts.
Required before using `texts_to_sequences` or `texts_to_matrix`.
# Arguments
texts: can be a list of strings,
or a generator of strings (for memory-efficiency)'

def fit_on_texts(self, texts):

    self.document_count = 0
    for text in texts:
        self.document_count += 1
        seq = (text if self.char_level else text_to_word_sequence(text, self.filters, self.lower, self.split))
        for w in seq:
            if (w in self.word_counts):
                self.word_counts[w] += 1
            else:
                self.word_counts[w] = 1
        for w in set(seq):
            if (w in self.word_docs):
                self.word_docs[w] += 1
            else:
                self.word_docs[w] = 1
    wcounts = list(self.word_counts.items())
    wcounts.sort(key=(lambda x: x[1]), reverse=True)
    sorted_voc = [wc[0] for wc in wcounts]
    self.word_index = dict(list(zip(sorted_voc, list(range(1, (len(sorted_voc) + 1))))))
    self.index_docs = {}
    for (w, c) in list(self.word_docs.items()):
        self.index_docs[self.word_index[w]] = c
