How to access topic words only in gensim
I think the below code snippet should give you a list of tuples containing the each topic(tp) and corresponding list of words(wd) in that topic
x=ldamodel.show_topics(num_topics=12, num_words=5,formatted=False)
topics_words = [(tp[0], [wd[0] for wd in tp[1]]) for tp in x]
#Below Code Prints Topics and Words
for topic,words in topics_words:
print(str(topic)+ "::"+ str(words))
print()
#Below Code Prints Only Words
for topic,words in topics_words:
print(" ".join(words))
The other answer was giving a string with weights associated with each word. But if you want to get each word in a topic separately for further work. Then you can try this. Here topic no is the key to the dictionary and the value is a single string containing all words in that topic separated by space
x=ldamodel.show_topics()
twords={}
for topic,word in x:
twords[topic]=re.sub('[^A-Za-z ]+', '', word)
print(twords)