Skip to content

centre-for-humanities-computing/tweetopic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

5ada7b8 Β· Jun 6, 2024
Jun 5, 2024
Jun 5, 2024
Jun 5, 2024
Jun 5, 2024
Sep 5, 2022
May 28, 2023
Sep 5, 2022
Aug 30, 2022
Jun 6, 2024
May 27, 2023
Jun 10, 2023
Jun 5, 2024

Repository files navigation

tweetopic

⚑ Blazing Fast topic modelling over short texts in Python

PyPI version pip downloads python version Code style: black

Features

  • Fast ⚑
  • Scalable πŸ’₯
  • High consistency and coherence 🎯
  • High quality topics πŸ”₯
  • Easy visualization and inspection πŸ‘€
  • Full scikit-learn compatibility πŸ”©

New in version 0.4.0 ✨

You can now pass random_state to topic models to make your results reproducible.

from tweetopic import DMM

model = DMM(10, random_state=42)

πŸ›  Installation

Install from PyPI:

pip install tweetopic

πŸ‘©β€πŸ’» Usage (documentation)

Train your a topic model on a corpus of short texts:

from tweetopic import DMM
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.pipeline import Pipeline

# Creating a vectorizer for extracting document-term matrix from the
# text corpus.
vectorizer = CountVectorizer(min_df=15, max_df=0.1)

# Creating a Dirichlet Multinomial Mixture Model with 30 components
dmm = DMM(n_components=30, n_iterations=100, alpha=0.1, beta=0.1)

# Creating topic pipeline
pipeline = Pipeline([
    ("vectorizer", vectorizer),
    ("dmm", dmm),
])

You may fit the model with a stream of short texts:

pipeline.fit(texts)

To investigate internal structure of topics and their relations to words and indicidual documents we recommend using topicwizard.

Install it from PyPI:

pip install topic-wizard

Then visualize your topic model:

import topicwizard

topicwizard.visualize(pipeline=pipeline, corpus=texts)

topicwizard visualization

πŸŽ“ References

  • Yin, J., & Wang, J. (2014). A Dirichlet Multinomial Mixture Model-Based Approach for Short Text Clustering. In Proceedings of the 20th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (pp. 233–242). Association for Computing Machinery.