MaartenGr / MaartenGr/BERTopic

MLflow Autologging Integration for BERTopic

Open
#2,429 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.8k
Forks
920
Avg merge
22h 24m
Merged PRs (30d)
5

Description

### Feature request

I am currently implementing an autologging integration for BERTopic with MLflow for managing ML experiments. This would automatically log BERTopic's training parameters (e.g., embedding model, UMAP/HDBSCAN settings), metrics, artifacts , and the fitted model via MLflow's PyFunc flavor during `fit_transform` calls. The goal is to simplify experiment tracking in BERTopic workflows without manual logging.

### Motivation

**Approach**: Monkey-patching `BERTopic.fit_transform` using MLflow's `safe_patch` for safe integration.
**What Gets Logged:**
**Parameters:** Embedding model name, UMAP (n_neighbors, n_components, ...), HDBSCAN (min_cluster_size...), vectorizer type
**Metrics:** n_documents, avg_doc_length, n_topics, n_outliers, avg/max/min_topic_size, vocab_size, embedding_dim, diversity, coherence (c_v, c_npmi, u_mass via gensim), per-topic coherence.
Artifacts: topic_info.csv, metrics.json, per_topic_coherence.csv, embeddings.npy and the full model as PyFunc.
**Flavor Support:** Registered as an MLflow flavor (`bertopic`) with `@autologging_integration`enabling mlflow.autolog()

**Mlflow issue** : https://github.com/mlflow/mlflow/issues/16792#issuecomment-3094634324

### Your contribution

Seeking Feedback:

Is this something you would be interested in merging into BERTopic's core as an optional MLflow submodule or would it be better as an external package like mlflow-scikit-learn or mlflow-txtai.

Should I pursue adding this as a separate repo with a lazy import in MLflow's __init__.py via PR or integrate it directly into BERTopic? Pros/cons from your perspective?

I would like to hear your thoughts on this. Thank you!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing BERTopic's fit_transform entry point and the linked MLflow issue about autologging integration. The proposal describes safe_patch, parameter and metric logging, artifact creation, and PyFunc model logging, but does not name files or tests. Done would first require agreement on whether this belongs in BERTopic or an external MLflow package and a defined integration scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.