| import chromadb |
|
|
| client = chromadb.PersistentClient(path="./my_mastodon_db") |
| collection = client.get_collection(name="mastodon_posts") |
|
|
| |
| print("Fetching all data from ChromaDB...") |
| all_data = collection.get( |
| |
| limit=750000, |
| include=["documents", "embeddings"] |
| ) |
|
|
| documents = all_data['documents'] |
| embeddings = all_data['embeddings'] |
|
|
|
|
|
|
| from bertopic import BERTopic |
|
|
| print("Data fetched. Starting topic modeling...") |
|
|
| |
| topic_model = BERTopic(embedding_model="disable") |
|
|
| |
| |
| |
| |
| topics, probs = topic_model.fit_transform(documents, embeddings) |
|
|
| print("Topic modeling complete!") |
|
|
| |
| |
| print(topic_model.get_topic_info()) |
|
|
| |
| print(topic_model.get_topic(0)) |
|
|
| topic_model.visualize_topics() |
|
|
|
|
|
|
|
|