Path: blob/master/4-Topic-Modeling.ipynb
164 views
Topic Modeling
Introduction
Another popular text analysis technique is called topic modeling. The ultimate goal of topic modeling is to find various topics that are present in your corpus. Each document in the corpus will be made up of at least one topic, if not multiple topics.
In this notebook, we will be covering the steps on how to do Latent Dirichlet Allocation (LDA), which is one of many topic modeling techniques. It was specifically designed for text data.
To use a topic modeling technique, you need to provide (1) a document-term matrix and (2) the number of topics you would like the algorithm to pick up.
Once the topic modeling technique is applied, your job as a human is to interpret the results and see if the mix of words in each topic make sense. If they don't make sense, you can try changing up the number of topics, the terms in the document-term matrix, model parameters, or even try a different model.
Topic Modeling - Attempt #1 (All Text)
Now that we have the corpus (term-document matrix) and id2word (dictionary of location: term), we need to specify two other parameters - the number of topics and the number of passes. Let's start the number of topics at 2, see if the results make sense, and increase the number from there.
These topics aren't looking too great. We've tried modifying our parameters. Let's try modifying our terms list as well.
Topic Modeling - Attempt #2 (Nouns Only)
One popular trick is to look only at terms that are from one part of speech (only nouns, only adjectives, etc.). Check out the UPenn tag set: https://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html.
Topic Modeling - Attempt #3 (Nouns and Adjectives)
Identify Topics in Each Document
Out of the 9 topic models we looked at, the nouns and adjectives, 4 topic one made the most sense. So let's pull that down here and run it through some more iterations to get more fine-tuned topics.
These four topics look pretty decent. Let's settle on these for now.
Topic 0: mom, parents
Topic 1: husband, wife
Topic 2: guns
Topic 3: profanity
For a first pass of LDA, these kind of make sense to me, so we'll call it a day for now.
Topic 0: mom, parents [Anthony, Hasan, Louis, Ricky]
Topic 1: husband, wife [Ali, John, Mike]
Topic 2: guns [Bill, Bo, Jim]
Topic 3: profanity [Dave, Joe]
Additional Exercises
Try further modifying the parameters of the topic models above and see if you can get better topics.
Create a new topic model that includes terms from a different part of speech and see if you can get better topics.