Main Content

Visualize LDA Topics Using Word Clouds

This example shows how to visualize the words in Latent Dirichlet Allocation (LDA) model topics.

A latent Dirichlet allocation (LDA) model is a topic model which discovers underlying topics in a collection of documents and infers word probabilities in topics. You can visualize the LDA topics using word clouds by displaying words with their corresponding topic word probabilities.

Load LDA Model

Load the LDA model factoryReportsLDAModel which is trained using a data set of factory reports detailing different failure events. For an example showing how to fit an LDA model to a collection of text data, see Analyze Text Data Using Topic Models.

load factoryReportsLDAModel
mdl
mdl = 
  ldaModel with properties:

                     NumTopics: 7
             WordConcentration: 1
            TopicConcentration: 0.5755
      CorpusTopicProbabilities: [0.1587 0.1573 0.1551 0.1534 0.1340 ... ]
    DocumentTopicProbabilities: [480x7 double]
        TopicWordProbabilities: [158x7 double]
                    Vocabulary: ["item"    "occasionally"    "get"    ...    ]
                    TopicOrder: 'initial-fit-probability'
                       FitInfo: [1x1 struct]

Visualize Topics Using Word Clouds

Visualize the topics using the wordcloud function.

numTopics = mdl.NumTopics;

figure
t = tiledlayout("flow");
title(t,"LDA Topics")

for i = 1:numTopics
    nexttile
    wordcloud(mdl,i);
    title("Topic " + i)
end

Figure contains objects of type wordcloud. The chart of type wordcloud has title Topic 1. The chart of type wordcloud has title Topic 2. The chart of type wordcloud has title Topic 3. The chart of type wordcloud has title Topic 4. The chart of type wordcloud has title Topic 5. The chart of type wordcloud has title Topic 6. The chart of type wordcloud has title Topic 7.

See Also

| | |

Related Topics