def prepare_topics(weights, factors, word_vectors, vocab, temperature=1.0, doc_lengths=None, term_frequency=None, normalize=False):
 topic_to_word = []
 msg = 'Vocabulary size did not match size of word vectors'
 assert (len(vocab) == word_vectors.shape[0]), msg
 if normalize:
  word_vectors /= np.linalg.norm(word_vectors, axis=1)[:, None]
 for factor_vector in factors:
  factor_to_word = prob_words(factor_vector, word_vectors, temperature=temperature)
  topic_to_word.append(np.ravel(factor_to_word))
 topic_to_word = np.array(topic_to_word)
 msg = 'Not all rows in topic_to_word sum to 1'
 assert np.allclose(np.sum(topic_to_word, axis=1), 1), msg
 doc_to_topic = _softmax_2d(weights)
 msg = 'Not all rows in doc_to_topic sum to 1'
 assert np.allclose(np.sum(doc_to_topic, axis=1), 1), msg
 data = {'topic_term_dists': topic_to_word, 'doc_topic_dists': doc_to_topic, 'doc_lengths': doc_lengths, 'vocab': vocab, 'term_frequency': term_frequency}
 return data

def prepare_topics ( weights , factors , word_vectors , vocab , temperature = 1.0 , doc_lengths = None , term_frequency = None , normalize = False ) : topic_to_word = [ ] msg = 'Vocabulary size did not match size of word vectors' assert ( len ( vocab ) == word_vectors . shape [ 0 ] ) , msg if normalize : word_vectors /= np . linalg . norm ( word_vectors , axis = 1 ) [ : , None ] for factor_vector in factors : factor_to_word = prob_words ( factor_vector , word_vectors , temperature = temperature ) topic_to_word . append ( np . ravel ( factor_to_word ) ) topic_to_word = np . array ( topic_to_word ) msg = 'Not all rows in topic_to_word sum to 1' assert np . allclose ( np . sum ( topic_to_word , axis = 1 ) , 1 ) , msg doc_to_topic = _softmax_2d ( weights ) msg = 'Not all rows in doc_to_topic sum to 1' assert np . allclose ( np . sum ( doc_to_topic , axis = 1 ) , 1 ) , msg data = { 'topic_term_dists' : topic_to_word , 'doc_topic_dists' : doc_to_topic , 'doc_lengths' : doc_lengths , 'vocab' : vocab , 'term_frequency' : term_frequency } return data
collects a dictionary of word .