Graph-based topic modeling built on semantic graphs.
GraphTopic is a Python library for discovering document topics using graph-based community detection instead of traditional clustering algorithms.
It is built on top of Graphion, a modular graph processing framework, allowing every stage of the topic modeling pipeline to be customized.
- Graph-based topic discovery
- Pluggable embedding models
- Pluggable graph construction
- Pluggable community detection
- Pluggable topic representation
- Simple sklearn-like API
- Built on Graphion
Install the core library:
pip install graphtopicTo use the built-in SentenceTransformer embedding model:
pip install "graphtopic[embedding]"from graphtopic import GraphTopic
from graphtopic.embedding_models import (
SentenceTransformerEmbedding,
)
documents = [
"Apple released a new iPhone.",
"Samsung announced a new Galaxy phone.",
"Barcelona won the football match.",
"Real Madrid signed a new player.",
]
model = GraphTopic(
embedding_model=SentenceTransformerEmbedding(
"sentence-transformers/all-MiniLM-L6-v2"
)
)
topics = model.fit_transform(documents)
for topic in model.get_topic_info():
print(topic)GraphTopic follows a modular processing pipeline:
Documents
↓
Embeddings
↓
FeatureSet
↓
Relation Graph
↓
Community Detection
↓
Topic Representation
↓
Topic Information
Each stage can be replaced with custom implementations.
GraphTopic is designed around interchangeable components.
You can replace:
- Embedding Model
- Reducer
- Relation Builder
- Graph Builder
- Graph Refiner
- Community Detector
- Partition Refiner
- Representation Model
This makes it easy to experiment with different graph construction and topic discovery strategies.
GraphTopic uses Graphion as its graph processing backend.
Graphion provides reusable components for:
- similarity computation
- graph construction
- graph refinement
- community detection
- graph processing pipelines
GraphTopic focuses only on topic modeling while delegating graph operations to Graphion.
- Python 3.11+
- NumPy
- scikit-learn
- Graphion
GraphTopic is currently in Pre-Alpha (0.0.x).
The public API is expected to evolve as new functionality is added.
MIT License