Beispiel #1
0
    terms.

The model used here is the same as the one deployed on the neuroquery website
( https://neuroquery.saclay.inria.fr ), and this example shows how to easily
reproduce the website's functionality in a Python script.

You can run this example on binder: https://mybinder.org/v2/gh/neuroquery/neuroquery.git/master?filepath=examples
"""

######################################################################
# Download the vocabulary and learned coefficients of a NeuroQuery model
# ----------------------------------------------------------------------

from neuroquery import fetch_neuroquery_model

neuroquery_data = fetch_neuroquery_model()
print(neuroquery_data)

######################################################################
# Load the NeuroQuery model
# -------------------------

from neuroquery import NeuroQueryModel

encoder = NeuroQueryModel.from_data_dir(neuroquery_data)

######################################################################
# Query the model and display the results
# ---------------------------------------

# taken from Wikipedia
Beispiel #2
0
"""
Minimal example: encoding with NeuroQuery
=========================================

The model used here is the same as the one deployed on the neuroquery website
( https://neuroquery.saclay.inria.fr ).
"""
######################################################################
# Encode a query into a statistical map of the brain
# --------------------------------------------------
from neuroquery import fetch_neuroquery_model, NeuroQueryModel
from nilearn.plotting import view_img

encoder = NeuroQueryModel.from_data_dir(fetch_neuroquery_model())

######################################################################
query = """Huntington's disease"""
result = encoder(query)
view_img(result["z_map"], threshold=3.1)

######################################################################
# (drag the mouse on this interactive plot to see other slices)
#
# Note: if you are not using a jupyter notebook, use `.open_in_browser()` to
# open the plot above:

view_img(result["z_map"], threshold=3.1).open_in_browser()

######################################################################
# Display some relevant terms:
from neuroquery.tokenization import get_html_highlighted_text
from nilearn.plotting import plot_img, view_img
import ipywidgets as widgets
from IPython.display import display, display_html, Markdown

import utils

EXAMPLE_QUERY = (
    "Theory of mind is the ability to attribute mental states — beliefs, "
    "intents, desires, emotions, knowledge, etc. — to oneself, and to others, "
    "and to understand that others have beliefs, desires, intentions, and "
    "perspectives that are different from one's own. (from wikipedia)")

# %%capture
encoder = SimpleEncoder.from_data_dir(
    fetch_neuroquery_model(model_name="ensemble_model_2020-02-12"))

query = widgets.Textarea(value=EXAMPLE_QUERY)
button = widgets.Button(description="Run query")
display(widgets.HBox([query, button]))
output = widgets.Output()
display(output)


def run_and_display_query(_):
    result = encoder(query.value)
    with output:
        output.clear_output()
        display_html(get_html_highlighted_text(result["highlighted_text"]),
                     raw=True)
        display_html(view_img(result["brain_map"],