scuwyh2000
commited on
Commit
•
61ed2da
1
Parent(s):
8bd85f7
test
Browse files
README.md
CHANGED
@@ -1,8 +1,4 @@
|
|
1 |
---
|
2 |
-
TODO: Add YAML tags here. Copy-paste the tags obtained with the online tagging app: https://huggingface.co/spaces/huggingface/datasets-tagging
|
3 |
-
---
|
4 |
-
|
5 |
-
# Dataset Card for [COCO]
|
6 |
annotations_creators:
|
7 |
- expert-generated
|
8 |
language:
|
@@ -32,6 +28,10 @@ train-eval-index:
|
|
32 |
eval_split: test
|
33 |
task: token-classification
|
34 |
task_id: entity_extraction
|
|
|
|
|
|
|
|
|
35 |
## Table of Contents
|
36 |
- [Table of Contents](#table-of-contents)
|
37 |
- [Dataset Description](#dataset-description)
|
|
|
1 |
---
|
|
|
|
|
|
|
|
|
2 |
annotations_creators:
|
3 |
- expert-generated
|
4 |
language:
|
|
|
28 |
eval_split: test
|
29 |
task: token-classification
|
30 |
task_id: entity_extraction
|
31 |
+
---
|
32 |
+
|
33 |
+
# Dataset Card for [COCO]
|
34 |
+
|
35 |
## Table of Contents
|
36 |
- [Table of Contents](#table-of-contents)
|
37 |
- [Dataset Description](#dataset-description)
|
coco.py
CHANGED
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
"""TODO: Add a description here."""
|
16 |
+
|
17 |
+
|
18 |
+
import csv
|
19 |
+
import json
|
20 |
+
import os
|
21 |
+
|
22 |
+
import datasets
|
23 |
+
|
24 |
+
_URL = "dataset_coco.json"
|
25 |
+
_URLS = {
|
26 |
+
"train": _URL
|
27 |
+
}
|
28 |
+
|
29 |
+
# TODO: Add BibTeX citation
|
30 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
31 |
+
_CITATION = """\
|
32 |
+
@InProceedings{huggingface:dataset,
|
33 |
+
title = {A great new dataset},
|
34 |
+
author={huggingface, Inc.
|
35 |
+
},
|
36 |
+
year={2020}
|
37 |
+
}
|
38 |
+
"""
|
39 |
+
|
40 |
+
# TODO: Add description of the dataset here
|
41 |
+
# You can copy an official description
|
42 |
+
_DESCRIPTION = """\
|
43 |
+
This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
|
44 |
+
"""
|
45 |
+
|
46 |
+
# TODO: Add a link to an official homepage for the dataset here
|
47 |
+
_HOMEPAGE = ""
|
48 |
+
|
49 |
+
# TODO: Add the licence for the dataset here if you can find it
|
50 |
+
_LICENSE = ""
|
51 |
+
|
52 |
+
# TODO: Add link to the official dataset URLs here
|
53 |
+
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
54 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
55 |
+
_URLS = {
|
56 |
+
"first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip",
|
57 |
+
"second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip",
|
58 |
+
}
|
59 |
+
|
60 |
+
|
61 |
+
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
62 |
+
class NewDataset(datasets.GeneratorBasedBuilder):
|
63 |
+
"""TODO: Short description of my dataset."""
|
64 |
+
|
65 |
+
VERSION = datasets.Version("1.1.0")
|
66 |
+
|
67 |
+
# This is an example of a dataset with multiple configurations.
|
68 |
+
# If you don't want/need to define several sub-sets in your dataset,
|
69 |
+
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
70 |
+
|
71 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
72 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
73 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
74 |
+
|
75 |
+
# You will be able to load one or the other configurations in the following list with
|
76 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
77 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
78 |
+
BUILDER_CONFIGS = [
|
79 |
+
datasets.BuilderConfig(name="first_domain", version=VERSION, description="This part of my dataset covers a first domain"),
|
80 |
+
datasets.BuilderConfig(name="second_domain", version=VERSION, description="This part of my dataset covers a second domain"),
|
81 |
+
]
|
82 |
+
|
83 |
+
DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
84 |
+
|
85 |
+
def _info(self):
|
86 |
+
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
87 |
+
if self.config.name == "first_domain": # This is the name of the configuration selected in BUILDER_CONFIGS above
|
88 |
+
features = datasets.Features(
|
89 |
+
{
|
90 |
+
"images": datasets.Sequence(
|
91 |
+
{
|
92 |
+
"filepath": datasets.Value("string"),
|
93 |
+
"sentids": datasets.Sequence(datasets.Value("int64")),
|
94 |
+
"filename": datasets.Value("string"),
|
95 |
+
"imgid": datasets.Value("int64"),
|
96 |
+
"split":datasets.Value("string"),
|
97 |
+
"sentences": datasets.Sequence(
|
98 |
+
{
|
99 |
+
"tokens": datasets.Sequence(datasets.Value("string")),
|
100 |
+
"raw": datasets.Value("string"),
|
101 |
+
"imgid": datasets.Value("int64"),
|
102 |
+
"sentid": datasets.Value("int64")
|
103 |
+
}
|
104 |
+
),
|
105 |
+
"cocoid": datasets.Value("int64")
|
106 |
+
}
|
107 |
+
),
|
108 |
+
"datasets": datasets.Value("string")
|
109 |
+
}
|
110 |
+
)
|
111 |
+
else: # This is an example to show how to have different features for "first_domain" and "second_domain"
|
112 |
+
features = datasets.Features(
|
113 |
+
{
|
114 |
+
"images": datasets.Sequence(
|
115 |
+
{
|
116 |
+
"filepath": datasets.Value("string"),
|
117 |
+
"sentids": datasets.Sequence(datasets.Value("int64")),
|
118 |
+
"filename": datasets.Value("string"),
|
119 |
+
"imgid": datasets.Value("int64"),
|
120 |
+
"split":datasets.Value("string"),
|
121 |
+
"sentences": datasets.Sequence(
|
122 |
+
{
|
123 |
+
"tokens": datasets.Sequence(datasets.Value("string")),
|
124 |
+
"raw": datasets.Value("string"),
|
125 |
+
"imgid": datasets.Value("int64"),
|
126 |
+
"sentid": datasets.Value("int64")
|
127 |
+
}
|
128 |
+
),
|
129 |
+
"cocoid": datasets.Value("int64")
|
130 |
+
}
|
131 |
+
),
|
132 |
+
"datasets": datasets.Value("string")
|
133 |
+
}
|
134 |
+
)
|
135 |
+
return datasets.DatasetInfo(
|
136 |
+
# This is the description that will appear on the datasets page.
|
137 |
+
description=_DESCRIPTION,
|
138 |
+
# This defines the different columns of the dataset and their types
|
139 |
+
features=features, # Here we define them above because they are different between the two configurations
|
140 |
+
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
141 |
+
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
142 |
+
# supervised_keys=("sentence", "label"),
|
143 |
+
# Homepage of the dataset for documentation
|
144 |
+
homepage=_HOMEPAGE,
|
145 |
+
# License for the dataset if available
|
146 |
+
license=_LICENSE,
|
147 |
+
# Citation for the dataset
|
148 |
+
citation=_CITATION,
|
149 |
+
)
|
150 |
+
|
151 |
+
def _split_generators(self, dl_manager):
|
152 |
+
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
153 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
154 |
+
|
155 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
156 |
+
# 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.
|
157 |
+
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
158 |
+
urls = _URLS[self.config.name]
|
159 |
+
data_dir = dl_manager.download_and_extract(urls)
|
160 |
+
return [
|
161 |
+
datasets.SplitGenerator(
|
162 |
+
name=datasets.Split.TRAIN,
|
163 |
+
# These kwargs will be passed to _generate_examples
|
164 |
+
gen_kwargs={
|
165 |
+
"filepath": os.path.join(data_dir, "train.jsonl"),
|
166 |
+
"split": "train",
|
167 |
+
},
|
168 |
+
),
|
169 |
+
datasets.SplitGenerator(
|
170 |
+
name=datasets.Split.VALIDATION,
|
171 |
+
# These kwargs will be passed to _generate_examples
|
172 |
+
gen_kwargs={
|
173 |
+
"filepath": os.path.join(data_dir, "dev.jsonl"),
|
174 |
+
"split": "dev",
|
175 |
+
},
|
176 |
+
),
|
177 |
+
datasets.SplitGenerator(
|
178 |
+
name=datasets.Split.TEST,
|
179 |
+
# These kwargs will be passed to _generate_examples
|
180 |
+
gen_kwargs={
|
181 |
+
"filepath": os.path.join(data_dir, "test.jsonl"),
|
182 |
+
"split": "test"
|
183 |
+
},
|
184 |
+
),
|
185 |
+
]
|
186 |
+
|
187 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
188 |
+
def _generate_examples(self, filepath, split):
|
189 |
+
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
190 |
+
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
191 |
+
with open(filepath, encoding="utf-8") as f:
|
192 |
+
for key, row in enumerate(f):
|
193 |
+
data = json.loads(row)
|
194 |
+
if self.config.name == "first_domain":
|
195 |
+
# Yields examples as (key, example) tuples
|
196 |
+
yield key, {
|
197 |
+
"sentence": data["sentence"],
|
198 |
+
"option1": data["option1"],
|
199 |
+
"answer": "" if split == "test" else data["answer"],
|
200 |
+
}
|
201 |
+
else:
|
202 |
+
yield key, {
|
203 |
+
"sentence": data["sentence"],
|
204 |
+
"option2": data["option2"],
|
205 |
+
"second_domain_answer": "" if split == "test" else data["second_domain_answer"],
|
206 |
+
}
|