generated from csinva/cookiecutter-ml-research
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
738 additions
and
530 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
202 changes: 202 additions & 0 deletions
202
notebooks_stories/2_analyze_pilot/01_check_alignment.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[2023-11-21 15:15:00,370] [INFO] [real_accelerator.py:158:get_accelerator] Setting ds_accelerator to cuda (auto detect)\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"/home/chansingh/imodelsx/.venv/lib/python3.11/site-packages/thinc/compat.py:36: UserWarning: 'has_mps' is deprecated, please use 'torch.backends.mps.is_built()'\n", | ||
" hasattr(torch, \"has_mps\")\n", | ||
"/home/chansingh/imodelsx/.venv/lib/python3.11/site-packages/thinc/compat.py:37: UserWarning: 'has_mps' is deprecated, please use 'torch.backends.mps.is_built()'\n", | ||
" and torch.has_mps # type: ignore[attr-defined]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%load_ext autoreload\n", | ||
"%autoreload 2\n", | ||
"import os\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import seaborn as sns\n", | ||
"from os.path import join\n", | ||
"from tqdm import tqdm\n", | ||
"import pandas as pd\n", | ||
"import sys\n", | ||
"import joblib\n", | ||
"from scipy.special import softmax\n", | ||
"import sasc.config\n", | ||
"import numpy as np\n", | ||
"from collections import defaultdict\n", | ||
"from copy import deepcopy\n", | ||
"import pandas as pd\n", | ||
"import sasc.viz\n", | ||
"from sasc import analyze_helper\n", | ||
"from sasc.modules.fmri_module import convert_module_num_to_voxel_num\n", | ||
"from sasc.config import FMRI_DIR, RESULTS_DIR\n", | ||
"import dvu\n", | ||
"dvu.set_style()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Load pilot pickle" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"stories_data_dict = joblib.load(\n", | ||
" join(sasc.config.RESULTS_DIR, 'pilot_story_data.pkl'))\n", | ||
"pilot_data_dir = '/home/chansingh/mntv1/deep-fMRI/story_data/20230504'\n", | ||
"\n", | ||
"# stories_data_dict = joblib.load(\n", | ||
"# join(sasc.config.RESULTS_DIR, 'pilot3_story_data.pkl'))\n", | ||
"# pilot_data_dir = '/home/chansingh/mntv1/deep-fMRI/story_data/20231106'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Read all the info from stories into a single pickle file" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
" 0%| | 0/6 [00:00<?, ?it/s]" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"100%|██████████| 6/6 [00:29<00:00, 5.00s/it]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# load responses\n", | ||
"default_story_idxs = np.where(\n", | ||
" np.array(stories_data_dict['story_setting']) == 'default')[0]\n", | ||
"resp_np_files = [stories_data_dict['story_name_new'][i].replace('_resps', '')\n", | ||
" for i in default_story_idxs]\n", | ||
"resps_dict = {\n", | ||
" k: np.load(join(pilot_data_dir, k))\n", | ||
" for k in tqdm(resp_np_files)\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Let's check the alignment" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"timings_list = stories_data_dict['timing']\n", | ||
"story_names_list = list(resps_dict.keys())\n", | ||
"resps = list(resps_dict.values())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 20, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"GenStory1.npy resp_length 435 story_trs 445 story_length 890.2769680636738\n", | ||
"GenStory2.npy resp_length 382 story_trs 392 story_length 784.0274450678589\n", | ||
"GenStory3.npy resp_length 322 story_trs 331 story_length 663.8185519243381\n", | ||
"GenStory4.npy resp_length 405 story_trs 415 story_length 830.2452811179473\n", | ||
"GenStory5.npy resp_length 407 story_trs 417 story_length 834.1917651885974\n", | ||
"GenStory6.npy resp_length 470 story_trs 480 story_length 960.9583298519948\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"TRIM = 5\n", | ||
"for i in range(len(resps)):\n", | ||
" t = timings_list[i]\n", | ||
" duration_secs = t['time_running'].max()\n", | ||
" print(story_names_list[i], 'resp_length',\n", | ||
" resps[i].shape[0], 'story_trs',\n", | ||
" int(duration_secs // 2), 'story_length', duration_secs) # , 'timings',\n", | ||
" diff = int(duration_secs // 2) - resps[i].shape[0]\n", | ||
" assert abs(diff - TRIM * 2) <= 1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Let's check the paragraph<>timing match" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".llm", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.6" | ||
}, | ||
"orig_nbformat": 4, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "a9ff692d44ea03fd8a03facee7621117bbbb82def09bacaacf0a2cbc238b7b91" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.