Building LDA models with a different number of topics
The number of topics is an exogenous parameter. We will build several models with a range of topics. We will use the BoW data and the TF-IDF data. To economize our code, we will develop a small function, build_lda_models()
. This function takes three arguments, as follows:
input_data
: Either BoW or TF-IDFname
: The filename to save the modelk
: The number of topics
The code is shown as follows:
def build_lda_models(input_data, name, k): np.random.seed(42) # Train the model lda = LdaModel(input_data, num_topics=k, id2word = gensim_dictionary) # Save the model from gensim.test.utils import datapath tempfile...