File size: 2,864 Bytes
ab0b497
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ef1e09
ab0b497
 
 
 
 
 
 
 
 
 
102907e
2711314
102907e
ab0b497
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ef1e09
 
ab0b497
 
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
88
89
90
91
92
93
94
"""C4 dataset based on Common Crawl."""


import gzip
import json

import datasets
try:
    import lzma as xz
except ImportError:
    import pylzma as xz


logger = datasets.logging.get_logger(__name__)


_DESCRIPTION = """\
A living legal dataset.
"""

_CITATION = """
TODO
"""

_URL = ""


_DATA_URL = {
    "eoir_privacy" : 
    {
        "train" : ["https://huggingface.co/datasets/pile-of-law/eoir_privacy/resolve/main/data/train.privacy.eoir.jsonl.xz"],
        "validation" : ["https://huggingface.co/datasets/pile-of-law/eoir_privacy/resolve/main/data/validation.privacy.eoir.jsonl.xz"]
    }
}

_VARIANTS = ["all"] + list(_DATA_URL.keys())


class EOIRPrivacy(datasets.GeneratorBasedBuilder):
    """TODO"""

    BUILDER_CONFIGS = [datasets.BuilderConfig(name) for name in _VARIANTS]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "text": datasets.Value("string"),
                    "year": datasets.Value("string"),
                    "name": datasets.Value("string"),
                    'label': datasets.ClassLabel(num_classes=2, names=['False', 'True'])
                }
            ),
            supervised_keys=None,
            homepage=_URL,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        data_urls = {}
        if self.config.name == "all":
            data_sources = list(_DATA_URL.keys())
        else:
            data_sources = [self.config.name]
        for split in ["train", "validation"]:
            data_urls[split] = []
            for source in data_sources:
                for chunk in _DATA_URL[source][split]:
                    data_urls[split].append(chunk)

        train_downloaded_files = dl_manager.download(data_urls["train"])
        validation_downloaded_files = dl_manager.download(data_urls["validation"])
        return [
            datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": train_downloaded_files}),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION, gen_kwargs={"filepaths": validation_downloaded_files}
            ),
        ]

    def _generate_examples(self, filepaths):
        """This function returns the examples in the raw (text) form by iterating on all the files."""
        id_ = 0
        for filepath in filepaths:
            logger.info("generating examples from = %s", filepath)
            with xz.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
                for line in f:
                    if line:
                        example = json.loads(line)
                        label = example["label"]
                        example["label"] = int(label)
                        yield id_, example
                        id_ += 1