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2022 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 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 |
+
import json
|
| 16 |
+
import os
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
from typing import Dict, List, Tuple
|
| 19 |
+
|
| 20 |
+
import datasets
|
| 21 |
+
|
| 22 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
| 23 |
+
from seacrowd.utils.constants import Licenses, Tasks
|
| 24 |
+
|
| 25 |
+
_CITATION = """
|
| 26 |
+
@inproceedings{lyu-etal-2021-goal,
|
| 27 |
+
title = "Goal-Oriented Script Construction",
|
| 28 |
+
author = "Lyu, Qing and
|
| 29 |
+
Zhang, Li and
|
| 30 |
+
Callison-Burch, Chris",
|
| 31 |
+
editor = "Belz, Anya and
|
| 32 |
+
Fan, Angela and
|
| 33 |
+
Reiter, Ehud and
|
| 34 |
+
Sripada, Yaji",
|
| 35 |
+
booktitle = "Proceedings of the 14th International Conference on Natural Language Generation",
|
| 36 |
+
month = aug,
|
| 37 |
+
year = "2021",
|
| 38 |
+
publisher = "Association for Computational Linguistics",
|
| 39 |
+
url = "https://aclanthology.org/2021.inlg-1.19",
|
| 40 |
+
doi = "10.18653/v1/2021.inlg-1.19",
|
| 41 |
+
pages = "184--200",
|
| 42 |
+
}
|
| 43 |
+
"""
|
| 44 |
+
_LOCAL = False
|
| 45 |
+
_LANGUAGES = {"ind": "id", "tha": "th", "vie": "vn"}
|
| 46 |
+
_DATASETNAME = "wikihow_gosc"
|
| 47 |
+
_DESCRIPTION = """
|
| 48 |
+
This dataset consists of wikiHow goal-oriented scripts. For each goal or task, sections with steps to achieve this task are
|
| 49 |
+
generated. Both the sections and steps within them are classified as either ordered or unordered.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
_HOMEPAGE = "https://github.com/veronica320/wikihow-GOSC/tree/main?tab=readme-ov-file"
|
| 53 |
+
_LICENSE = Licenses.MIT.value
|
| 54 |
+
_URL = "https://drive.google.com/uc?id=1AqAocrNFEPhBAfa5ATCj-3xMWbq659ME"
|
| 55 |
+
|
| 56 |
+
_SUPPORTED_TASKS = [Tasks.INSTRUCTION_TUNING]
|
| 57 |
+
_SOURCE_VERSION = "1.0.0"
|
| 58 |
+
_SEACROWD_VERSION = "2024.06.20"
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class WikiHowGOSCDataset(datasets.GeneratorBasedBuilder):
|
| 62 |
+
"""Dataset of WikiHow tasks/goals with generated steps to perform them."""
|
| 63 |
+
|
| 64 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
| 65 |
+
|
| 66 |
+
BUILDER_CONFIGS = [
|
| 67 |
+
SEACrowdConfig(
|
| 68 |
+
name=f"{_DATASETNAME}_{lang}_source",
|
| 69 |
+
version=_SOURCE_VERSION,
|
| 70 |
+
description=f"{_DATASETNAME} source schema for {lang} language",
|
| 71 |
+
schema="source",
|
| 72 |
+
subset_id=f"{_DATASETNAME}_{lang}",
|
| 73 |
+
)
|
| 74 |
+
for lang in _LANGUAGES
|
| 75 |
+
]
|
| 76 |
+
|
| 77 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_ind_source"
|
| 78 |
+
|
| 79 |
+
def _info(self) -> datasets.DatasetInfo:
|
| 80 |
+
|
| 81 |
+
features = datasets.Features(
|
| 82 |
+
{
|
| 83 |
+
"title": datasets.Value("string"),
|
| 84 |
+
"category": datasets.Value("string"),
|
| 85 |
+
"sections": datasets.Sequence({"section": datasets.Value("string"), "steps": datasets.Sequence(datasets.Value("string")), "ordered": datasets.Value("int32")}),
|
| 86 |
+
"ordered": datasets.Value("int32"),
|
| 87 |
+
}
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
return datasets.DatasetInfo(
|
| 91 |
+
description=_DESCRIPTION,
|
| 92 |
+
features=features,
|
| 93 |
+
homepage=_HOMEPAGE,
|
| 94 |
+
license=_LICENSE,
|
| 95 |
+
citation=_CITATION,
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 99 |
+
"""Returns SplitGenerators."""
|
| 100 |
+
try:
|
| 101 |
+
import gdown
|
| 102 |
+
except ImportError:
|
| 103 |
+
raise ImportError("Please install `gdown` to enable downloading data from google drive.")
|
| 104 |
+
|
| 105 |
+
# Download from Google drive
|
| 106 |
+
output_dir = Path.cwd() / "data" / "wikihow_gosc"
|
| 107 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 108 |
+
output_file = output_dir / "wikihow_multilingual_scripts.zip"
|
| 109 |
+
if not output_file.exists():
|
| 110 |
+
gdown.download(_URL, str(output_file), fuzzy=True)
|
| 111 |
+
else:
|
| 112 |
+
print(f"File already downloaded: {str(output_file)}")
|
| 113 |
+
|
| 114 |
+
data_dir = Path(dl_manager.extract(output_file))
|
| 115 |
+
lang = _LANGUAGES[self.config.subset_id.split("_")[-1]]
|
| 116 |
+
|
| 117 |
+
return [ # Train and test are in same file
|
| 118 |
+
datasets.SplitGenerator(
|
| 119 |
+
name=datasets.Split.TRAIN,
|
| 120 |
+
gen_kwargs={
|
| 121 |
+
"filepath": os.path.join(data_dir, f"script_{lang}.json"),
|
| 122 |
+
"split": "train",
|
| 123 |
+
},
|
| 124 |
+
),
|
| 125 |
+
datasets.SplitGenerator(
|
| 126 |
+
name=datasets.Split.TEST,
|
| 127 |
+
gen_kwargs={
|
| 128 |
+
"filepath": os.path.join(data_dir, f"script_{lang}.json"),
|
| 129 |
+
"split": "test",
|
| 130 |
+
},
|
| 131 |
+
),
|
| 132 |
+
]
|
| 133 |
+
|
| 134 |
+
def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
|
| 135 |
+
"""Yields examples as (key, example) tuples."""
|
| 136 |
+
with open(filepath, "r", encoding="utf-8") as file:
|
| 137 |
+
data = json.load(file)
|
| 138 |
+
for key, example in enumerate(data[split]):
|
| 139 |
+
if "sections" not in example: # Single-section example
|
| 140 |
+
yield key, {
|
| 141 |
+
"title": example["title"],
|
| 142 |
+
"category": example["category"],
|
| 143 |
+
"sections": [{
|
| 144 |
+
"section": "",
|
| 145 |
+
"steps": example["steps"],
|
| 146 |
+
"ordered": example["ordered"],
|
| 147 |
+
}],
|
| 148 |
+
"ordered": 1
|
| 149 |
+
}
|
| 150 |
+
else:
|
| 151 |
+
yield key, example
|