LDA topic modeling

Trains a latent Dirichlet allocation model with scikit-learn using abstracts from Neurosynth.

import os

import pandas as pd

from nimare import annotate
from nimare.dataset import Dataset
from nimare.utils import get_resource_path

Load dataset with abstracts

dset = Dataset(os.path.join(get_resource_path(), "neurosynth_laird_studies.json"))

Initialize LDA model

model = annotate.lda.LDAModel(n_topics=5, max_iter=1000, text_column="abstract")

Run model

new_dset = model.fit(dset)

View results

This DataFrame is very large, so we will only show a slice of it.

id study_id contrast_id Neurosynth_TFIDF__001 Neurosynth_TFIDF__01 Neurosynth_TFIDF__05 Neurosynth_TFIDF__10 Neurosynth_TFIDF__100 Neurosynth_TFIDF__11 Neurosynth_TFIDF__12
0 17029760-1 17029760 1 0.0 0.0 0.0 0.000000 0.0 0.000000 0.0
1 18760263-1 18760263 1 0.0 0.0 0.0 0.000000 0.0 0.000000 0.0
2 19162389-1 19162389 1 0.0 0.0 0.0 0.000000 0.0 0.176321 0.0
3 19603407-1 19603407 1 0.0 0.0 0.0 0.000000 0.0 0.000000 0.0
4 20197097-1 20197097 1 0.0 0.0 0.0 0.000000 0.0 0.000000 0.0
5 22569543-1 22569543 1 0.0 0.0 0.0 0.000000 0.0 0.000000 0.0
6 22659444-1 22659444 1 0.0 0.0 0.0 0.000000 0.0 0.000000 0.0
7 23042731-1 23042731 1 0.0 0.0 0.0 0.000000 0.0 0.000000 0.0
8 23702412-1 23702412 1 0.0 0.0 0.0 0.061006 0.0 0.000000 0.0
9 24681401-1 24681401 1 0.0 0.0 0.0 0.000000 0.0 0.000000 0.0


Given that this DataFrame is very wide (many terms), we will transpose it before presenting it.

model.distributions_["p_topic_g_word_df"].T.head(10)
LDA5__1_human_functional_frontal LDA5__2_connectivity_functional_anterior LDA5__3_cortex_motor_network LDA5__4_connectivity_cognitive_identified LDA5__5_social_functional_connectivity
10 2.001000 0.001000 0.001000 0.001000 0.001000
abstract 0.001000 0.001000 0.001000 1.000975 1.001025
action 1.001168 1.000832 0.001000 0.001000 0.001000
active 0.001000 1.000409 2.001721 1.000871 0.001000
addition 0.001000 1.000148 1.000922 3.001929 0.001000
additionally 2.001000 0.001000 0.001000 0.001000 0.001000
affective 2.742754 1.258777 0.001000 0.001000 2.001469
affective processes 0.001000 2.001000 0.001000 0.001000 0.001000
ale 0.001000 0.001000 0.001000 1.000873 1.001127
altered 0.001000 0.001000 0.001000 0.001000 4.001000


LDA5__1_human_functional_frontal LDA5__2_connectivity_functional_anterior LDA5__3_cortex_motor_network LDA5__4_connectivity_cognitive_identified LDA5__5_social_functional_connectivity
Token
0 human connectivity cortex connectivity social
1 functional functional motor cognitive functional
2 frontal anterior network identified connectivity
3 maps macm control stimulation altered
4 cortex functional connectivity lateral literature structural
5 lateral posterior prefrontal talairach function
6 medial seed prefrontal cortex error indicate
7 cognitive approaches parietal functional modeling
8 memory networks cognition published network
9 frontal pole connections cortices functions analytic


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

Gallery generated by Sphinx-Gallery