0
votes

I'm new to python. What I'm trying to do is to read 2 parameters via console.

  1. parameter:path to a trained LDA model with gensim.
  2. parameter:the number of most common words per topic which I want to get in return.

Now I want to print for all the topics the number of the most common words per topic. Now my question is how to get all the topics.

This is what I have so far:

import sys, getopt
import gensim

def main(argv):
   input_file = argv[0] #LDA Path
   number_of_words = argv[1] #Number of most common word per topic

   ldamodel = gensim.models.ldamodel.LdaModel.load(input_file, mmap=None) #load model
   ldamodel.print_topic(?, number_of_words)



if __name__ == "__main__":
   main(sys.argv[1:])

Gensim doc

Thanks

1
ldamodel.print_topic(10, topn=5) <= with this code you print for 10 topics in your model the top 5 common words. Right? But why to look only at 10 topics..Jürgen K.

1 Answers

0
votes

get_topic_terms does what you want. I think the number of topics is stored in num_topics variable, accessible through ldamodel.num_topics.