Installation

Requirements

tmtoolkit works with Python 3.6, 3.7 or 3.8.

Requirements are automatically installed via pip as described below. Additional packages can also be installed via pip for certain use cases (see Optional packages).

Note

A special note for Windows users: tmtoolkit has been tested on Windows and works well (I recommend using the Anaconda distribution for Python when using Windows). However, you will need to wrap all code that uses multi-processing (i.e. all calls to tmtoolkit.preprocess.TMPreproc and the parallel topic modeling functions) in a if __name__ == '__main__' block like this:

def main():
    # code with multi-processing comes here
    # ...

if __name__ == '__main__':
    main()

Installation instructions

The package tmtoolkit is available on PyPI and can be installed via Python package manager pip. It is highly recommended to install tmtoolkit and its dependencies in a Python Virtual Environment (“venv”) and upgrade to the latest pip version (you may also choose to install virtualenvwrapper, which makes managing venvs a lot easier).

Creating and activating a venv without virtualenvwrapper:

python3 -m venv myenv

# activating the environment (on Windows type "myenv\Scripts\activate.bat")
source myenv/bin/activate

Alternatively, creating and activating a venv with virtualenvwrapper:

mkvirtualenv myenv

# activating the environment
workon myenv

Upgrading pip (only do this when you’ve activated your venv):

pip install -U pip

Now in order to install tmtoolkit, you can choose if you want a minimal installation or install a recommended set of packages that enable most features. For the recommended installation, you can type one of the following, depending on the preferred package for topic modeling:

# recommended installation without topic modeling
pip install -U "tmtoolkit[recommended]"

# recommended installation with "lda" for topic modeling
pip install -U "tmtoolkit[recommended,lda]"

# recommended installation with "scikit-learn" for topic modeling
pip install -U "tmtoolkit[recommended,sklearn]"

# recommended installation with "gensim" for topic modeling
pip install -U "tmtoolkit[recommended,gensim]"

# you may also select several topic modeling packages
pip install -U "tmtoolkit[recommended,lda,sklearn,gensim]"

For the minimal installation, you can just do:

pip install -U tmtoolkit

Note

For Linux and MacOS users, it’s also recommended to install the datatable package (see Optional packages), which makes many operations faster and more memory efficient.

Note

The tmtoolkit package is about 7MB big, because it contains some example corpora.

After that, you should initially run tmtoolkit’s setup routine. This makes sure that all required data files are present and downloads them if necessary. You should specify a list of languages for which language models should be downloaded and installed. The list of available language models corresponds with the models provided by SpaCy (except for “multi-language”). Specify the two-letter ISO language code for the language models that you want to install:

python -m tmtoolkit setup en,de

To install all available language models, you can run:

python -m tmtoolkit setup all

Optional packages

For additional features, you can install further packages from PyPI via pip:

  • for faster tabular data creation and access (replaces usage of pandas package in most functions): datatable; note that datatable is currently only available for Linux and MacOS

  • for the word cloud functions: wordcloud and Pillow

  • for Excel export: openpyxl

  • for topic modeling, one of the LDA implementations: lda, scikit-learn or gensim

  • for additional topic model coherence metrics: gensim

  • for stemming: nltk

For LDA evaluation metrics griffiths_2004 and held_out_documents_wallach09 it is necessary to install gmpy2 for multiple-precision arithmetic. This in turn requires installing some C header libraries for GMP, MPFR and MPC. On Debian/Ubuntu systems this is done with:

sudo apt install libgmp-dev libmpfr-dev libmpc-dev

After that, gmpy2 can be installed via pip.