Skip to content
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 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
150 changes: 150 additions & 0 deletions seacrowd/sea_datasets/wikihow_gosc/wikihow_gosc.py
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"),
Comment on lines +82 to +85
Copy link
Collaborator

@sabilmakbar sabilmakbar May 19, 2024

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).
image
image

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!

Copy link
Collaborator Author

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:

"sections": ["section": "", "steps": ['" Mulailah membuat situs web.", "Gunakan Twitter."], "ordered": 1],
"ordered": 1

where ordered inside and outside sections are the same. ordered inside sections indicates if steps inside that section are ordered, and ordered outside indicates if sections themselves are ordered. They should be the same if there's just one section

Copy link
Collaborator

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 section ordered value is 0 (the one coming from actual data) because it's a single-valued list anyway (indicates the list contents is ordered for sections data). The ordered in inner section (for section data, singleton list) will follow the initial ordered 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:

# the `ordered` value in sections list indicatest the actual `ordered` state on the `steps`
"sections": ["section": "", "steps": ['" Mulailah membuat situs web.", "Gunakan Twitter."], "ordered": 0],
"ordered": 1 # the value indicates the ordering in `sections` is ordered (which is 1 for singleton list)

Copy link
Collaborator Author

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

}
)

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