Text Mining and Topic Modeling Toolkit for Python with parallel processing power





GitHub Stars



Last Commit

1yr ago







Apache License 2.0



tmtoolkit: Text mining and topic modeling toolkit

|pypi| |pypi_downloads| |rtd| |travis| |coverage| |zenodo|

tmtoolkit is a set of tools for text mining and topic modeling with Python developed especially for the use in the social sciences. It aims for easy installation, extensive documentation and a clear programming interface while offering good performance on large datasets by the means of vectorized operations (via NumPy) and parallel computation (using Python's multiprocessing module). It combines several known and well-tested packages such as SpaCy <> and SciPy <>.

At the moment, tmtoolkit focuses on methods around the Bag-of-words model, but word vectors (word embeddings) can also be generated.

The documentation for tmtoolkit is available on <> and the GitHub code repository is on <>.


Text preprocessing ^^^^^^^^^^^^^^^^^^

tmtoolkit implements or provides convenient wrappers for several preprocessing methods, including:

  • tokenization and part-of-speech (POS) tagging <>_ (via SpaCy)
  • lemmatization and term normalization <>_
  • extensive pattern matching capabilities <> (exact matching, regular expressions or "glob" patterns) to be used in many methods of the package, e.g. for filtering on token, document or document label level, or for keywords-in-context (KWIC) <#Keywords-in-context-(KWIC)-and-general-filtering-methods>
  • adding and managing custom token metadata <>_
  • accessing word vectors (word embeddings) <,-vocabulary-and-other-important-properties>_
  • generating n-grams <>_
  • generating sparse document-term matrices <>_
  • expanding compound words and "gluing" of specified subsequent tokens <>_, e.g. ["White", "House"] becomes ["White_House"]

All text preprocessing methods can operate in parallel to speed up computations with large datasets.

Topic modeling ^^^^^^^^^^^^^^

  • model computation in parallel <>_ for different copora and/or parameter sets

  • support for lda <>, scikit-learn <> and gensim <>_ topic modeling backends

  • evaluation of topic models <>_ (e.g. in order to an optimal number of topics for a given dataset) using several implemented metrics:

    • model coherence (Mimno et al. 2011 <>) or with metrics implemented in Gensim <>)
    • KL divergence method (Arun et al. 2010 <>_)
    • probability of held-out documents (Wallach et al. 2009 <>_)
    • pair-wise cosine distance method (Cao Juan et al. 2009 <>_)
    • harmonic mean method (Griffiths, Steyvers 2004 <>_)
    • the loglikelihood or perplexity methods natively implemented in lda, sklearn or gensim
  • plotting of evaluation results <>_

  • common statistics for topic models <> such as word saliency and distinctiveness (Chuang et al. 2012 <>), topic-word relevance (Sievert and Shirley 2014 <>_)

  • finding / filtering topics with pattern matching <>_

  • export estimated document-topic and topic-word distributions to Excel <>_

  • visualize topic-word distributions and document-topic distributions <>_ as word clouds or heatmaps

  • model coherence (Mimno et al. 2011 <>_) for individual topics

  • integrate PyLDAVis <>_ to visualize results

Other features ^^^^^^^^^^^^^^

  • loading and cleaning of raw text from text files, tabular files (CSV or Excel), ZIP files or folders <>_
  • common statistics and transformations for document-term matrices <>_ like word cooccurrence and tf-idf


  • all languages are supported, for which SpaCy language models <>_ are available
  • all data must reside in memory, i.e. no streaming of large data from the hard disk (which for example Gensim <>_ supports)

Requirements and installation

For requirements and installation procedures, please have a look at the installation section in the documentation <>_.


Code licensed under Apache License 2.0 <>. See LICENSE <> file.

.. |pypi| image:: :target: :alt: PyPI Version

.. |pypi_downloads| image:: :target: :alt: Downloads from PyPI

.. |travis| image:: :target: :alt: Travis CI Build Status

.. |coverage| image:: :target: :alt: Coverage status

.. |rtd| image:: :target: :alt: Documentation Status

.. |zenodo| image:: :target: :alt: Citable Zenodo DOI

Rate & Review

Great Documentation0
Easy to Use0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Unwelcoming Community0