jopan commited on
Commit
156ed8c
1 Parent(s): 719bb97

Upload 2 files

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