Visualizing topics from BERTopic
In this recipe, we will create and visualize a BERTopic model on the BBC data. There are several visualizations available with the BERTopic package, and we will use several of them.
In this recipe, we will create a topic model in a similar fashion as in Chapter 6, in the Topic modeling using BERTopic recipe. However, unlike in Chapter 6, we will not limit the number of topics created, and resulting in more than the 5 original topics in the data. It will allow for more interesting visualizations.
Getting ready
We will use the BERTopic
package to create the visualization. It is available in the poetry
environment.
How to do it...
- Import the necessary packages and functions:
import pandas as pd import numpy as np from bertopic import BERTopic from bertopic.representation import KeyBERTInspired
- Run the language utilities file:
%run -i "../util/lang_utils.ipynb"
- Read in the data:
bbc_df = pd.read_csv("../data/bbc-text...