File size: 1,701 Bytes
4be7826
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import os
import datasets

_CITATION = ""
_DESCRIPTION = "Multi-subset dataset for XS Toxicity benchmark."
_HOMEPAGE = ""

# List your available configs here
CONFIG_NAMES = [
    "XSTest-response-Het",
    "XSTest-response-Hom"
    # Add more here if needed
]

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)