def __train_topicmodel(self, num_topics=1): if num_topics <= 1: if self.num_topics == 1: self.num_topics, optim_decay = self.__chooseK(limit=20, start=2, step=1) else: raise ValueError( "Please enter num_topics '> 1' or put '= 1' if you want suggestions" ) else: # if self.num_topics == 1: self.num_topics = num_topics optim_decay = 0.7 if self.algo == 'gensim': # Build LDA model ldamodel = LdaMulticore(corpus=self.corpus, id2word=self.dictionary, num_topics=self.num_topics, passes=20, alpha='asymmetric', eta='auto', random_state=42, iterations=1000, per_word_topics=True, eval_every=None) elif self.algo == 'sklearn': ldamodel = LatentDirichletAllocation(n_components=self.num_topics, learning_method='batch', max_iter=20, learning_decay=optim_decay, max_doc_update_iter=1000, n_jobs=-1, random_state=42) lda_output = ldamodel.fit_transform(self.lda_dtm) self.ldamodel = ldamodel