-1

Please I to visualize my top 25 topics models using a word cloud. I want the subplot to be placed side by side. I have trained the model. The topics contain the trained LDA model.

Below is my code:

from gensim.test.utils import common_texts
from gensim.corpora.dictionary import Dictionary
import gensim
import matplotlib.pyplot as plt
from wordcloud import WordCloud

lda_model = gensim.models.ldamodel.LdaModel(corpus=corpus,
                                           id2word=dictionary,
                                           num_topics=25, #Identifies the 25 topic trends for transportation
                                           random_state=100,
                                           update_every=1,
                                           chunksize=100,
                                           passes=10,
                                           alpha='auto',
                                           per_word_topics=True)


def dsplay_wordcloud(H, W):
  fig, axes = plt.subplots(5, 5, figsize=(30, 15), sharex=True)
  axes = axes.flatten()
  cloud = WordCloud(stopwords=stop_words,
                  background_color='white',
                  # width=2500,
                  # height=1800,
                  # max_words=200,
                  # max_font_size=30
                  prefer_horizontal=0.5
                  )
  for topic_idx, t in enumerate(H):
    ax = axes[topic_idx]
    for t in range(W):
      plt.imshow(cloud.fit_words(dict(lda_model.show_topic(t, 200))))
      plt.axis("off")
      plt.title("Topic Number " + str(t), fontdict = {'fontsize' : 20})
      fig.suptitle('Topic display', fontsize=14, fontweight='bold')

  plt.subplots_adjust(top=0.90, bottom=0.05, wspace=0.90, hspace=0.3)
  plt.show()


dsplay_wordcloud(lda_model, lda_model.num_topics)

Please I need help with this code. Below are the error code

Output and Error code picture.

1 Answers1

0

Change cloud() to cloud. The error is Python saying, "You're trying to call cloud like it's a function, but it's not a function, it's a WordCloud object."

John Kugelman
  • 349,597
  • 67
  • 533
  • 578