File size: 2,471 Bytes
26a8a58 |
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 |
# coding=utf-8
import json
import os
import datasets
from datasets.download.download_manager import DownloadManager
from datasets.tasks import TextClassification
logger = datasets.logging.get_logger(__name__)
_DESCRIPTION = "`azaheadhealth`"
_VARIANTS = {
"micro": {
"version": "1.0.0",
"splits": {
"train": "data/micro_train.json",
"test": "data/micro_test.json"
}
},
"small": {
"version": "1.0.0",
"splits": {
"train": "data/small_train.json",
"test": "data/small_test.json"
}
},
}
class AZAheadHealthConfig(datasets.BuilderConfig):
"""BuildConfig for AZAheadHealth"""
def __init__(self, **kwargs):
super(AZAheadHealthConfig, self).__init__(**kwargs)
class AZAheadHealth(datasets.GeneratorBasedBuilder):
"""AZAheadHealth: A custom dataset in the health domain for the AZAhead project."""
use_auth_token = True
BUILDER_CONFIGS = [
AZAheadHealthConfig(name=name, version=config["version"])
for name, config in _VARIANTS.items()
]
DEFAULT_CONFIG_NAME = "small"
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"text": datasets.Value("string"),
"label": datasets.ClassLabel(num_classes=2, names=["NEGATIVE", "POSITIVE"]),
}
),
supervised_keys=None,
task_templates=[
TextClassification(
text_column="text", label_column="label"
)
]
)
def _split_generators(self, dl_manager: DownloadManager):
downloaded_files = dl_manager.download(_VARIANTS[self.config.name]["splits"])
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]})
]
def _generate_examples(self, filepath):
logger.info("generating examples from = %s", filepath)
with open(filepath) as fin:
content = json.load(fin)
key = 0
for sample in content:
yield key, {
"text": sample["text"],
"label": sample["label"]
}
key+=1 |