Train an LDA model and use it

This example trains a latent Dirichlet allocation with MALLET using abstracts from Neurosynth.

Start with the necessary imports

import os

import nimare
from nimare import annotate
from nimare.tests.utils import get_test_data_path

Load dataset with abstracts

dset = nimare.dataset.Dataset.load(
    os.path.join(get_test_data_path(), 'neurosynth_laird_studies.pkl.gz'))

Download MALLET

LDAModel will do this automatically.

mallet_dir = nimare.extract.download_mallet()

Run model

Five iterations will take ~10 minutes

model = annotate.topic.LDAModel(dset.texts, text_column='abstract', n_iters=5)
model.fit()
model.save('lda_model.pkl.gz')

Total running time of the script: ( 0 minutes 0.000 seconds)

Gallery generated by Sphinx-Gallery