Text Mining and Topic Modeling Toolkit
Project description
tmtoolkit is a set of tools for text mining and topic modeling with Python developed especially for the use in the social sciences, linguistics, journalism or related disciplines. 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 and the loky package). The basis of tmtoolkit’s text mining capabilities are built around SpaCy, which offers many language models.
The documentation for tmtoolkit is available on tmtoolkit.readthedocs.org and the GitHub code repository is on github.com/internaut/tmtoolkit.
Requirements and installation
tmtoolkit works with Python 3.8 or newer (tested up to Python 3.11).
The tmtoolkit package is highly modular and tries to install as few dependencies as possible. For requirements and installation procedures, please have a look at the installation section in the documentation. For short, the recommended way of installing tmtoolkit is to create and activate a Python Virtual Environment (“venv”) and then install tmtoolkit with a recommended set of dependencies and a list of language models via the following:
pip install -U "tmtoolkit[recommended]"
# add or remove language codes in the list for installing the models that you need;
# don't use spaces in the list of languages
python -m tmtoolkit setup en,de
Again, you should have a look at the detailed installation instructions in order to install additional packages that enable more features such as topic modeling.
Features
Text preprocessing
The tmtoolkit package offers several text preprocessing and text mining methods, including:
tokenization, sentence segmentation, part-of-speech (POS) tagging, named-entity recognition (NER) (via SpaCy)
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 or document level, or for keywords-in-context (KWIC)
adding and managing custom document and token attributes
accessing text corpora along with their document and token attributes as dataframes
calculating and visualizing corpus summary statistics
finding out and joining collocations
calculating token cooccurrences
generating n-grams and using N-gram models
generating sparse document-term matrices
Wherever possible and useful, these 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
common statistics for topic models such as word saliency and distinctiveness (Chuang et al. 2012), topic-word relevance (Sievert and Shirley 2014)
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
Limits
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)
Contribute
If you’d like to contribute, please read the developer documentation first.
License
Code licensed under Apache License 2.0. See LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tmtoolkit-0.12.0.tar.gz
.
File metadata
- Download URL: tmtoolkit-0.12.0.tar.gz
- Upload date:
- Size: 12.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6df5429cd675989f21d9f075ddb11fe5ae273d6544fc337a2589bab2bc331909 |
|
MD5 | b76a64cc1c3edd65d57c662875641569 |
|
BLAKE2b-256 | 3299488fa98f68711ea337e2659c51d54860cd79e499263dbd49f22696dd8067 |
File details
Details for the file tmtoolkit-0.12.0-py3-none-any.whl
.
File metadata
- Download URL: tmtoolkit-0.12.0-py3-none-any.whl
- Upload date:
- Size: 10.5 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f18c68ef0676377714a6fe87d1822903f3c3493cc64437d1da7964ec3f68b2b5 |
|
MD5 | 206592e2a6f0cc855d63f46d8698ff78 |
|
BLAKE2b-256 | 59998193f25605b747177322c7f07f194a090a80ef6f1e66cb347d96aa9f51da |