|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
This file provides a HuggingFace dataset loader implementation for |
|
the JHU/HLTCOE MegaWika dataset, specifically for a report generation |
|
or multi-doc summarization dataset using the raw MegaWika |
|
|
|
|
|
MegaWika is a multi- and crosslingual text dataset containing 30 million |
|
Wikipedia passages with their scraped and cleaned web citations. The |
|
passages span 50 Wikipedias in 50 languages, and the articles in which |
|
the passages were originally embedded are included for convenience. Where |
|
a Wikipedia passage is in a non-English language, an automated English |
|
translation is provided. |
|
""" |
|
|
|
|
|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@misc{barham2023megawika, |
|
title={MegaWika: Millions of reports and their sources across 50 diverse languages}, |
|
author={Samuel Barham and and Weller and Michelle Yuan and Kenton Murray and Mahsa Yarmohammadi and Zhengping Jiang and Siddharth Vashishtha and Alexander Martin and Anqi Liu and Aaron Steven White and Jordan Boyd-Graber and Benjamin Van Durme}, |
|
year={2023}, |
|
eprint={2307.07049}, |
|
archivePrefix={arXiv}, |
|
primaryClass={cs.CL} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
MegaWika is a multi- and crosslingual text dataset containing 30 million |
|
Wikipedia passages with their scraped and cleaned web citations. The |
|
passages span 50 Wikipedias in 50 languages, and the articles in which |
|
the passages were originally embedded are included for convenience. Where |
|
a Wikipedia passage is in a non-English language, an automated English |
|
translation is provided. |
|
""" |
|
|
|
_URL = "https://huggingface.co/datasets/hltcoe/megawika" |
|
|
|
|
|
class MegaWikaReportGenerationConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for MegaWikaReportGeneration.""" |
|
|
|
def __init__(self, language: str = "en", monolingual: bool = True, iterative: bool = False, **kwargs): |
|
"""BuilderConfig for MegaWikaReportGeneration. |
|
""" |
|
super(MegaWikaReportGenerationConfig, self).__init__(**kwargs) |
|
self.language = language |
|
self.monolingual = monolingual |
|
self.iterative = iterative |
|
|
|
|
|
class MegaWikaReportGeneration(datasets.GeneratorBasedBuilder): |
|
"""The MegaWikaReportGeneration benchmark.""" |
|
|
|
BUILDER_CONFIGS = [ |
|
MegaWikaReportGenerationConfig( |
|
name="monolingual-section", |
|
monolingual=True, |
|
iterative=False, |
|
), |
|
MegaWikaReportGenerationConfig( |
|
name="crosslingual-section", |
|
monolingual=False, |
|
iterative=False, |
|
), |
|
MegaWikaReportGenerationConfig( |
|
name="monolingual-iterative", |
|
monolingual=True, |
|
iterative=True, |
|
), |
|
MegaWikaReportGenerationConfig( |
|
name="crosslingual-iterative", |
|
monolingual=False, |
|
iterative=True, |
|
), |
|
] |
|
|
|
def _info(self): |
|
features = {} |
|
features["id"] = datasets.Value("string") |
|
features["num_docs"] = datasets.Value("int32") |
|
features["title"] = datasets.Value("string") |
|
features["intro"] = datasets.Value("string") |
|
features["section_name"] = datasets.Value("string") |
|
features["gold_section_text"] = datasets.Value("string") |
|
features["citations"] = datasets.features.Sequence(datasets.Value("string")) |
|
features["previous_text"] = datasets.Value("string") |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features(features), |
|
homepage=_URL, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
dl_dir = dl_manager.download_and_extract(self.config.url) or "" |
|
dl_dir = os.path.join(dl_dir, "mono" if self.config.monolingual else "cl", "iterative" if self.config.iterative else "section", self.config.language) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"data_file": os.path.join(dl_dir, "train.jsonl"), |
|
"split": datasets.Split.TRAIN, |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"data_file": os.path.join(dl_dir, "dev.jsonl"), |
|
"split": datasets.Split.VALIDATION, |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"data_file": os.path.join(dl_dir, "test.jsonl"), |
|
"split": datasets.Split.TEST, |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, data_file, split): |
|
with open(data_file, encoding="utf-8") as f: |
|
for idx, line in enumerate(f): |
|
row = json.loads(line) |
|
if "previous_text" not in row: |
|
row["previous_text"] = "" |
|
yield idx, row |