After training the model, you can run topic modeling on the trained text.
To run topic modeling, use the sample data from the
movies
dataset. The dataset has no target
column. When the output table generates, you can review the
generated word groups and expressions for the trained text.
Complete the following tasks:
-
If not already done, load the model. You can use the session variable for the model that is valid for the duration of the connection. Alternatively, you can use the model handle previously set. For the option to set the user name, you can set it to
NULL
.The following example uses the session variable.
mysql> CALL sys.ML_MODEL_LOAD(@model, NULL);
The following example uses the model handle.
mysql> CALL sys.ML_MODEL_LOAD('topic_modeling_use_case', NULL);
-
Run topic modeling on the dataset by using the
ML_PREDICT_TABLE
routine.mysql> CALL sys.ML_PREDICT_TABLE(table_name, model_handle, output_table_name), [options]);
Replace
table_name
,model_handle
, andoutput_table_name
with your own values. Addoptions
as needed.The following example runs
ML_PREDICT_TABLE
on the dataset previously created.mysql> CALL sys.ML_PREDICT_TABLE('topic_modeling_data.movies', @model, 'topic_modeling_data.topic_modeling_predictions', NULL);
Where:
topic_modeling_data.movies
is the fully qualified name of the input table that contains the data to run topic modeling for (database_name.table_name
).@model
is the session variable for the model handle.topic_modeling_data.topic_modeling_predictions
is the fully qualified name of the output table with generated word groups and expressions (database_name.table_name
).NULL
sets no options for the routine.
-
Query the
ml_results
column from the output table. Review the generated word groups and expressions for the movie descriptions next totags
.mysql> SELECT ml_results FROM topic_modeling_predictions; +-----------------------------------------------------------------------------------------------------------------------------------------+ | ml_results | +-----------------------------------------------------------------------------------------------------------------------------------------+ | {"predictions": {"tags": ["dangerous", "future", "join force", "journey", "warrior", "battle", "rebel", "force", "join", "group"]}} | | {"predictions": {"tags": ["machine", "world", "agent", "group rebel", "human", "real", "real world", "power", "rebel", "fight"]}} | | {"predictions": {"tags": ["family", "empire", "rival", "criminal", "powerful"]}} | | {"predictions": {"tags": ["scientist", "astronaut", "attempt", "humanity", "massive", "work", "earth", "ensure", "power", "survival"]}} | | {"predictions": {"tags": ["include", "mysterious", "strange", "world", "woman", "young woman", "young"]}} | | {"predictions": {"tags": ["empire", "force", "dark force", "evil", "group rebel", "join force", "wise", "battle", "dark", "help"]}} | | {"predictions": {"tags": ["alien", "attempt", "humanity", "planet", "battle", "creature", "ensure", "scientist", "survival", "team"]}} | | {"predictions": {"tags": ["future", "human", "creature", "form", "learn", "secret", "discover", "young"]}} | | {"predictions": {"tags": ["agent", "deal personal", "murder", "personal", "strange", "victim", "form", "help", "deal", "young"]}} | | {"predictions": {"tags": ["wizard", "power", "dark", "learn", "school", "secret", "young", "destroy", "discover", "man"]}} | | {"predictions": {"tags": ["alien", "dangerous", "massive", "mission", "planet", "work", "criminal", "earth", "team", "destroy"]}} | | {"predictions": {"tags": ["murder", "student", "challenge", "help", "school", "face", "woman", "young woman", "young"]}} | | {"predictions": {"tags": ["group", "fall", "friend", "place", "victim", "creature", "survival", "travel", "discover", "fight"]}} | | {"predictions": {"tags": ["fall", "friend", "machine", "secure", "ensure", "scientist", "travel", "deal", "man", "young man"]}} | | {"predictions": {"tags": ["place", "sister", "young", "fight", "woman", "young woman"]}} | | {"predictions": {"tags": ["deal personal", "mysterious", "personal", "secure", "criminal", "powerful", "deal", "group"]}} | | {"predictions": {"tags": ["wizard", "dark force", "evil", "include", "journey", "warrior", "wise", "dark", "powerful", "destroy"]}} | | {"predictions": {"tags": ["family", "sister", "challenge", "deal", "woman", "young woman", "young"]}} | | {"predictions": {"tags": ["astronaut", "mission", "earth", "face", "group"]}} | | {"predictions": {"tags": ["world", "real", "real world", "rival", "challenge", "discover", "face", "join", "man", "young man"]}} | | {"predictions": {"tags": ["student", "form", "learn", "school", "secret", "force", "group"]}} | +-----------------------------------------------------------------------------------------------------------------------------------------+ 21 rows in set (0.0472 sec)
To modify the number of word groups in the ml_results
column, you can set the topk
option. This
option must be an integer greater or equal to one. The
following example uses the same trained table and adds the
option to limit the number of generated word groups to five.
mysql> CALL sys.ML_PREDICT_TABLE('topic_modeling_data.movies', @model, 'topic_modeling_data.topic_modeling_predictions_five', JSON_OBJECT('topk', 5));
Query the ml_results
column to review the
top five generated word groups.
mysql> SELECT ml_results FROM topic_modeling_predictions_five;
+----------------------------------------------------------------------------------------------+
| ml_results |
+----------------------------------------------------------------------------------------------+
| {"predictions": {"tags": ["dangerous", "future", "join force", "journey", "warrior"]}} |
| {"predictions": {"tags": ["machine", "world", "agent", "group rebel", "human"]}} |
| {"predictions": {"tags": ["family", "empire", "rival", "criminal", "powerful"]}} |
| {"predictions": {"tags": ["scientist", "astronaut", "attempt", "humanity", "massive"]}} |
| {"predictions": {"tags": ["include", "mysterious", "strange", "world", "woman"]}} |
| {"predictions": {"tags": ["empire", "force", "dark force", "evil", "group rebel"]}} |
| {"predictions": {"tags": ["alien", "attempt", "humanity", "planet", "battle"]}} |
| {"predictions": {"tags": ["future", "human", "creature", "form", "learn"]}} |
| {"predictions": {"tags": ["agent", "deal personal", "murder", "personal", "strange"]}} |
| {"predictions": {"tags": ["wizard", "power", "dark", "learn", "school"]}} |
| {"predictions": {"tags": ["alien", "dangerous", "massive", "mission", "planet"]}} |
| {"predictions": {"tags": ["murder", "student", "challenge", "help", "school"]}} |
| {"predictions": {"tags": ["group", "fall", "friend", "place", "victim"]}} |
| {"predictions": {"tags": ["fall", "friend", "machine", "secure", "ensure"]}} |
| {"predictions": {"tags": ["place", "sister", "young", "fight", "woman"]}} |
| {"predictions": {"tags": ["deal personal", "mysterious", "personal", "secure", "criminal"]}} |
| {"predictions": {"tags": ["wizard", "dark force", "evil", "include", "journey"]}} |
| {"predictions": {"tags": ["family", "sister", "challenge", "deal", "woman"]}} |
| {"predictions": {"tags": ["astronaut", "mission", "earth", "face", "group"]}} |
| {"predictions": {"tags": ["world", "real", "real world", "rival", "challenge"]}} |
| {"predictions": {"tags": ["student", "form", "learn", "school", "secret"]}} |
+----------------------------------------------------------------------------------------------+
21 rows in set (0.0475 sec)
To learn more about generating predictions for one or more rows of data, see Generate Predictions for a Row of Data.
Review other Machine Learning Use Cases.