Upload load_script.py
Browse files- load_script.py +158 -0
load_script.py
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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: Add a description here."""
|
17 |
+
|
18 |
+
|
19 |
+
import json
|
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 |
+
@article{qin2024infobench,
|
29 |
+
title={InFoBench: Evaluating Instruction Following Ability in Large Language Models},
|
30 |
+
author={Yiwei Qin and Kaiqiang Song and Yebowen Hu and Wenlin Yao and Sangwoo Cho and Xiaoyang Wang and Xuansheng Wu and Fei Liu and Pengfei Liu and Dong Yu},
|
31 |
+
year={2024},
|
32 |
+
eprint={2401.03601},
|
33 |
+
archivePrefix={arXiv},
|
34 |
+
primaryClass={cs.CL}
|
35 |
+
}
|
36 |
+
"""
|
37 |
+
|
38 |
+
# TODO: Add description of the dataset here
|
39 |
+
# You can copy an official description
|
40 |
+
_DESCRIPTION = """\
|
41 |
+
InFoBench: Evaluating Instruction Following Ability in Large Language Models
|
42 |
+
"""
|
43 |
+
|
44 |
+
# TODO: Add a link to an official homepage for the dataset here
|
45 |
+
_HOMEPAGE = ""
|
46 |
+
|
47 |
+
# TODO: Add the licence for the dataset here if you can find it
|
48 |
+
_LICENSE = """MIT License
|
49 |
+
|
50 |
+
Copyright (c) 2023 qinyiwei
|
51 |
+
|
52 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
53 |
+
of this software and associated documentation files (the "Software"), to deal
|
54 |
+
in the Software without restriction, including without limitation the rights
|
55 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
56 |
+
copies of the Software, and to permit persons to whom the Software is
|
57 |
+
furnished to do so, subject to the following conditions:
|
58 |
+
|
59 |
+
The above copyright notice and this permission notice shall be included in all
|
60 |
+
copies or substantial portions of the Software.
|
61 |
+
|
62 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
63 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
64 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
65 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
66 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
67 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
68 |
+
SOFTWARE.
|
69 |
+
"""
|
70 |
+
|
71 |
+
# TODO: Add link to the official dataset URLs here
|
72 |
+
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
73 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
74 |
+
_URLS = {
|
75 |
+
"test": "https://huggingface.co/datasets/kqsong/InFoBench/raw/main/InfoBench.json",
|
76 |
+
}
|
77 |
+
|
78 |
+
|
79 |
+
# TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
|
80 |
+
class NewDataset(datasets.GeneratorBasedBuilder):
|
81 |
+
"""TODO: Short description of my dataset."""
|
82 |
+
|
83 |
+
VERSION = datasets.Version("1.0.0")
|
84 |
+
|
85 |
+
# This is an example of a dataset with multiple configurations.
|
86 |
+
# If you don't want/need to define several sub-sets in your dataset,
|
87 |
+
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
88 |
+
|
89 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
90 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
91 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
92 |
+
|
93 |
+
# You will be able to load one or the other configurations in the following list with
|
94 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
95 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
96 |
+
BUILDER_CONFIGS = [
|
97 |
+
datasets.BuilderConfig(name="test", version=VERSION, description="Test Split")
|
98 |
+
]
|
99 |
+
|
100 |
+
DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
101 |
+
|
102 |
+
def _info(self):
|
103 |
+
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
104 |
+
features = datasets.Features(
|
105 |
+
{
|
106 |
+
"id": datasets.Value(dtype="string", id=None),
|
107 |
+
"subset": datasets.Value(dtype="string", id=None),
|
108 |
+
"category": datasets.Value(dtype="string", id=None),
|
109 |
+
"input": datasets.Value(dtype="string", id=None),
|
110 |
+
"instruction": datasets.Value(dtype="string", id=None),
|
111 |
+
"decomposed_questions": datasets.Sequence(feature=datasets.Value(dtype="string", id=None), length=-1, id=None),
|
112 |
+
"question_label": datasets.Sequence(feature=datasets.Sequence(feature=datasets.Value(dtype="string", id=None), length=-1, id=None), length=-1, id=None),
|
113 |
+
}
|
114 |
+
)
|
115 |
+
return datasets.DatasetInfo(
|
116 |
+
# This is the description that will appear on the datasets page.
|
117 |
+
description=_DESCRIPTION,
|
118 |
+
# This defines the different columns of the dataset and their types
|
119 |
+
features=features, # Here we define them above because they are different between the two configurations
|
120 |
+
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
121 |
+
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
122 |
+
# supervised_keys=("sentence", "label"),
|
123 |
+
# Homepage of the dataset for documentation
|
124 |
+
homepage=_HOMEPAGE,
|
125 |
+
# License for the dataset if available
|
126 |
+
license=_LICENSE,
|
127 |
+
# Citation for the dataset
|
128 |
+
citation=_CITATION,
|
129 |
+
)
|
130 |
+
|
131 |
+
def _split_generators(self, dl_manager):
|
132 |
+
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
133 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
134 |
+
|
135 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
136 |
+
# 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.
|
137 |
+
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
138 |
+
urls = _URLS[self.config.name]
|
139 |
+
data_dir = dl_manager.download_and_extract(urls)
|
140 |
+
return [
|
141 |
+
datasets.SplitGenerator(
|
142 |
+
name=datasets.Split.TEST,
|
143 |
+
# These kwargs will be passed to _generate_examples
|
144 |
+
gen_kwargs={
|
145 |
+
"filepath": os.path.join(data_dir, "test.jsonl"),
|
146 |
+
"split": "test"
|
147 |
+
},
|
148 |
+
),
|
149 |
+
]
|
150 |
+
|
151 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
152 |
+
def _generate_examples(self, filepath, split):
|
153 |
+
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
154 |
+
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
155 |
+
with open(filepath, encoding="utf-8") as f:
|
156 |
+
for key, row in enumerate(f):
|
157 |
+
data = json.loads(row)
|
158 |
+
yield key, data
|