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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ w-rat
2
+ w-common
3
+ w-use
4
+ w-examin
5
+ w-pathogenesi
6
+ w-retinopathi
7
+ w-mous
8
+ w-studi
9
+ w-anim
10
+ w-model
11
+ w-metabol
12
+ w-abnorm
13
+ w-contribut
14
+ w-develop
15
+ w-investig
16
+ w-mice
17
+ w-2
18
+ w-month
19
+ w-compar
20
+ w-obtain
21
+ w-method
22
+ w-induc
23
+ w-6
24
+ w-inject
25
+ w-experiment
26
+ w-normal
27
+ w-diet
28
+ w-30
29
+ w-hyperglycemia
30
+ w-level
31
+ w-lipid
32
+ w-oxid
33
+ w-activ
34
+ w-protein
35
+ w-kinas
36
+ w-c
37
+ w-measur
38
+ w-result
39
+ w-increas
40
+ w-retin
41
+ w-stress
42
+ w-3
43
+ w-similar
44
+ w-observ
45
+ w-conclus
46
+ w-play
47
+ w-import
48
+ w-role
49
+ w-present
50
+ w-p
51
+ w-m
52
+ w-r
53
+ w-muscl
54
+ w-control
55
+ w-chang
56
+ w-dure
57
+ w-lower
58
+ w-higher
59
+ w-mass
60
+ w-correl
61
+ w-decreas
62
+ w-determin
63
+ w-concentr
64
+ w-stimul
65
+ w-period
66
+ w-caus
67
+ w-mark
68
+ w-group
69
+ w-evid
70
+ w-fast
71
+ w-type
72
+ w-signific
73
+ w-differ
74
+ w-ratio
75
+ w-suggest
76
+ w-degre
77
+ w-occur
78
+ w-vivo
79
+ w-respect
80
+ w-dysfunct
81
+ w-region
82
+ w-high
83
+ w-appear
84
+ w-sever
85
+ w-affect
86
+ w-cardiovascular
87
+ w-complic
88
+ w-primari
89
+ w-death
90
+ w-patient
91
+ w-clinic
92
+ w-suscept
93
+ w-cardiac
94
+ w-tissu
95
+ w-specif
96
+ w-function
97
+ w-defect
98
+ w-possibl
99
+ w-indic
100
+ w-state
101
+ w-onli
102
+ w-bodi
103
+ w-weight
104
+ w-loss
105
+ w-valu
106
+ w-howev
107
+ w-4
108
+ w-condit
109
+ w-durat
110
+ w-8
111
+ w-week
112
+ w-onset
113
+ w-data
114
+ w-direct
115
+ w-report
116
+ w-provid
117
+ w-addit
118
+ w-evalu
119
+ w-sensit
120
+ w-heart
121
+ w-object
122
+ w-mean
123
+ w-blood
124
+ w-glucos
125
+ w-strong
126
+ w-hba
127
+ w-1c
128
+ w-a1c
129
+ w-variabl
130
+ w-independ
131
+ w-assess
132
+ w-relat
133
+ w-trial
134
+ w-research
135
+ w-design
136
+ w-profil
137
+ w-sampl
138
+ w-particip
139
+ w-n
140
+ w-1
141
+ w-consist
142
+ w-befor
143
+ w-min
144
+ w-predict
145
+ w-adjust
146
+ w-sex
147
+ w-treatment
148
+ w-7
149
+ w-gt
150
+ w-0
151
+ w-larg
152
+ w-influenc
153
+ w-base
154
+ w-standard
155
+ w-14
156
+ w-10
157
+ w-wherea
158
+ w-enhanc
159
+ w-manag
160
+ w-day
161
+ w-secret
162
+ w-cholesterol
163
+ w-insulin
164
+ w-24
165
+ w-h
166
+ w-low
167
+ w-rate
168
+ w-fatti
169
+ w-acid
170
+ w-effect
171
+ w-hormon
172
+ w-hepat
173
+ w-contrast
174
+ w-product
175
+ w-major
176
+ w-plasma
177
+ w-current
178
+ w-flow
179
+ w-chronic
180
+ w-mechan
181
+ w-test
182
+ w-therefor
183
+ w-analys
184
+ w-mrna
185
+ w-streptozotocin
186
+ w-did
187
+ w-15
188
+ w-g
189
+ w-25
190
+ w-mmol
191
+ w-l
192
+ w-5
193
+ w-reduc
194
+ w-number
195
+ w-densiti
196
+ w-posit
197
+ w-cell
198
+ w-17
199
+ w-mm
200
+ w-18
201
+ w-induct
202
+ w-associ
203
+ w-express
204
+ w-glycem
205
+ w-respons
206
+ w-therapi
207
+ w-random
208
+ w-initi
209
+ w-ani
210
+ w-singl
211
+ w-new
212
+ w-agent
213
+ w-metformin
214
+ w-medic
215
+ w-glycosyl
216
+ w-hemoglobin
217
+ w-analysi
218
+ w-baselin
219
+ w-health
220
+ w-factor
221
+ w-process
222
+ w-care
223
+ w-9
224
+ w-01
225
+ w-95
226
+ w-interv
227
+ w-ci
228
+ w-12
229
+ w-reduct
230
+ w-achiev
231
+ w-target
232
+ w-lt
233
+ w-diseas
234
+ w-class
235
+ w-age
236
+ w-obes
237
+ w-renal
238
+ w-improv
239
+ w-progress
240
+ w-noninsulindepend
241
+ w-mellitus
242
+ w-becaus
243
+ w-s
244
+ w-index
245
+ w-hypertens
246
+ w-need
247
+ w-followup
248
+ w-year
249
+ w-mg
250
+ w-dl
251
+ w-remain
252
+ w-subject
253
+ w-treat
254
+ w-oral
255
+ w-requir
256
+ w-0001
257
+ w-mortal
258
+ w-includ
259
+ w-vs
260
+ w-background
261
+ w-poor
262
+ w-drug
263
+ w-13
264
+ w-rang
265
+ w-combin
266
+ w-intervent
267
+ w-daili
268
+ w-dose
269
+ w-100
270
+ w-toler
271
+ w-receiv
272
+ w-11
273
+ w-postprandi
274
+ w-kg
275
+ w-hypoglycemia
276
+ w-frequent
277
+ w-event
278
+ w-versus
279
+ w-symptom
280
+ w-incid
281
+ w-parent
282
+ w-complex
283
+ w-longterm
284
+ w-inhibitor
285
+ w-peripher
286
+ w-nerv
287
+ w-stz
288
+ w-conduct
289
+ w-demonstr
290
+ w-frequenc
291
+ w-inhibit
292
+ w-neuropathi
293
+ w-pathway
294
+ w-shown
295
+ w-time
296
+ w-ii
297
+ w-individu
298
+ w-adult
299
+ w-50
300
+ w-60
301
+ w-diagnosi
302
+ w-healthi
303
+ w-follow
304
+ w-young
305
+ w-seen
306
+ w-alter
307
+ w-gene
308
+ w-e
309
+ w-identifi
310
+ w-previous
311
+ w-mediat
312
+ w-vascular
313
+ w-lipoprotein
314
+ w-involv
315
+ w-phenotyp
316
+ w-confirm
317
+ w-variant
318
+ w-endotheli
319
+ w-potenti
320
+ w-disord
321
+ w-popul
322
+ w-nonobes
323
+ w-aim
324
+ w-serum
325
+ w-hba1c
326
+ w-hypoglycaemia
327
+ w-continu
328
+ w-case
329
+ w-impair
330
+ w-risk
331
+ w-known
332
+ w-men
333
+ w-women
334
+ w-40
335
+ w-complet
336
+ w-estim
337
+ w-like
338
+ w-particular
339
+ w-human
340
+ w-character
341
+ w-elev
342
+ w-synthesi
343
+ w-greater
344
+ w-small
345
+ w-reveal
346
+ w-liver
347
+ w-niddm
348
+ w-genet
349
+ w-receptor
350
+ w-growth
351
+ w-pancreat
352
+ w-betacel
353
+ w-molecul
354
+ w-enzym
355
+ w-regul
356
+ w-polymorph
357
+ w-total
358
+ w-allel
359
+ w-02
360
+ w-resist
361
+ w-cpeptid
362
+ w-hypothesi
363
+ w-perform
364
+ w-score
365
+ w-001
366
+ w-05
367
+ w-histori
368
+ w-action
369
+ w-approxim
370
+ w-suppress
371
+ w-glucagon
372
+ w-ml
373
+ w-x
374
+ w-free
375
+ w-peopl
376
+ w-uptak
377
+ w-intens
378
+ w-relationship
379
+ w-prevent
380
+ w-autoimmun
381
+ w-recent
382
+ w-preval
383
+ w-nondiabet
384
+ w-genotyp
385
+ w-conclud
386
+ w-linkag
387
+ w-islet
388
+ w-peptid
389
+ w-form
390
+ w-membran
391
+ w-transgen
392
+ w-failur
393
+ w-isol
394
+ w-negat
395
+ w-earli
396
+ w-famili
397
+ w-chromosom
398
+ w-immun
399
+ w-support
400
+ w-16
401
+ w-cohort
402
+ w-insulindepend
403
+ w-outcom
404
+ w-screen
405
+ w-approach
406
+ w-infus
407
+ w-multipl
408
+ w-depend
409
+ w-physic
410
+ w-transport
411
+ w-acut
412
+ w-releas
413
+ w-presenc
414
+ w-glycaem
415
+ w-male
416
+ w-antibodi
417
+ w-femal
418
+ w-pattern
419
+ w-t2dm
420
+ w-promot
421
+ w-fat
422
+ w-d
423
+ w-bmi
424
+ w-haplotyp
425
+ w-triglycerid
426
+ w-interact
427
+ w-marker
428
+ w-describ
429
+ w-area
430
+ w-20
431
+ w-cytokin
432
+ w-bind
433
+ w-bb
434
+ w-alpha
435
+ w-beta
436
+ w-cd4
437
+ w-spontan
438
+ w-given
439
+ w-vitro
440
+ w-basal
441
+ w-protect
442
+ w-pressur
443
+ w-detect
444
+ w-exercis
445
+ w-children
446
+ w-adolesc
447
+ w-life
448
+ w-b
449
+ w-antigen
450
+ w-iddm
451
+ w-american
452
+ w-hla
453
+ w-arteri
454
+ w-nephropathi
455
+ w-review
456
+ w-destruct
457
+ w-content
458
+ w-autoantibodi
459
+ w-dm
460
+ w-select
461
+ w-infect
462
+ w-recipi
463
+ w-intak
464
+ w-placebo
465
+ w-db
466
+ w-pancrea
467
+ w-diagnos
468
+ w-glomerular
469
+ w-albumin
470
+ w-excret
471
+ w-syndrom
472
+ w-t
473
+ w-lymphocyt
474
+ w-produc
475
+ w-coronari
476
+ w-status
477
+ w-microalbuminuria
478
+ w-nod
479
+ w-mhc
480
+ w-insul
481
+ w-administr
482
+ w-revers
483
+ w-transplant
484
+ w-graft
485
+ w-t1d
486
+ w-lead
487
+ w-v
488
+ w-dietari
489
+ w-general
490
+ w-macrophag
491
+ w-kidney
492
+ w-urinari
493
+ w-myocardi
494
+ w-meal
495
+ w-ica
496
+ w-locus
497
+ w-tcell
498
+ w-depress
499
+ w-bone
500
+ w-mutat
501
+ summary
pubmed.py ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ from datasets import features
19
+ import pandas
20
+ import os
21
+
22
+ import datasets
23
+
24
+
25
+ # TODO: Add BibTeX citation
26
+ # Find for instance the citation on arxiv or on the dataset repo/website
27
+ _CITATION = ""
28
+
29
+ # TODO: Add description of the dataset here
30
+ # You can copy an official description
31
+ _DESCRIPTION = """\
32
+ The Pubmed Diabetes dataset consists of 19717 scientific publications from PubMed database pertaining to diabetes classified into one of three classes. The citation network consists of 44338 links. Each publication in the dataset is described by a TF/IDF weighted word vector from a dictionary which consists of 500 unique words. The README file in the dataset provides more details.
33
+ """
34
+
35
+ # TODO: Add a link to an official homepage for the dataset here
36
+ _HOMEPAGE = "https://linqs.soe.ucsc.edu/data"
37
+
38
+ # TODO: Add the licence for the dataset here if you can find it
39
+ _LICENSE = ""
40
+
41
+ # TODO: Add link to the official dataset URLs here
42
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
43
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
44
+ _URLs = {
45
+ "nodes": "https://linqs-data.soe.ucsc.edu/public/Pubmed-Diabetes.tgz",
46
+ "edges": "https://linqs-data.soe.ucsc.edu/public/Pubmed-Diabetes.tgz"
47
+ }
48
+
49
+ _CLASS_LABELS = [
50
+ "Diabetes Mellitus, Experimental",
51
+ "Diabetes Mellitus Type 1",
52
+ "Diabetes Mellitus Type 2"
53
+ ]
54
+
55
+
56
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
57
+ class PubmedDataset(datasets.GeneratorBasedBuilder):
58
+ VERSION = datasets.Version("1.0.0")
59
+
60
+ # This is an example of a dataset with multiple configurations.
61
+ # If you don't want/need to define several sub-sets in your dataset,
62
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
63
+
64
+ # If you need to make complex sub-parts in the datasets with configurable options
65
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
66
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
67
+
68
+ # You will be able to load one or the other configurations in the following list with
69
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
70
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
71
+ BUILDER_CONFIGS = [
72
+ datasets.BuilderConfig(name="nodes", version=VERSION,
73
+ description="The PubMed dataset"),
74
+ datasets.BuilderConfig(name="edges", version=VERSION,
75
+ description="The PubMed network")
76
+ ]
77
+
78
+ # It's not mandatory to have a default configuration. Just use one if it make sense.
79
+ DEFAULT_CONFIG_NAME = "nodes"
80
+
81
+ def _info(self):
82
+ if self.config.name == "nodes":
83
+ with open("pubmed-word-features.txt", "rt", encoding="UTF-8") as f:
84
+ word_features = f.read().split("\n")
85
+
86
+ features_dict = {
87
+ w: datasets.Value("float32")
88
+ for w in word_features
89
+ }
90
+ features_dict["node"] = datasets.Value("string")
91
+ features_dict["label"] = datasets.ClassLabel(names=_CLASS_LABELS)
92
+ features_dict["neighbors"] = datasets.Sequence(
93
+ datasets.Value("string")
94
+ )
95
+ features = datasets.Features(features_dict)
96
+ elif self.config.name == "edges": # This is an example to show how to have different features for "first_domain" and "second_domain"
97
+ features = datasets.Features(
98
+ {
99
+ "source": datasets.Value("string"),
100
+ "target": datasets.Value("string")
101
+ }
102
+ )
103
+ return datasets.DatasetInfo(
104
+ # This is the description that will appear on the datasets page.
105
+ description=_DESCRIPTION,
106
+ # This defines the different columns of the dataset and their types
107
+ # Here we define them above because they are different between the two configurations
108
+ features=features,
109
+ # If there's a common (input, target) tuple from the features,
110
+ # specify them here. They'll be used if as_supervised=True in
111
+ # builder.as_dataset.
112
+ supervised_keys=None,
113
+ # Homepage of the dataset for documentation
114
+ homepage=_HOMEPAGE,
115
+ # License for the dataset if available
116
+ license=_LICENSE,
117
+ # Citation for the dataset
118
+ citation=_CITATION,
119
+ )
120
+
121
+ def _split_generators(self, dl_manager):
122
+ """Returns SplitGenerators."""
123
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
124
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
125
+
126
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
127
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
128
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
129
+ my_urls = _URLs[self.config.name]
130
+ data_dir = dl_manager.download_and_extract(my_urls)
131
+ data_dir = os.path.join(data_dir, "Pubmed-Diabetes", "data")
132
+
133
+ return [
134
+ datasets.SplitGenerator(
135
+ name=datasets.Split.TRAIN,
136
+ # These kwargs will be passed to _generate_examples
137
+ gen_kwargs={
138
+ "edges_path": os.path.join(data_dir, "Pubmed-Diabetes.DIRECTED.cites.tab"),
139
+ "nodes_path": os.path.join(data_dir, "Pubmed-Diabetes.NODE.paper.tab"),
140
+ "split": "train"
141
+ }
142
+ )
143
+ ]
144
+
145
+ def _generate_examples(
146
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
147
+ self, edges_path, nodes_path, split
148
+ ):
149
+ """ Yields examples as (key, example) tuples. """
150
+ # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
151
+ # The `key` is here for legacy reason (tfds) and is not important in itself.
152
+
153
+ if self.config.name == "nodes":
154
+ neighbors = {}
155
+ with open(edges_path, "rt", encoding="UTF-8") as f:
156
+ # Skip the two first lines
157
+ f.readline()
158
+ f.readline()
159
+
160
+ for line in f:
161
+ cols = line.strip().split("\t")
162
+ src, target = cols[1].split(":")[1], cols[3].split(":")[1]
163
+ for n in (target, src):
164
+ if n not in neighbors:
165
+ neighbors[n] = []
166
+ neighbors[src].append(target)
167
+
168
+ with open("pubmed-word-features.txt", "rt", encoding="UTF-8") as f:
169
+ word_features = f.read().split("\n")
170
+
171
+ def _word_feature_tuple(x):
172
+ w, v = x.split("=")
173
+ return (w, float(v))
174
+
175
+ with open(nodes_path, "rt", encoding="UTF-8") as f:
176
+ # Skip the two first lines
177
+ f.readline()
178
+ f.readline()
179
+
180
+ for id, line in enumerate(f):
181
+ row = line.split("\t")
182
+ node = row[0]
183
+ label = _CLASS_LABELS[int(row[1][-1]) - 1]
184
+ w_features = dict(map(_word_feature_tuple, row[2:-1]))
185
+ features = {"node": node, "label": label,
186
+ "neighbors": neighbors[node]}
187
+ for x in word_features:
188
+ features[x] = w_features.get(x, 0.0)
189
+ yield id, features
190
+
191
+ elif self.config.name == "edges":
192
+ with open(edges_path, "rt", encoding="UTF-8") as f:
193
+ # Skip the two first lines
194
+ f.readline()
195
+ f.readline()
196
+
197
+ for id, line in enumerate(f):
198
+ cols = line.strip().split("\t")
199
+ src, target = cols[1].split(":")[1], cols[3].split(":")[1]
200
+ yield id, {"source": src, "target": target}