Topic Modelling with BERTtopic in Python | by Petr Korab | Apr, 2024

Hands-on tutorial on modeling political statements with a -based topic

Petr Korab
Towards Data Science
Photo by Harryarts on Freepik

(i.e., topic identification in a corpus of text data) has developed quickly since the Latent Dirichlet Allocation (LDA) model was published. This classic topic model, however, does not well capture the between words because it is based on the statistical concept of a bag of words. Recent embedding-based Top2Vec and BERTopic address its drawbacks by exploiting pre-trained language models to generate topics.

In this article, we’ll use Maarten Grootendorst’s (2022) BERTopic to identify the terms representing topics in political speech transcripts. It outperforms most traditional and modern topic models in topic modeling metrics on various corpora and has been used in companies, academia (Chagnon, 2024), and the sector. We’ll explore in Python code:

  • how to effectively preprocess data
  • how to create a Bigram topic model
  • how to explore the most frequent terms over .

As an example , we’ll use the Empoliticon: Political Speeches- & Emotion dataset, released under the…

Source link