-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closes #526 | Add dataloader for WIkiHow-GOSC #674
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
# coding=utf-8 | ||
# Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import json | ||
import os | ||
from pathlib import Path | ||
from typing import Dict, List, Tuple | ||
|
||
import datasets | ||
|
||
from seacrowd.utils.configs import SEACrowdConfig | ||
from seacrowd.utils.constants import Licenses, Tasks | ||
|
||
_CITATION = """ | ||
@inproceedings{lyu-etal-2021-goal, | ||
title = "Goal-Oriented Script Construction", | ||
author = "Lyu, Qing and | ||
Zhang, Li and | ||
Callison-Burch, Chris", | ||
editor = "Belz, Anya and | ||
Fan, Angela and | ||
Reiter, Ehud and | ||
Sripada, Yaji", | ||
booktitle = "Proceedings of the 14th International Conference on Natural Language Generation", | ||
month = aug, | ||
year = "2021", | ||
publisher = "Association for Computational Linguistics", | ||
url = "https://aclanthology.org/2021.inlg-1.19", | ||
doi = "10.18653/v1/2021.inlg-1.19", | ||
pages = "184--200", | ||
} | ||
""" | ||
_LOCAL = False | ||
_LANGUAGES = {"ind": "id", "tha": "th", "vie": "vn"} | ||
_DATASETNAME = "wikihow_gosc" | ||
_DESCRIPTION = """ | ||
This dataset consists of wikiHow goal-oriented scripts. For each goal or task, sections with steps to achieve this task are | ||
generated. Both the sections and steps within them are classified as either ordered or unordered. | ||
""" | ||
|
||
_HOMEPAGE = "https://github.com/veronica320/wikihow-GOSC/tree/main?tab=readme-ov-file" | ||
_LICENSE = Licenses.MIT.value | ||
_URL = "https://drive.google.com/uc?id=1AqAocrNFEPhBAfa5ATCj-3xMWbq659ME" | ||
|
||
_SUPPORTED_TASKS = [Tasks.INSTRUCTION_TUNING] | ||
_SOURCE_VERSION = "1.0.0" | ||
|
||
|
||
class WikiHowGOSCDataset(datasets.GeneratorBasedBuilder): | ||
"""Dataset of WikiHow tasks/goals with generated steps to perform them.""" | ||
|
||
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION) | ||
|
||
BUILDER_CONFIGS = [ | ||
SEACrowdConfig( | ||
name=f"{_DATASETNAME}_{lang}_source", | ||
version=_SOURCE_VERSION, | ||
description=f"{_DATASETNAME} source schema for {lang} language", | ||
schema="source", | ||
subset_id=f"{_DATASETNAME}_{lang}", | ||
) | ||
for lang in _LANGUAGES | ||
] | ||
|
||
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_ind_source" | ||
|
||
def _info(self) -> datasets.DatasetInfo: | ||
|
||
features = datasets.Features( | ||
{ | ||
"title": datasets.Value("string"), | ||
"category": datasets.Value("string"), | ||
"sections": datasets.Sequence({"section": datasets.Value("string"), "steps": datasets.Sequence(datasets.Value("string")), "ordered": datasets.Value("int32")}), | ||
"ordered": datasets.Value("int32"), | ||
} | ||
) | ||
|
||
return datasets.DatasetInfo( | ||
description=_DESCRIPTION, | ||
features=features, | ||
homepage=_HOMEPAGE, | ||
license=_LICENSE, | ||
citation=_CITATION, | ||
) | ||
|
||
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: | ||
"""Returns SplitGenerators.""" | ||
try: | ||
import gdown | ||
except ImportError: | ||
raise ImportError("Please install `gdown` to enable downloading data from google drive.") | ||
|
||
# Download from Google drive | ||
output_dir = Path.cwd() / "data" / "wikihow_gosc" | ||
output_dir.mkdir(parents=True, exist_ok=True) | ||
output_file = output_dir / "wikihow_multilingual_scripts.zip" | ||
if not output_file.exists(): | ||
gdown.download(_URL, str(output_file), fuzzy=True) | ||
else: | ||
print(f"File already downloaded: {str(output_file)}") | ||
|
||
data_dir = Path(dl_manager.extract(output_file)) | ||
lang = _LANGUAGES[self.config.subset_id.split("_")[-1]] | ||
|
||
return [ # Train and test are in same file | ||
datasets.SplitGenerator( | ||
name=datasets.Split.TRAIN, | ||
gen_kwargs={ | ||
"filepath": os.path.join(data_dir, f"script_{lang}.json"), | ||
"split": "train", | ||
}, | ||
), | ||
datasets.SplitGenerator( | ||
name=datasets.Split.TEST, | ||
gen_kwargs={ | ||
"filepath": os.path.join(data_dir, f"script_{lang}.json"), | ||
"split": "test", | ||
}, | ||
), | ||
] | ||
|
||
def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]: | ||
"""Yields examples as (key, example) tuples.""" | ||
with open(filepath, "r", encoding="utf-8") as file: | ||
data = json.load(file) | ||
for key, example in enumerate(data[split]): | ||
if "sections" not in example: # Single-section example | ||
yield key, { | ||
"title": example["title"], | ||
"category": example["category"], | ||
"sections": [{ | ||
"section": "", | ||
"steps": example["steps"], | ||
"ordered": example["ordered"], | ||
}], | ||
"ordered": 1 | ||
} | ||
else: | ||
yield key, example |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @elyanah-aco, I checked this data, and some of the examples don't have any
sections
key (probably single-sectioned data).This is an example of the key list of the data and (note: one-based index since I enumerate it from 1).
Do you mind making some readjustments on the
_generate_examples
to cater to such cases? I'm thinking of transforming such data into a section field with a single-valued list (let me know if you have a better workaround). Thx!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sabilmakbar I'm thinking like this:
where
ordered
inside and outsidesections
are the same.ordered
inside sections indicates if steps inside that section are ordered, andordered
outside indicates if sections themselves are ordered. They should be the same if there's just one sectionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for the outer
ordered
, it should be valued as 1, even if the inner sectionordered
value is 0 (the one coming from actual data) because it's a single-valued list anyway (indicates the list contents is ordered forsections
data). Theordered
in inner section (forsection
data, singleton list) will follow the initialordered
value from actual example. Wdyt?If we're taking the example from prev ss (but the
ordered
value is 0 instead of 1), we can construct it like this:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup you're correct. Will work on this tomorrow