|
|
|
|
|
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 |