Package: tmtoolkit
tmtoolkitis 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’smultiprocessingmodule and thelokypackage). The basis of tmtoolkit’s text mining capabilities are built aroundSpaCy, which offersmany language models.The documentation for tmtoolkit is available ontmtoolkit.readthedocs.organd
the GitHub code repository is ongithub.com/internaut/tmtoolkit.Requirements and installationtmtoolkit works with Python 3.8 or newer (tested up to Python 3.11).NoteThere are two dependencies, that don’t work with Python 3.11 so far:ldaandwordcloud. If you want to
do topic modeling via LDA and/or want to use word cloud visualizations, you must use Python 3.8 to 3.10 or
wait until lda and wordcloud receive updates that make them work under 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 theinstallation section in the documentation. For short,
the recommended way of installing tmtoolkit is to create and activate aPython 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,deAgain, you should have a look at the detailedinstallation instructionsin order to install additional
packages that enable more features such as topic modeling.FeaturesText preprocessingThe 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)lemmatization and token normalizationextensivepattern 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 forkeywords-in-context (KWIC)adding and managingcustom document and token attributesaccessing text corpora along with theirdocument and token attributes as dataframescalculating andvisualizing corpus summary statisticsfinding out and joiningcollocationscalculatingtoken cooccurrencessplitting and sampling corporageneratingn-gramsand usingN-gram modelsgeneratingsparse document-term matricesWherever possible and useful, these methods can operate in parallel to speed up computations with large datasets.Topic modelingmodel computation in parallelfor different copora
and/or parameter setssupport forlda,scikit-learnandgensimtopic modeling backendsevaluation 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 withmetrics 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 gensimplotting of evaluation resultscommon statistics for topic modelssuch as
word saliency and distinctiveness (Chuang et al. 2012), topic-word
relevance (Sievert and Shirley 2014)finding / filtering topics with pattern matchingexport estimated document-topic and topic-word distributions to Excelvisualize topic-word distributions and document-topic distributionsas word clouds or heatmapsmodel coherence (Mimno et al. 2011) for individual topicsintegratePyLDAVisto visualize resultsOther featuresloading and cleaning of raw text fromtext files, tabular files (CSV or Excel), ZIP files or folderssplitting and joining documentscommon statistics and transformations for document-term matriceslike word cooccurrence andtf-idfinteroperability with RLimitsall languages are supported, for whichSpaCy language modelsare availableall data must reside in memory, i.e. no streaming of large data from the hard disk (which for exampleGensimsupports)ContributeIf you’d like to contribute, please read thedeveloper documentationfirst.LicenseCode licensed underApache License 2.0.
SeeLICENSEfile.