Python, NLP, Numpy, Scikit Learn.
doc_words.items(): if word in self.vocab: tf = word_count/doc_len idf = np.log(number_of_docs/self.word_frequency[word]) idf = 1 if idf == 0 else idf TfIdf_vec[word] = tf * idf vec = [v for v in TfIdf_vec.values()] return np.array(vec) For our example with only three sentences, the vectors