%% 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

%% 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

% Copyright 2021 The MathWorks, Inc.