Skip to main content

HDBSCAN Tuning for BERTopic Models

Project description

TopicTuner — Tune BERTopic HDBSCAN Models

To install from PyPi :

pip install topicmodeltuner

The Problem

Out of the box, BERTopic relies upon HDBSCAN to cluster topics. Two of the most important HDBSCAN parameters, min_cluster_size and sample_size will almost always have a dramatic effect on cluster formation. They dictate the number of clusters created including the -1 or uncategorized cluster. While with some datasets a large number of uncategorized documents may be the right clustering, in practice BERTopic will essentially discard a large percentage of "good" documents and not use them for cluster formation and topic formation.

HDBSCAN is quite sensitive to the values of these two parameters relative to the text being clustered. This means that when using the BERTopic default value of min_topic_size=10 (which is assigned to HDBSCAN's min_cluster_size) the default parameters will more often than not result in an unmanageable number of topics; as well as a sub-optimal number of uncategorized documents. Additionally, documents assigned to the -1 category will not be used to determine topic vocabularly results.

The Solution

TopicTuner provides a TopicModelTuner class — a convenience wrapper for BERTopic Models that efficiently manages the process of discovering optimized min_cluster_size and sample_size parameters, providing:

  • Random and grid search functionality to quickly discover optimized parameters for a given BERTopic model.
  • An internal datastore that records all searches for a given model, making parameter selection fast and easy.
  • Visualizations to assist in parameter tuning and selection.
  • Two way Import/Export functionality so that you can start from scratch, or with an existing BERTopic model and export a BERTopic model with optimized parameters at the end of your session.
  • Save and Load for persistance.

To get you started this release includes both a demo notebook and API documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

topicmodeltuner-0.2.1.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

topicmodeltuner-0.2.1-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file topicmodeltuner-0.2.1.tar.gz.

File metadata

  • Download URL: topicmodeltuner-0.2.1.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.15

File hashes

Hashes for topicmodeltuner-0.2.1.tar.gz
Algorithm Hash digest
SHA256 52793e3f949e56185254025f621eaf4fc60dc7bc62b07ba6ca82e55d9ac99042
MD5 299c19c3d23f1893d57450441e91af2c
BLAKE2b-256 3035cfc4d2e76af15c5ef9c092c57b56d936e2703d8d6d5cdcf710dc7940f9de

See more details on using hashes here.

File details

Details for the file topicmodeltuner-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for topicmodeltuner-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 354a43be02625982c7fe59869deb9c2020f3aa0ecb7025ec7689d94d5a3edac8
MD5 e44af4218eda5a52e602a4613602355d
BLAKE2b-256 0259cd3b0435cae8c45242fb2facea825a92519f9d91f99dc83c38892dc201ec

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page