debatelab-admin commited on
Commit
d940e57
·
1 Parent(s): 48a3b42
Files changed (1) hide show
  1. deepa2-corpus.py +166 -0
deepa2-corpus.py ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """Dataset with argument reconstructions (DA2) manually gathered from the literature."""
16
+
17
+ import logging
18
+ import json
19
+ import os
20
+
21
+ logger = logging.getLogger(__name__)
22
+
23
+ import datasets # pylint: disable=import-error
24
+ from huggingface_hub import hf_hub_download # pylint: disable=import-error
25
+
26
+
27
+
28
+
29
+ # Find for instance the citation on arxiv or on the dataset repo/website
30
+ _CITATION = """\
31
+ @InProceedings{betz:dataset,
32
+ title = {A great new dataset},
33
+ author={Betz, Gregor
34
+ },
35
+ year={2020}
36
+ }
37
+ """
38
+
39
+ _DESCRIPTION = """\
40
+ Dataset with argument reconstructions (DA2) manually gathered from the literature.
41
+ """
42
+
43
+ _HOMEPAGE = ""
44
+
45
+ _LICENSE = ""
46
+
47
+ _URLS = {
48
+ "all": ["corpus.zip"],
49
+ "books_only": ["corpus.zip"],
50
+ }
51
+
52
+
53
+ class DeepA2Corpus(datasets.GeneratorBasedBuilder):
54
+ """Dataset with argument reconstructions (DA2) manually gathered from the literature."""
55
+
56
+ VERSION = datasets.Version("0.1.0")
57
+
58
+ # This is an example of a dataset with multiple configurations.
59
+ # If you don't want/need to define several sub-sets in your dataset,
60
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
61
+
62
+ # If you need to make complex sub-parts in the datasets with configurable options
63
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
64
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
65
+
66
+ # You will be able to load one or the other configurations in the following list with
67
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
68
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
69
+ BUILDER_CONFIGS = [
70
+ datasets.BuilderConfig(name="all", version=VERSION, description="This part of my dataset covers a first domain"),
71
+ datasets.BuilderConfig(name="books_only", version=VERSION, description="NOT IMPLEMENTED YET"),
72
+ ]
73
+
74
+ DEFAULT_CONFIG_NAME = "all" # It's not mandatory to have a default configuration. Just use one if it make sense.
75
+
76
+ def _info(self):
77
+ features = datasets.Features(
78
+ {
79
+ "text": datasets.Value("string"),
80
+ }
81
+ )
82
+
83
+ return datasets.DatasetInfo(
84
+ # This is the description that will appear on the datasets page.
85
+ description=_DESCRIPTION,
86
+ # This defines the different columns of the dataset and their types
87
+ features=features, # Here we define them above because they are different between the two configurations
88
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
89
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
90
+ # supervised_keys=("sentence", "label"),
91
+ # Homepage of the dataset for documentation
92
+ homepage=_HOMEPAGE,
93
+ # License for the dataset if available
94
+ license=_LICENSE,
95
+ # Citation for the dataset
96
+ citation=_CITATION,
97
+ )
98
+
99
+ def _split_generators(self, dl_manager):
100
+ # This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
101
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
102
+
103
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
104
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
105
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
106
+
107
+ #filenames = _URLS[self.config.name]
108
+ #
109
+ #filepaths = []
110
+ #for filename in filenames:
111
+ # logger.info("Downloading %s", filename)
112
+ # filepaths.append(
113
+ # hf_hub_download(
114
+ # repo_id="debatelab/deepa2-harvest",
115
+ # repo_type="dataset",
116
+ # filename=filename,
117
+ # token=True,
118
+ # )
119
+ # )
120
+
121
+ return [
122
+ datasets.SplitGenerator(
123
+ name=datasets.Split.TRAIN,
124
+ # These kwargs will be passed to _generate_examples
125
+ gen_kwargs={
126
+ "filepaths": ["corpus"],
127
+ "split": datasets.Split.TRAIN,
128
+ },
129
+ ),
130
+ datasets.SplitGenerator(
131
+ name=datasets.Split.VALIDATION,
132
+ # These kwargs will be passed to _generate_examples
133
+ gen_kwargs={
134
+ "filepaths": [],
135
+ "split": datasets.Split.VALIDATION,
136
+ },
137
+ ),
138
+ datasets.SplitGenerator(
139
+ name=datasets.Split.TEST,
140
+ # These kwargs will be passed to _generate_examples
141
+ gen_kwargs={
142
+ "filepaths": [],
143
+ "split": datasets.Split.TEST,
144
+ },
145
+ ),
146
+ ]
147
+
148
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
149
+ def _generate_examples(self, filepaths, split):
150
+ # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
151
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
152
+
153
+
154
+ for filepath in filepaths:
155
+ dataset = datasets.load_dataset("debatelab/deepa2-corpus", datafiles=f"{filepath}/*.txt",split=split)
156
+
157
+
158
+ with open(filepath, encoding="utf-8") as f:
159
+ for key, row in enumerate(f):
160
+ data = json.loads(row)
161
+ data = {
162
+ k:v for k,v in data.items()
163
+ if k in _DA2_FEATURES
164
+ }
165
+ data["metadata"] = []
166
+ yield key, data