Update loading_script.py
Browse files- loading_script.py +144 -0
loading_script.py
CHANGED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
16 |
+
"""TODO: This Dataset is provided by intel for oneAPI_AI Hackathon contest."""
|
17 |
+
|
18 |
+
|
19 |
+
import csv
|
20 |
+
import os
|
21 |
+
|
22 |
+
import datasets
|
23 |
+
|
24 |
+
|
25 |
+
# TODO: Add BibTeX citation
|
26 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
27 |
+
_CITATION = """\
|
28 |
+
@InProceedings{huggingface:dataset,
|
29 |
+
title = {oneAPIDataset},
|
30 |
+
author={huggingface, Inc.
|
31 |
+
},
|
32 |
+
year={2023}
|
33 |
+
}
|
34 |
+
"""
|
35 |
+
|
36 |
+
# TODO: Add description of the dataset here
|
37 |
+
# You can copy an official description
|
38 |
+
_DESCRIPTION = """\
|
39 |
+
This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
|
40 |
+
"""
|
41 |
+
|
42 |
+
|
43 |
+
# TODO: Add link to the official dataset URLs here
|
44 |
+
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
45 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
46 |
+
# _URLS = {
|
47 |
+
# "first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip",
|
48 |
+
# "second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip",
|
49 |
+
# }
|
50 |
+
|
51 |
+
|
52 |
+
# TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
|
53 |
+
class NewDataset(datasets.GeneratorBasedBuilder):
|
54 |
+
"""TODO: Short description of my dataset."""
|
55 |
+
|
56 |
+
VERSION = datasets.Version("1.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 = datasets.BuilderConfig(name="first_domain", version=VERSION, description="oneAPI dataset contains context,question and answer")
|
70 |
+
|
71 |
+
DEFAULT_CONFIG_NAME = "default" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
72 |
+
|
73 |
+
def _info(self):
|
74 |
+
|
75 |
+
features = datasets.Features(
|
76 |
+
{
|
77 |
+
|
78 |
+
"Story": datasets.Value("string"),
|
79 |
+
"Question": datasets.Value("string"),
|
80 |
+
"span_start": datasets.Value("int32")
|
81 |
+
"span_end": datasets.Value("int32"),
|
82 |
+
"span_text": datasets.Value("string"),
|
83 |
+
"Answer" : datasets.Value("string"),
|
84 |
+
# These are the features of the dataset
|
85 |
+
}
|
86 |
+
)
|
87 |
+
return datasets.DatasetInfo(
|
88 |
+
# This is the description that will appear on the datasets page.
|
89 |
+
description=_DESCRIPTION,
|
90 |
+
# This defines the different columns of the dataset and their types
|
91 |
+
features=features, # Here we define them above because they are different between the two configurations
|
92 |
+
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
93 |
+
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
94 |
+
# supervised_keys=("sentence", "label"),
|
95 |
+
|
96 |
+
# Citation for the dataset
|
97 |
+
citation=_CITATION,
|
98 |
+
)
|
99 |
+
|
100 |
+
def _split_generators(self, dl_manager):
|
101 |
+
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
102 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
103 |
+
|
104 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
105 |
+
# 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.
|
106 |
+
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
107 |
+
# urls = _URLS[self.config.name]
|
108 |
+
data_dir = "./Data"
|
109 |
+
return [
|
110 |
+
datasets.SplitGenerator(
|
111 |
+
name=datasets.Split.TRAIN,
|
112 |
+
# These kwargs will be passed to _generate_examples
|
113 |
+
gen_kwargs={
|
114 |
+
"filepath": os.path.join(data_dir, "train.csv"),
|
115 |
+
"split": "train",
|
116 |
+
},
|
117 |
+
),
|
118 |
+
datasets.SplitGenerator(
|
119 |
+
name=datasets.Split.TEST,
|
120 |
+
# These kwargs will be passed to _generate_examples
|
121 |
+
gen_kwargs={
|
122 |
+
"filepath": os.path.join(data_dir, "test.csv"),
|
123 |
+
"split": "test"
|
124 |
+
},
|
125 |
+
),
|
126 |
+
]
|
127 |
+
|
128 |
+
|
129 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
130 |
+
def _generate_examples(self, filepath):
|
131 |
+
|
132 |
+
with open(filepath, mode="r", newline="", encoding="utf-8") as f:
|
133 |
+
csv_reader = csv.DictReader(f)
|
134 |
+
for row in (csv_reader):
|
135 |
+
yield {
|
136 |
+
"Story": row["Story"],
|
137 |
+
"Question": row["Question"],
|
138 |
+
"span_start": row["span_start"],
|
139 |
+
"span_end": row["span_end"],
|
140 |
+
"span_text": row["span_text"],
|
141 |
+
"Answer": row["Answer"]
|
142 |
+
}
|
143 |
+
|
144 |
+
|