Datasets:

Modalities:
Text
Languages:
English
ArXiv:
Tags:
License:
Severine commited on
Commit
1fe472a
1 Parent(s): ed67c16

add data loading script

Browse files
Files changed (1) hide show
  1. C2Gen.py +121 -0
C2Gen.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+ """The SuperGLUE benchmark."""
18
+
19
+ import json
20
+ import os
21
+ import datasets
22
+ import pandas as pd
23
+
24
+ _CITATION = """TODO
25
+ """
26
+
27
+ # You can copy an official description
28
+ _DESCRIPTION = """The task of C2Gen is to both generate commonsensical text which include the given words, and also have the generated text adhere to the given context.
29
+ """
30
+
31
+ _HOMEPAGE = ""
32
+
33
+ _LICENSE = "cc-by-sa-4.0"
34
+
35
+ # TODO: Add link to the official dataset URLs here
36
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
37
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
38
+ _URL = "https://huggingface.co/datasets/Severine/C2Gen/resolve/main/data/"
39
+ _TASKS = {
40
+ "c2gen": "C2Gen",
41
+ }
42
+
43
+
44
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
45
+ class SuperLim(datasets.GeneratorBasedBuilder):
46
+ """TODO: Short description of my dataset."""
47
+
48
+ VERSION = datasets.Version("1.1.0")
49
+
50
+ # If you need to make complex sub-parts in the datasets with configurable options
51
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
52
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
53
+
54
+ # You will be able to load one or the other configurations in the following list with
55
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
56
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
57
+ BUILDER_CONFIGS = [
58
+ datasets.BuilderConfig(name="c2gen", version=VERSION, description=_DESCRIPTION),
59
+ ]
60
+
61
+
62
+ def _info(self):
63
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
64
+ # This is the name of the configuration selected in BUILDER_CONFIGS above
65
+ features = datasets.Features(
66
+ {
67
+ "context": datasets.Value("string"),
68
+ "keywords": datasets.Value("string"),
69
+ # These are the features of your dataset like images, labels ...
70
+ }
71
+ )
72
+
73
+ return datasets.DatasetInfo(
74
+ # This is the description that will appear on the datasets page.
75
+ description=_DESCRIPTION,
76
+ # This defines the different columns of the dataset and their types
77
+ features=features, # Here we define them above because they are different between the two configurations
78
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
79
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
80
+ # supervised_keys=("sentence", "label"),
81
+ # Homepage of the dataset for documentation
82
+ homepage=_HOMEPAGE,
83
+ # License for the dataset if available
84
+ license=_LICENSE,
85
+ # Citation for the dataset
86
+ citation=_CITATION,
87
+ )
88
+
89
+ def _split_generators(self, dl_manager):
90
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
91
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
92
+
93
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
94
+ # 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.
95
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
96
+ #urls = _URLS[self.config.name]
97
+ data_dir_test = dl_manager.download_and_extract(os.path.join(_URL, _TASKS[self.config.name], "test.json"))
98
+ return [
99
+ datasets.SplitGenerator(
100
+ name=datasets.Split.TEST,
101
+ # These kwargs will be passed to _generate_examples
102
+ gen_kwargs={
103
+ "filepath": data_dir_test,
104
+ "split": "test"
105
+ },
106
+ ),
107
+ ]
108
+
109
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
110
+ def _generate_examples(self, filepath, split):
111
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
112
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
113
+ data = json.load(open(filepath,"r"))
114
+ for key, row in enumerate(data):
115
+
116
+ # Yields examples as (key, example) tuples
117
+ yield key, {
118
+ "context": row["Context"],
119
+ "keywords": row["Words"],
120
+ }
121
+