|
|
import json |
|
|
import os |
|
|
import datasets |
|
|
|
|
|
_CITATION = "" |
|
|
_DESCRIPTION = "Multi-subset dataset for XS Toxicity benchmark." |
|
|
_HOMEPAGE = "" |
|
|
|
|
|
|
|
|
CONFIG_NAMES = [ |
|
|
"XSTest-response-Het", |
|
|
"XSTest-response-Hom" |
|
|
|
|
|
] |
|
|
|
|
|
class XSTestConfig(datasets.BuilderConfig): |
|
|
def __init__(self, **kwargs): |
|
|
super().__init__(**kwargs) |
|
|
|
|
|
class XSTestDataset(datasets.GeneratorBasedBuilder): |
|
|
BUILDER_CONFIGS = [ |
|
|
XSTestConfig( |
|
|
name=name, |
|
|
version=datasets.Version("1.0.0"), |
|
|
description=f"{name} subset of the XS Toxicity test benchmark." |
|
|
) |
|
|
for name in CONFIG_NAMES |
|
|
] |
|
|
|
|
|
def _info(self): |
|
|
return datasets.DatasetInfo( |
|
|
description=_DESCRIPTION, |
|
|
features=datasets.Features({ |
|
|
"data_id": datasets.Value("string"), |
|
|
"prompt": datasets.Value("string"), |
|
|
"response": datasets.Value("string"), |
|
|
"type": datasets.Value("string"), |
|
|
}), |
|
|
homepage=_HOMEPAGE, |
|
|
citation=_CITATION, |
|
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
|
data_dir = dl_manager.download_and_extract(".") |
|
|
config_name = self.config.name |
|
|
split_path = os.path.join(data_dir, "data", config_name, "train.jsonl") |
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TRAIN, |
|
|
gen_kwargs={"filepath": split_path} |
|
|
) |
|
|
] |
|
|
|
|
|
def _generate_examples(self, filepath): |
|
|
with open(filepath, "r", encoding="utf-8") as f: |
|
|
for idx, line in enumerate(f): |
|
|
yield idx, json.loads(line) |
|
|
|