liveBook · Manning

Topic modeling

As explained in Outlier Detection in Python

Topic modeling is an unsupervised technique for inferring recurring semantic topics and their distributions in a collection of documents.

Topic modeling infers recurring topics from a document collection by identifying words that tend to co-occur, then assigns each document scores describing its relationship to each topic. section 9.3.2

Use topic-related features to:

  • Find documents that are unusual because they discuss rarely covered topics. section 9.3.2
  • Identify unusual combinations between topics and other document features. section 9.3.2
  • Cluster strings according to how similarly they cover the discovered topics. section 9.3.3

Interpreting discovered topics

Expense comments containing “dinner,” “restaurant,” and “client” may form one topic, while “taxi,” “cab,” “hotel,” and “plane” may form another. Topic names are inferred from co-occurring words rather than supplied in advance, so results may differ from expected categories. section 9.3.2

Listing 9.10 Using BERTopic with the 20 Newsgroups dataset
from bertopic import BERTopic
from sklearn.datasets import fetch_20newsgroups
 
data = fetch_20newsgroups(subset='all',  
                          remove=('headers', 'footers', 'quotes'))
topic_model = BERTopic()
topics, probs = topic_model.fit_transform(data['data'])

Run BERTopic on the 20 Newsgroups dataset to produce topic assignments and probabilities. section 9.3.2

How Outlier Detection in Python covers it

How deep it goes
Explains co-occurring words, document-topic scores, interpretation limits, and practical tooling without deriving the underlying algorithms.
Examples
Demonstrates expense-comment topics and BERTopic assignments on the 20 Newsgroups dataset.
What it assumes
Assumes a collection of text documents and teaches topic relationships without requiring predefined topic categories.
What you can do after
Apply it via BERTopic to generate topics, document assignments, and topic probabilities for text collections.
How it connects
Connects topic modeling with NLP, outlier detection, clustering, TF-IDF, LDA, and BERT-based processing.

Also explained in

Compare how 2 books explain topic modeling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Outlier Detection in Python. The section links point to the parts of the book it draws on.