zwellington commited on
Commit
26a8a58
1 Parent(s): ef6bdfc

add loading script

Browse files
Files changed (1) hide show
  1. azaheadhealth.py +87 -0
azaheadhealth.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+
3
+ import json
4
+ import os
5
+
6
+ import datasets
7
+ from datasets.download.download_manager import DownloadManager
8
+ from datasets.tasks import TextClassification
9
+
10
+ logger = datasets.logging.get_logger(__name__)
11
+
12
+ _DESCRIPTION = "`azaheadhealth`"
13
+
14
+ _VARIANTS = {
15
+ "micro": {
16
+ "version": "1.0.0",
17
+ "splits": {
18
+ "train": "data/micro_train.json",
19
+ "test": "data/micro_test.json"
20
+ }
21
+ },
22
+ "small": {
23
+ "version": "1.0.0",
24
+ "splits": {
25
+ "train": "data/small_train.json",
26
+ "test": "data/small_test.json"
27
+ }
28
+ },
29
+ }
30
+
31
+ class AZAheadHealthConfig(datasets.BuilderConfig):
32
+ """BuildConfig for AZAheadHealth"""
33
+
34
+ def __init__(self, **kwargs):
35
+ super(AZAheadHealthConfig, self).__init__(**kwargs)
36
+
37
+ class AZAheadHealth(datasets.GeneratorBasedBuilder):
38
+ """AZAheadHealth: A custom dataset in the health domain for the AZAhead project."""
39
+
40
+ use_auth_token = True
41
+
42
+ BUILDER_CONFIGS = [
43
+ AZAheadHealthConfig(name=name, version=config["version"])
44
+ for name, config in _VARIANTS.items()
45
+ ]
46
+
47
+ DEFAULT_CONFIG_NAME = "small"
48
+
49
+ def _info(self):
50
+ return datasets.DatasetInfo(
51
+ description=_DESCRIPTION,
52
+ features=datasets.Features(
53
+ {
54
+ "text": datasets.Value("string"),
55
+ "label": datasets.ClassLabel(num_classes=2, names=["NEGATIVE", "POSITIVE"]),
56
+ }
57
+ ),
58
+ supervised_keys=None,
59
+ task_templates=[
60
+ TextClassification(
61
+ text_column="text", label_column="label"
62
+ )
63
+ ]
64
+ )
65
+
66
+ def _split_generators(self, dl_manager: DownloadManager):
67
+
68
+ downloaded_files = dl_manager.download(_VARIANTS[self.config.name]["splits"])
69
+
70
+ return [
71
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
72
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]})
73
+ ]
74
+
75
+ def _generate_examples(self, filepath):
76
+ logger.info("generating examples from = %s", filepath)
77
+
78
+ with open(filepath) as fin:
79
+ content = json.load(fin)
80
+
81
+ key = 0
82
+ for sample in content:
83
+ yield key, {
84
+ "text": sample["text"],
85
+ "label": sample["label"]
86
+ }
87
+ key+=1