Datasets:
File size: 7,988 Bytes
156ed8c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import pickle\n",
"from const import *\n",
"import pandas as pd\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"SCIDMT_PATH = {\n",
" 'DICT': './SciDMT/SciDMT_dict.json',\n",
"\n",
" # machine learning inputs at sentence level\n",
" 'sent_xy': './SciDMT/SciDMT_sentences.p', \n",
" 'sent_eval': './SciDMT/SciDMT_E_sentences.json',\n",
" 'sent_split': './SciDMT/SciDMT_sentences_split.json',\n",
"\n",
" # document level inputs\n",
" 'doc_split': './SciDMT/SciDMT_split.json',\n",
" 'doc_eval': './SciDMT/SciDMT_E_human_annotations.json',\n",
" 'doc_text_and_meta': './SciDMT/SciDMT_papers.csv',\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def print_dict_structure(d, indent=0, indent_str=' '):\n",
" for key, value in d.items():\n",
" print(indent_str * indent + ' ' +str(key))\n",
" if isinstance(value, dict):\n",
" print_dict_structure(value, indent+1)\n",
" else:\n",
" if type(value) == list:\n",
" des = f'| len={len(value)} | first 3 entries={value[:3]}'\n",
" else:\n",
" des = ''\n",
" print(indent_str * (indent+1) + ' ' + str(type(value)) + des)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"dict_keys(['datasets', 'methods', 'tasks'])\n"
]
}
],
"source": [
"# Load SciDMT dictionary for entities\n",
"DICT = json.load(open(SCIDMT_PATH['DICT'], 'r'))\n",
"print(DICT.keys())"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Load SciDMT evaluation set in sentence level\n",
"scidmt_e = pd.read_json(SCIDMT_PATH['sent_eval'])\n",
"\n",
"# load x_test, y_test\n",
"X_test, y_test = scidmt_e['X'].to_list(), scidmt_e['y'].to_list()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" is_contain\n",
" datasets\n",
" <class 'list'>| len=48049 | first 3 entries=[True, False, True]\n",
" tasks\n",
" <class 'list'>| len=48049 | first 3 entries=[True, True, True]\n",
" methods\n",
" <class 'list'>| len=48049 | first 3 entries=[True, True, True]\n",
" all\n",
" <class 'list'>| len=48049 | first 3 entries=[True, True, True]\n",
" is_test\n",
" datasets\n",
" <class 'list'>| len=48049 | first 3 entries=[False, False, False]\n",
" tasks\n",
" <class 'list'>| len=48049 | first 3 entries=[True, False, False]\n",
" methods\n",
" <class 'list'>| len=48049 | first 3 entries=[False, True, False]\n",
" all\n",
" <class 'list'>| len=48049 | first 3 entries=[False, False, False]\n",
" doc_pids\n",
" <class 'list'>| len=48049 | first 3 entries=[51881821, 51881855, 51881912]\n",
" is_0shot\n",
" datasets\n",
" <class 'list'>| len=48049 | first 3 entries=[False, False, False]\n",
" methods\n",
" <class 'list'>| len=48049 | first 3 entries=[False, False, False]\n",
" tasks\n",
" <class 'list'>| len=48049 | first 3 entries=[False, False, False]\n",
" all\n",
" <class 'list'>| len=48049 | first 3 entries=[False, False, False]\n",
" SHOT0\n",
" datasets\n",
" entity_indexs\n",
" <class 'list'>| len=10 | first 3 entries=[1561, 2889, 2810]\n",
" ml_inputs_idxs\n",
" <class 'list'>| len=147 | first 3 entries=[461223, 461224, 461225]\n",
" tasks\n",
" entity_indexs\n",
" <class 'list'>| len=10 | first 3 entries=[766, 1487, 1548]\n",
" ml_inputs_idxs\n",
" <class 'list'>| len=305 | first 3 entries=[646887, 646888, 646889]\n",
" methods\n",
" entity_indexs\n",
" <class 'list'>| len=10 | first 3 entries=[605, 1324, 1099]\n",
" ml_inputs_idxs\n",
" <class 'list'>| len=128 | first 3 entries=[1154530, 1154548, 1154550]\n"
]
}
],
"source": [
"# load document level split\n",
"DOC_SPLIT = json.load(open(SCIDMT_PATH['doc_split'], 'r'))\n",
"print_dict_structure(DOC_SPLIT)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" is_contain\n",
" datasets\n",
" <class 'list'>| len=1128148 | first 3 entries=[True, False, False]\n",
" tasks\n",
" <class 'list'>| len=1128148 | first 3 entries=[False, True, True]\n",
" methods\n",
" <class 'list'>| len=1128148 | first 3 entries=[False, False, False]\n",
" all\n",
" <class 'list'>| len=1128148 | first 3 entries=[True, True, True]\n",
" is_test\n",
" datasets\n",
" <class 'list'>| len=1128148 | first 3 entries=[False, False, False]\n",
" tasks\n",
" <class 'list'>| len=1128148 | first 3 entries=[True, True, True]\n",
" methods\n",
" <class 'list'>| len=1128148 | first 3 entries=[True, True, True]\n",
" all\n",
" <class 'list'>| len=1128148 | first 3 entries=[False, False, False]\n"
]
}
],
"source": [
"# load sentence level train/test split\n",
"with open(SCIDMT_PATH['sent_split'], 'r') as f:\n",
" SPLIT = json.load(f)\n",
"print_dict_structure(SPLIT)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_1610900/687978490.py:4: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.\n",
" X_train = np.array(X)[is_train]#[:5000] ##debug\n",
"/tmp/ipykernel_1610900/687978490.py:5: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.\n",
" y_train = np.array(y)[is_train]#[:5000] ##debug\n"
]
}
],
"source": [
"# load x_train, y_train\n",
"# is_test = true are not all human annotated. Thus, we have a seperate test file\n",
"is_train = np.logical_and(SPLIT['is_test']['all']==False, SPLIT['is_contain']['all'] == True)\n",
"X, y, _, _, _ = pickle.load(open(SCIDMT_PATH['sent_xy'], 'rb'))\n",
"X_train = np.array(X)[is_train]#[:5000] ##debug\n",
"y_train = np.array(y)[is_train]#[:5000] ##debug"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "py39",
"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.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|